index.js 22 KB

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