index.js 20 KB

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