index.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. const app = getApp();
  2. const {
  3. login,
  4. listByDevice
  5. } = require('../../utils/api.js');
  6. import timeUtil from '../../utils/time_util.js';
  7. import strings from '../../utils/strings.js';
  8. import store from '../../utils/store.js';
  9. import route_constant from '../../utils/route_constant.js';
  10. import route_util from '../../utils/route_util.js';
  11. /// 乐鑫相关
  12. import lexin_util from '../../utils/lexin/util.js';
  13. import lexin_jump from '../../utils/lexin/jump.js';
  14. import lexin_add from '../../utils/lexin/add.js';
  15. import lexin_scan from '../../utils/lexin/scan.js';
  16. import lexin_subscribe from '../../utils/lexin/subscribe.js';
  17. import lexin_connect from '../../utils/lexin/connect.js';
  18. import lexin_message from '../../utils/lexin/message.js';
  19. import {
  20. BtHelper
  21. } from '../../devices/bt_helper.js';
  22. Page({
  23. data: {
  24. nvabarData: {
  25. showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
  26. title: 'OhPlay', //导航栏 中间的标题
  27. },
  28. ///下午好
  29. isLogin: false,
  30. greeting: "",
  31. bannerList: [{
  32. "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
  33. },
  34. {
  35. "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
  36. }
  37. ],
  38. autoplay: true,
  39. interval: 3000, // 切换时间间隔
  40. duration: 500, // 滑动动画时长
  41. circular: true, // 衔接滑动
  42. indexPage: 0,
  43. ///是否展示频道
  44. showChannel: false,
  45. ////首页
  46. navBarHeight: app.globalData.navBarHeight,
  47. MenuButtonheight: app.globalData.MenuButtonheight,
  48. MenuButtonTop: app.globalData.MenuButtonTop,
  49. actionIndex: null,
  50. luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
  51. channelData: [],
  52. isOneLoading: true,
  53. uid: null,
  54. isSetWake: false,
  55. battery: 4, // 0≤电量<20,0格
  56. ////我的界面
  57. loginStatus: true,
  58. nickName: "未登录",
  59. userPic: './../../img/head_pic.png',
  60. intervalId: null,
  61. /// 是否第一次自动连接过
  62. autoConnected: false,
  63. intervalId1: null,
  64. intervalId2: null,
  65. deviceMacId: null,
  66. deviceListSelect: null,
  67. deviceList: [],
  68. connectDeviceIding: "",
  69. },
  70. onLoad(options) {
  71. var that = this;
  72. that.onLoginLoad();
  73. that.onDeviceLoad();
  74. that.onUserInfoLoad();
  75. that.onBannerLoad();
  76. },
  77. onShow() {
  78. var that = this;
  79. that.onBannerShow();
  80. },
  81. onLoginLoad() {
  82. var that = this;
  83. var userInfo = wx.getStorageSync("userInfo") || "";
  84. if (!strings.isEmpty(userInfo)) {
  85. var phone = userInfo.phone;
  86. if (!strings.isEmpty(phone)) {
  87. that.loginReset(phone, null, null, null);
  88. };
  89. }
  90. },
  91. ///重新登录
  92. loginReset(phone, succeedCall1, succeedCall2, failCall) {
  93. // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","userId":933625,"deviceUid":1,"accessToken":"PUK8WVnLbIFsWYjSteitmg3OhllpbUMvIPKUtfJgwhRtpl1jx4Fm1NkHQIiZYhHz","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥"}
  94. var that = this;
  95. wx.login({
  96. success: res0 => {
  97. // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":933625,"deviceUid":1,"accessToken":"kaKdNAb9eO0iUGKsaLP18UE0wRwrvoCr4opjNC3AieaigH4Fu1IspQKi2zTPgLNG","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥","isNewUser":false}
  98. login({
  99. code: res0.code,
  100. phone: phone,
  101. }).then((res1) => {
  102. app.globalData.userInfo = res1;
  103. store.setStore("userInfo", res1);
  104. store.setStore("token", JSON.stringify({
  105. id: res1.userId,
  106. token: res1.accessToken,
  107. }));
  108. that.onUserInfoLoad();
  109. if (succeedCall1 != null) {
  110. succeedCall1();
  111. }
  112. if (succeedCall2 != null) {
  113. succeedCall2();
  114. }
  115. });
  116. },
  117. fail(fail4) {
  118. if (failCall != null) {
  119. failCall();
  120. }
  121. },
  122. });
  123. },
  124. onDeviceLoad() {
  125. var that = this;
  126. var deviceList = store.getStore("deviceList");
  127. if (!strings.isEmpty(deviceList)) {
  128. that.updateDeviceList(deviceList, true, false);
  129. }
  130. ///监听蓝牙设备
  131. BtHelper.getInstance().initBluetoothAdapter();
  132. BtHelper.getInstance().getBluetoothDevices();
  133. BtHelper.getInstance().startScan(null, null, null);
  134. var isFirst = true;
  135. ///再秒再对比一次
  136. that.stopIntervalId1();
  137. that.data.intervalId1 = setInterval(async function () {
  138. isFirst = false;
  139. that.compareList();
  140. }, isFirst ? 6 * 1000 : 12 * 1000);
  141. },
  142. /// 对比蓝牙数据
  143. compareList() {
  144. var that = this;
  145. lexin_scan.compareList(function (list) {
  146. that.updateDeviceList(list, false, false);
  147. }, function (item) {
  148. that.addBlueDevice(item);
  149. });
  150. },
  151. // 回调
  152. mqttCallback(type, option) {
  153. // console.log("gadsfadsfadsfa==888===" + type);
  154. var that = this;
  155. let payloads = null;
  156. if (option && option.payload) {
  157. payloads = JSON.parse(option.payload);
  158. };
  159. switch (type) {
  160. ///先走订阅
  161. case "connect":
  162. lexin_subscribe.subscribeAllDevice();
  163. break;
  164. ///再走有在线
  165. case "message_onoffline":
  166. lexin_connect.searchOnlineDevice(payloads, function (list) {
  167. that.updateDeviceList(list, false, false);
  168. }, function () {
  169. var indexPage = that.data.indexPage;
  170. that.setData({
  171. actionIndex: null,
  172. deviceListSelect: null,
  173. indexPage: indexPage == 1 ? 0 : indexPage,
  174. });
  175. });
  176. break;
  177. case "message":
  178. if (payloads) {
  179. var payloadType = payloads.type;
  180. var other = payloads.other;
  181. ///获取频道位置
  182. if (payloadType === "get_position" && other) {
  183. lexin_message.getPosition(other, function (actionIndex) {
  184. that.setData({
  185. actionIndex: actionIndex,
  186. });
  187. });
  188. }
  189. // 获取歌曲信息
  190. else if (payloadType === "get_dev_info" && other) {
  191. that.setDeviceInfor(other);
  192. lexin_message.getDeviceInfo(payloads);
  193. }
  194. ///获取电量
  195. else if (payloadType === "battery" && other) {
  196. var battery = lexin_message.getDeviceInfo(other.battery);
  197. that.setData({
  198. battery: battery,
  199. });
  200. }
  201. ///获取播放状态
  202. else if (payloadType === "play" || payloadType === "play_state") {
  203. lexin_message.getPlay();
  204. }
  205. }
  206. break;
  207. default:
  208. }
  209. },
  210. ///去连接设备数据
  211. actionDevice(device) {
  212. var that = this;
  213. // 取消订阅
  214. var deviceMacId = that.data.deviceMacId;
  215. if (!strings.isEmpty(deviceMacId)) {
  216. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  217. app.unsubscribe(pubResponse);
  218. };
  219. that.subscribeCurrDevice(device);
  220. },
  221. ///数据处理
  222. subscribeCurrDevice(device) {
  223. var that = this;
  224. var isOK = app.globalData.client && app.globalData.client.connected;
  225. if (!isOK) {
  226. app.connect();
  227. setTimeout(() => {
  228. that.subscribeCurrDevice(device);
  229. }, 500);
  230. return;
  231. };
  232. var deviceId = device.deviceId;
  233. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  234. that.setData({
  235. deviceMacId: deviceMacId,
  236. });
  237. /// 订阅设备
  238. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  239. app.subscribe(pubResponse);
  240. /// 获取设备信息
  241. const obj = {
  242. DstDeviceName: deviceMacId
  243. };
  244. app.PubMsg({
  245. type: "get_dev_info",
  246. ...obj
  247. });
  248. },
  249. ///选择对应的频道
  250. onTapChannelIndex(e) {
  251. var that = this;
  252. var index = e.currentTarget.dataset.index;
  253. lexin_jump.toChannelIndex(index, function (i) {
  254. that.setData({
  255. actionIndex: i,
  256. });
  257. });
  258. },
  259. getchannelData(clientType) {
  260. var that = this;
  261. listByDevice({
  262. clientType: clientType,
  263. unShowLoad: true,
  264. }).then((res) => {
  265. store.setStore("channelData", res);
  266. that.setData({
  267. channelData: res,
  268. });
  269. // 接收设备当前播放状态
  270. var deviceList = that.getDeviceList();
  271. var deviceListSelect = that.getDeviceListSelect();
  272. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  273. return;
  274. };
  275. var deviceId = deviceList[deviceListSelect].deviceId;
  276. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  277. const obj = {
  278. DstDeviceName: deviceMacId
  279. }
  280. app.PubMsg({
  281. type: "get_position",
  282. ...obj
  283. });
  284. })
  285. },
  286. ///去频道详情
  287. onTapToChannel() {
  288. var that = this;
  289. var actionIndex = that.data.actionIndex;
  290. if (strings.isEmpty(actionIndex)) {
  291. return;
  292. }
  293. var channelData = that.getChannelData();
  294. if (channelData.length > actionIndex) {
  295. store.setStore("channelDeta", channelData[actionIndex]);
  296. wx.navigateTo({
  297. url: './../channelDetails/channelDetails'
  298. });
  299. }
  300. },
  301. onTapIndex(e) {
  302. var that = this;
  303. var index = e.currentTarget.dataset.index;
  304. var indexPage = that.data.indexPage;
  305. if (indexPage != index) {
  306. that.setData({
  307. indexPage: index,
  308. });
  309. }
  310. },
  311. onTapLogin() {
  312. var that = this;
  313. ///退出登录
  314. var isLogin = that.getIsLogin();
  315. if (isLogin) {
  316. that.logOut();
  317. return;
  318. }
  319. route_util.jump(route_constant.login);
  320. },
  321. ///退出登录
  322. logOut() {
  323. var that = this;
  324. wx.removeStorageSync('userInfo');
  325. wx.removeStorageSync('token');
  326. var nickName = "未登录";
  327. var greeting = that.getGreetBuNickName(nickName);
  328. that.setData({
  329. isLogin: false,
  330. greeting: greeting,
  331. nickName: nickName,
  332. userPic: "./../../img/head_pic.png",
  333. });
  334. var deviceList = that.getDeviceList();
  335. var deviceListSelect = that.getDeviceListSelect();
  336. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  337. return;
  338. };
  339. ///有设备在线被选中,则让它不被选择
  340. if (deviceList[deviceListSelect].connectType == 3) {
  341. var deviceMacId = that.data.deviceMacId;
  342. if (!strings.isEmpty(deviceMacId)) {
  343. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  344. app.unsubscribe(pubResponse);
  345. var indexPage = that.data.indexPage;
  346. that.setData({
  347. deviceMacId: null,
  348. actionIndex: null,
  349. deviceListSelect: null,
  350. indexPage: indexPage == 1 ? 0 : indexPage,
  351. });
  352. };
  353. }
  354. },
  355. ///点击item
  356. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  357. onTapItem(e) {
  358. var that = this;
  359. var isLogin = that.getIsLogin();
  360. if (!isLogin) {
  361. route_util.jump(route_constant.login);
  362. return;
  363. }
  364. var index = e.currentTarget.dataset.index;
  365. var device = e.currentTarget.dataset.item;
  366. var connectType = device.connectType;
  367. var deviceListSelect = that.getDeviceListSelect();
  368. // wifi只支持在线点击
  369. if (connectType == 3 && device.state === "online") {
  370. if (index === deviceListSelect) {
  371. that.goWake();
  372. } else {
  373. that.addWifiDevice(device);
  374. }
  375. return;
  376. }
  377. ///去蓝牙连接处理
  378. if (index === deviceListSelect) {
  379. route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
  380. } else if (device.state === "offline") {
  381. console.log("去连接蓝牙")
  382. } else {
  383. // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
  384. device.name = device.devName;
  385. BtHelper.getInstance().connect(device, function (isConnected, d) {
  386. if (isConnected) {
  387. that.addBlueDevice(d);
  388. }
  389. });
  390. }
  391. },
  392. // 去唤醒界面
  393. goWake() {
  394. var that = this;
  395. var deviceList = that.getDeviceList();
  396. var deviceListSelect = that.getDeviceListSelect();
  397. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  398. return
  399. };
  400. var device = deviceList[deviceListSelect];
  401. wx.navigateTo({
  402. url: './../deviceWake/deviceWake?deviceId=' + device.deviceId + "&clientType=" + device.ProdModel,
  403. });
  404. },
  405. ///删除当前设备
  406. deleteDevice(e) {
  407. var that = this;
  408. var index = e.currentTarget.dataset.index;
  409. wx.showModal({
  410. title: '确定删除?',
  411. success: function (res) {
  412. if (res.confirm) {
  413. var deviceList = that.getDeviceList();
  414. if (deviceList[index].connectType == 3) {
  415. that.cancelWifi(index, false);
  416. } else {
  417. that.cancelBlue(index, false);
  418. }
  419. }
  420. }
  421. });
  422. },
  423. ///是否是同一个蓝牙
  424. isTheSameBlue(device) {
  425. var that = this;
  426. var deviceList = that.getDeviceList();
  427. var deviceListSelect = that.getDeviceListSelect();
  428. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  429. return false;
  430. };
  431. if (deviceList[deviceListSelect].connectType == 3) {
  432. return false;
  433. } else {
  434. if (deviceList[deviceListSelect].deviceId == device.deviceId) {
  435. return true;
  436. } else {
  437. return false;
  438. }
  439. }
  440. },
  441. ///断开当前的
  442. cancelCurrent() {
  443. var that = this;
  444. var deviceList = that.getDeviceList();
  445. var deviceListSelect = that.getDeviceListSelect();
  446. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  447. return;
  448. };
  449. if (deviceList[deviceListSelect].connectType == 3) {
  450. that.cancelWifi(deviceListSelect, true);
  451. } else {
  452. that.cancelBlue(deviceListSelect, true);
  453. }
  454. },
  455. /// 断开蓝牙连接
  456. cancelBlue(index, onlyCancel) {
  457. var that = this;
  458. if (onlyCancel) {
  459. return;
  460. }
  461. var deviceList = that.getDeviceList();
  462. var deviceListSelect = that.getDeviceListSelect();
  463. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  464. return;
  465. };
  466. ///是否删除的当前播放这个
  467. var isCurrentIndex = false;
  468. var deviceListSelect = that.getDeviceListSelect();
  469. if (deviceListSelect != null && deviceList.length > deviceListSelect) {
  470. isCurrentIndex = (deviceListSelect == index);
  471. };
  472. ///删除当前设备
  473. var deviceId = deviceList[index].deviceId;
  474. deviceList = deviceList.filter((item, i) => {
  475. return deviceId !== item.deviceId;
  476. });
  477. store.setStore("deviceList", deviceList);
  478. var indexPage = that.data.indexPage;
  479. that.setData({
  480. deviceList: deviceList,
  481. indexPage: indexPage == 1 ? 0 : indexPage,
  482. deviceListSelect: isCurrentIndex ? null : deviceListSelect,
  483. });
  484. },
  485. /// 断开连接wifi
  486. cancelWifi(index, onlyCancel) {
  487. var that = this;
  488. var deviceList = that.getDeviceList();
  489. if (index === null || deviceList.length <= index) {
  490. return;
  491. };
  492. var deviceId = deviceList[index].deviceId;
  493. // 取消订阅
  494. var pubResponse = lexin_util.getResponseByDeviceId(deviceId);
  495. app.unsubscribe(pubResponse);
  496. if (onlyCancel) {
  497. return;
  498. }
  499. ///是否删除的当前播放这个
  500. var isCurrentIndex = false;
  501. var deviceListSelect = that.getDeviceListSelect();
  502. if (deviceListSelect != null && deviceList.length > deviceListSelect) {
  503. isCurrentIndex = (deviceListSelect == index);
  504. };
  505. deviceList = deviceList.filter((item, i) => {
  506. return deviceId !== item.deviceId;
  507. });
  508. store.setStore("deviceList", deviceList);
  509. var indexPage = that.data.indexPage;
  510. var deviceMacId = that.data.deviceMacId;
  511. var actionIndex = that.data.actionIndex;
  512. that.setData({
  513. deviceList: deviceList,
  514. deviceMacId: isCurrentIndex ? null : deviceMacId,
  515. actionIndex: isCurrentIndex ? null : actionIndex,
  516. deviceListSelect: isCurrentIndex ? null : deviceListSelect,
  517. indexPage: indexPage == 1 ? 0 : indexPage,
  518. });
  519. },
  520. /// 新添加蓝牙设备
  521. addBlueDevice(device) {
  522. var that = this;
  523. var addDeviceList = lexin_add.addBlueDevice(device);
  524. that.updateDeviceList(addDeviceList, false, false);
  525. that.setData({
  526. deviceListSelect: 0,
  527. autoConnected: true,
  528. });
  529. },
  530. // 新添加Wifi设备
  531. addWifiDevice(device) {
  532. var that = this;
  533. var isOK = app.globalData.client && app.globalData.client.connected;
  534. if (!isOK) {
  535. app.connect();
  536. setTimeout(() => {
  537. that.addWifiDevice(device);
  538. }, 500);
  539. return;
  540. };
  541. var deviceId = device.deviceId;
  542. var addDeviceList = lexin_add.addWifiDevice(device);
  543. that.updateDeviceList(addDeviceList, false, false);
  544. var indexPage = that.data.indexPage;
  545. that.setData({
  546. deviceListSelect: null,
  547. connectDeviceIding: deviceId,
  548. indexPage: indexPage == 1 ? 0 : indexPage,
  549. });
  550. lexin_subscribe.subscribeSingleDevice(device);
  551. },
  552. refreshCurrentDevice(device) {
  553. var that = this;
  554. var deviceList = that.getDeviceList();
  555. var selectIndex = null;
  556. for (var i = 0; i < deviceList.length; i++) {
  557. if (device.deviceId == deviceList[i].deviceId) {
  558. selectIndex = i;
  559. break;
  560. }
  561. }
  562. if (selectIndex != null) {
  563. var addDeviceList = lexin_add.addWifiDevice(device);
  564. that.updateDeviceList(addDeviceList, false, false);
  565. that.setData({
  566. autoConnected: true,
  567. deviceListSelect: selectIndex,
  568. connectDeviceIding: "",
  569. });
  570. }
  571. },
  572. /// 手机关闭蓝牙,所有蓝牙设备离线
  573. closeBlueResetOffline(isInit, closeAllBlue) {
  574. var that = this;
  575. var deviceList = that.getDeviceList();
  576. that.updateDeviceList(deviceList, isInit, closeAllBlue);
  577. },
  578. /// 更新列表排序
  579. updateDeviceList(deviceList, isInit, closeAllBlue) {
  580. var that = this;
  581. var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
  582. if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
  583. store.setStore("deviceList", finalList);
  584. that.setData({
  585. deviceList: finalList,
  586. });
  587. }
  588. },
  589. ///点击banner事件
  590. onTapBanner() {
  591. var that = this;
  592. var item = e.currentTarget.dataset.item;
  593. },
  594. ///添加设备
  595. jumpToAddDevice() {
  596. var that = this;
  597. var isLogin = that.getIsLogin();
  598. if (!isLogin) {
  599. route_util.jump(route_constant.login);
  600. return;
  601. }
  602. route_util.jump(route_constant.deviceList);
  603. },
  604. // 关于我们
  605. jumpToAboutUs() {
  606. lexin_jump.toAboutUs();
  607. },
  608. /// 是否已登录
  609. getIsLogin() {
  610. var that = this;
  611. var isLogin = that.data.isLogin;
  612. return isLogin;
  613. },
  614. /// 获取列表数据
  615. getDeviceList() {
  616. var that = this;
  617. var deviceList = that.data.deviceList;
  618. return deviceList;
  619. },
  620. ///获取当前选中的
  621. getDeviceListSelect() {
  622. var that = this;
  623. var deviceListSelect = that.data.deviceListSelect;
  624. return deviceListSelect;
  625. },
  626. ///获取是否已经第一次连接过
  627. getAutoConnected() {
  628. var that = this;
  629. var autoConnected = that.data.autoConnected;
  630. return autoConnected;
  631. },
  632. ///当前正在连接的设备id
  633. getConnectDeviceIding() {
  634. var that = this;
  635. var connectDeviceIding = that.data.connectDeviceIding
  636. return connectDeviceIding;
  637. },
  638. ///获取频道数据
  639. getChannelData() {
  640. var that = this;
  641. var channelData = that.data.channelData;
  642. return channelData;
  643. },
  644. /// 当前播放频道
  645. getActionIndex() {
  646. var that = this;
  647. var actionIndex = that.data.actionIndex;
  648. return actionIndex;
  649. },
  650. ///设置设备相关信息
  651. setDeviceInfor(other) {
  652. var that = this;
  653. // 接收设备当前信息
  654. that.getchannelData(other.ProdModel);
  655. // 电量
  656. var battery = lexin_message.getDeviceInfo(other.Power);
  657. that.setData({
  658. battery: battery,
  659. })
  660. // 当前设备木有设置定时
  661. that.setData({
  662. isSetWake: false,
  663. });
  664. other.alarm.map((v) => {
  665. if (v.enable === "1") {
  666. that.setData({
  667. isSetWake: true
  668. });
  669. }
  670. });
  671. },
  672. ///******************************* 可折叠 ********************************************///
  673. onUserInfoLoad() {
  674. var that = this;
  675. var userInfo = wx.getStorageSync("userInfo") || "";
  676. if (!strings.isEmpty(userInfo)) {
  677. var phone = userInfo.phone;
  678. if (!phone) {
  679. return;
  680. };
  681. var nickName = userInfo.nickname || "";
  682. var greeting = that.getGreetBuNickName(nickName);
  683. // 获取缓存的频道数据
  684. var channelData = wx.getStorageSync("channelData") || "";
  685. if (!strings.isEmpty(channelData)) {
  686. that.setData({
  687. channelData: channelData,
  688. greeting: greeting,
  689. nickName: nickName,
  690. userPic: userInfo.headUrl || "",
  691. isLogin: true,
  692. })
  693. } else {
  694. that.setData({
  695. greeting: greeting,
  696. nickName: nickName,
  697. userPic: userInfo.headUrl || "",
  698. isLogin: true,
  699. });
  700. }
  701. } else {
  702. var greeting = that.getGreetBuNickName("");
  703. that.setData({
  704. greeting: greeting,
  705. })
  706. }
  707. },
  708. getGreetBuNickName(nickName) {
  709. var greeting = timeUtil.getGreet();
  710. if (nickName != "" && nickName != "未登录") {
  711. greeting = greeting + ',' + nickName;;
  712. }
  713. return greeting;
  714. },
  715. onBannerLoad() {
  716. var that = this;
  717. // var bannerList = wx.getStorageSync("homeBanner") || [];
  718. // if (that.data.bannerList.length > 0) {
  719. // that.setData({
  720. // bannerList: bannerList
  721. // });
  722. // }
  723. },
  724. onBannerShow() {
  725. var that = this;
  726. // getBanner({}).then((res) => {
  727. // that.setData({
  728. // bannerList: res
  729. // });
  730. // store.setStore("homeBanner", res);
  731. // })
  732. },
  733. stopIntervalId1: function () {
  734. var that = this;
  735. if (!strings.isEmpty(that.data.intervalId1)) {
  736. clearInterval(that.data.intervalId1);
  737. that.data.intervalId1 = null;
  738. }
  739. },
  740. stopIntervalId2: function () {
  741. var that = this;
  742. if (!strings.isEmpty(that.data.intervalId2)) {
  743. clearInterval(that.data.intervalId2);
  744. that.data.intervalId2 = null;
  745. }
  746. },
  747. ///销毁蓝牙
  748. onUnload() {
  749. var that = this;
  750. that.stopIntervalId1();
  751. that.stopIntervalId2();
  752. if (!strings.isEmpty(that.data.intervalId)) {
  753. clearInterval(that.data.intervalId);
  754. that.data.intervalId = null;
  755. }
  756. BtHelper.getInstance().disconnect();
  757. if (app.globalData.client === null) {
  758. return;
  759. };
  760. app.globalData.client.end(true);
  761. app.globalData.client.end(true);
  762. app.globalData.client = null;
  763. },
  764. })