index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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. var deviceId = device.deviceId;
  174. deviceMacId = lexin_util.getDeviceMacId(deviceId);
  175. that.setData({
  176. deviceMacId: deviceMacId,
  177. });
  178. that.subscribeCurrDevice(device);
  179. },
  180. ///数据处理
  181. subscribeCurrDevice(device) {
  182. var that = this;
  183. var isOK = app.globalData.client && app.globalData.client.connected;
  184. if (!isOK) {
  185. app.connect();
  186. setTimeout(() => {
  187. that.subscribeCurrDevice(device);
  188. }, 500);
  189. return;
  190. };
  191. var deviceId = device.deviceId;
  192. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  193. const obj = {
  194. DstDeviceName: deviceMacId
  195. };
  196. /// /AIrSMArT_7cdfa1fd3af0/user/pub_response
  197. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  198. app.subscribe(pubResponse);
  199. app.PubMsg({
  200. type: "get_dev_info",
  201. ...obj
  202. });
  203. },
  204. ///选择对应的频道
  205. onTapChannelIndex(e) {
  206. var that = this;
  207. var index = e.currentTarget.dataset.index;
  208. lexin_jump.toChannelIndex(index, function (i) {
  209. that.setData({
  210. actionIndex: i,
  211. });
  212. });
  213. },
  214. getchannelData(clientType) {
  215. var that = this;
  216. var deviceList = that.getDeviceList();
  217. var deviceListSelect = that.getDeviceListSelect();
  218. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  219. return;
  220. };
  221. var deviceId = deviceList[deviceListSelect].deviceId;
  222. listByDevice({
  223. clientType: clientType,
  224. unShowLoad: true,
  225. }).then((res) => {
  226. that.setData({
  227. channelData: res
  228. });
  229. // 接收设备当前播放状态
  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. wx.setStorageSync("channelData", res);
  239. })
  240. },
  241. ///去频道详情
  242. onTapToChannel() {
  243. var that = this;
  244. var actionIndex = that.data.actionIndex;
  245. if (strings.isEmpty(actionIndex)) {
  246. return;
  247. }
  248. var channelData = that.getChannelData();
  249. if (channelData.length > actionIndex) {
  250. wx.setStorageSync("channelDeta", channelData[actionIndex]);
  251. wx.navigateTo({
  252. url: './../channelDetails/channelDetails'
  253. });
  254. }
  255. },
  256. onTapIndex(e) {
  257. var that = this;
  258. var index = e.currentTarget.dataset.index;
  259. var indexPage = that.data.indexPage;
  260. if (indexPage != index) {
  261. that.setData({
  262. indexPage: index,
  263. });
  264. }
  265. },
  266. onTapLogin() {
  267. var that = this;
  268. ///退出登录
  269. var isLogin = that.getIsLogin();
  270. if (isLogin) {
  271. that.logOut();
  272. return;
  273. }
  274. route_util.jump(route_constant.login);
  275. },
  276. ///退出登录
  277. logOut() {
  278. var that = this;
  279. wx.removeStorageSync('userInfo');
  280. wx.removeStorageSync('token');
  281. var nickName = "未登录";
  282. var greeting = that.getGreetBuNickName(nickName);
  283. that.setData({
  284. isLogin: false,
  285. greeting: greeting,
  286. nickName: nickName,
  287. userPic: "./../../img/head_pic.png",
  288. });
  289. var deviceList = that.getDeviceList();
  290. var deviceListSelect = that.getDeviceListSelect();
  291. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  292. return;
  293. };
  294. ///有设备在线被选中,则让它不被选择
  295. if (deviceList[deviceListSelect].connectType == 3) {
  296. var deviceMacId = that.data.deviceMacId;
  297. if (!strings.isEmpty(deviceMacId)) {
  298. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  299. app.unsubscribe(pubResponse);
  300. that.setData({
  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 (data) {
  338. if (data) {
  339. that.addBlueDevice(device);
  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(connectDevice) {
  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 == connectDevice.deviceId) {
  387. return true;
  388. } else {
  389. return false;
  390. }
  391. }
  392. },
  393. ///断开当前的
  394. async 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. await that.cancelWifi(deviceListSelect, true);
  403. } else {
  404. await that.cancelBlue(deviceListSelect, true);
  405. }
  406. },
  407. /// 断开蓝牙连接
  408. async cancelBlue(index, onlyCancel) {
  409. var that = this;
  410. if (onlyCancel) {
  411. return;
  412. }
  413. var deviceList = that.getDeviceList();
  414. var deviceId = deviceList[index].deviceId;
  415. ///删除当前设备
  416. deviceList = deviceList.filter((item, i) => {
  417. return deviceId !== item.deviceId;
  418. });
  419. store.setStore("deviceList", deviceList);
  420. that.setData({
  421. deviceListSelect: null,
  422. deviceList: deviceList,
  423. });
  424. },
  425. /// 断开连接wifi
  426. async cancelWifi(index, onlyCancel) {
  427. var that = this;
  428. var deviceList = that.getDeviceList();
  429. if (index === null || deviceList.length <= index) {
  430. return;
  431. };
  432. var deviceId = deviceList[index].deviceId;
  433. // 取消订阅
  434. var pubResponse = lexin_util.getResponseByDeviceId(deviceId);
  435. app.unsubscribe(pubResponse);
  436. if (onlyCancel) {
  437. return;
  438. }
  439. deviceList = deviceList.filter((item, i) => {
  440. return deviceId !== item.deviceId;
  441. });
  442. store.setStore("deviceList", deviceList);
  443. that.setData({
  444. deviceList: deviceList,
  445. deviceMacId: null,
  446. actionIndex: null,
  447. deviceListSelect: null,
  448. });
  449. },
  450. // 新添加Wifi设备
  451. addWifiDevice(device) {
  452. var that = this;
  453. var that = this;
  454. var isOK = app.globalData.client && app.globalData.client.connected;
  455. if (!isOK) {
  456. app.connect();
  457. setTimeout(() => {
  458. that.addWifiDevice(device);
  459. }, 500);
  460. return;
  461. };
  462. var deviceId = device.deviceId;
  463. var addDeviceList = lexin_add.addWifiDevice(device);
  464. that.updateDeviceList(addDeviceList, false, false);
  465. that.setData({
  466. deviceListSelect: null,
  467. connectDeviceIding: deviceId,
  468. });
  469. lexin_subscribe.subscribeSingleDevice(deviceId);
  470. },
  471. refreshCurrentDevice(device) {
  472. var that = this;
  473. var deviceList = that.getDeviceList();
  474. var selectIndex = null;
  475. for (var i = 0; i < deviceList.length; i++) {
  476. if (device.deviceId == deviceList[i].deviceId) {
  477. selectIndex = i;
  478. break;
  479. }
  480. }
  481. if (selectIndex != null) {
  482. var addDeviceList = lexin_add.addWifiDevice(device);
  483. that.updateDeviceList(addDeviceList, false, false);
  484. that.setData({
  485. autoConnected: true,
  486. deviceListSelect: selectIndex,
  487. connectDeviceIding: "",
  488. });
  489. }
  490. },
  491. /// 新添加蓝牙设备
  492. addBlueDevice(device) {
  493. var that = this;
  494. var addDeviceList = lexin_add.addBlueDevice(device);
  495. that.updateDeviceList(addDeviceList, false, false);
  496. that.setData({
  497. deviceListSelect: 0,
  498. autoConnected: true,
  499. });
  500. },
  501. /// 手机关闭蓝牙,所有蓝牙设备离线
  502. closeBlueResetOffline(isInit, closeAllBlue) {
  503. var that = this;
  504. var deviceList = that.getDeviceList();
  505. that.updateDeviceList(deviceList, isInit, closeAllBlue);
  506. },
  507. /// 更新列表排序
  508. updateDeviceList(deviceList, isInit, closeAllBlue) {
  509. var that = this;
  510. var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
  511. if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
  512. store.setStore("deviceList", finalList);
  513. that.setData({
  514. deviceList: finalList,
  515. });
  516. }
  517. },
  518. ///点击banner事件
  519. onTapBanner() {
  520. var that = this;
  521. var item = e.currentTarget.dataset.item;
  522. },
  523. ///添加设备
  524. jumpToAddDevice() {
  525. var that = this;
  526. var isLogin = that.getIsLogin();
  527. if (!isLogin) {
  528. route_util.jump(route_constant.login);
  529. return;
  530. }
  531. route_util.jump(route_constant.deviceList);
  532. },
  533. // 关于我们
  534. jumpToAboutUs() {
  535. lexin_jump.toAboutUs();
  536. },
  537. /// 是否已登录
  538. getIsLogin() {
  539. var that = this;
  540. var isLogin = that.data.isLogin;
  541. return isLogin;
  542. },
  543. /// 获取列表数据
  544. getDeviceList() {
  545. var that = this;
  546. var deviceList = that.data.deviceList;
  547. return deviceList;
  548. },
  549. ///获取当前选中的
  550. getDeviceListSelect() {
  551. var that = this;
  552. var deviceListSelect = that.data.deviceListSelect;
  553. return deviceListSelect;
  554. },
  555. ///获取是否已经第一次连接过
  556. getAutoConnected() {
  557. var that = this;
  558. var autoConnected = that.data.autoConnected;
  559. return autoConnected;
  560. },
  561. ///当前正在连接的设备id
  562. getConnectDeviceIding() {
  563. var that = this;
  564. var connectDeviceIding = that.data.connectDeviceIding
  565. return connectDeviceIding;
  566. },
  567. ///获取频道数据
  568. getChannelData() {
  569. var that = this;
  570. var channelData = that.data.channelData;
  571. return channelData;
  572. },
  573. /// 当前播放频道
  574. getActionIndex() {
  575. var that = this;
  576. var actionIndex = that.data.actionIndex;
  577. return actionIndex;
  578. },
  579. ///设置设备相关信息
  580. setDeviceInfor(other) {
  581. var that = this;
  582. // 接收设备当前信息
  583. that.getchannelData(other.ProdModel);
  584. // 电量
  585. var battery = lexin_message.getDeviceInfo(other.Power);
  586. that.setData({
  587. battery: battery,
  588. })
  589. // 当前设备木有设置定时
  590. that.setData({
  591. isSetWake: false,
  592. });
  593. other.alarm.map((v) => {
  594. if (v.enable === "1") {
  595. that.setData({
  596. isSetWake: true
  597. });
  598. }
  599. });
  600. },
  601. ///******************************* 可折叠 ********************************************///
  602. onUserInfoLoad() {
  603. var that = this;
  604. var userInfo = wx.getStorageSync("userInfo") || "";
  605. if (!strings.isEmpty(userInfo)) {
  606. var phone = userInfo.phone;
  607. if (!phone) {
  608. return;
  609. };
  610. var nickName = userInfo.nickname || "";
  611. var greeting = that.getGreetBuNickName(nickName);
  612. // 获取缓存的频道数据
  613. var channelData = wx.getStorageSync("channelData") || "";
  614. if (!strings.isEmpty(channelData)) {
  615. that.setData({
  616. channelData: channelData,
  617. greeting: greeting,
  618. nickName: nickName,
  619. userPic: userInfo.headUrl || "",
  620. isLogin: true,
  621. })
  622. } else {
  623. that.setData({
  624. greeting: greeting,
  625. nickName: nickName,
  626. userPic: userInfo.headUrl || "",
  627. isLogin: true,
  628. });
  629. }
  630. } else {
  631. var greeting = that.getGreetBuNickName("");
  632. that.setData({
  633. greeting: greeting,
  634. })
  635. }
  636. },
  637. getGreetBuNickName(nickName) {
  638. var greeting = timeUtil.getGreet();
  639. if (nickName != "" && nickName != "未登录") {
  640. greeting = greeting + ',' + nickName;;
  641. }
  642. return greeting;
  643. },
  644. onBannerLoad() {
  645. var that = this;
  646. // var bannerList = wx.getStorageSync("homeBanner") || [];
  647. // if (that.data.bannerList.length > 0) {
  648. // that.setData({
  649. // bannerList: bannerList
  650. // });
  651. // }
  652. },
  653. onBannerShow() {
  654. var that = this;
  655. // getBanner({}).then((res) => {
  656. // that.setData({
  657. // bannerList: res
  658. // });
  659. // wx.setStorageSync("homeBanner", res);
  660. // })
  661. },
  662. stopIntervalId1: function () {
  663. var that = this;
  664. if (!strings.isEmpty(that.data.intervalId1)) {
  665. clearInterval(that.data.intervalId1);
  666. that.data.intervalId1 = null;
  667. }
  668. },
  669. stopIntervalId2: function () {
  670. var that = this;
  671. if (!strings.isEmpty(that.data.intervalId2)) {
  672. clearInterval(that.data.intervalId2);
  673. that.data.intervalId2 = null;
  674. }
  675. },
  676. ///销毁蓝牙
  677. onUnload() {
  678. var that = this;
  679. that.stopIntervalId1();
  680. that.stopIntervalId2();
  681. if (!strings.isEmpty(that.data.intervalId)) {
  682. clearInterval(that.data.intervalId);
  683. that.data.intervalId = null;
  684. }
  685. BtHelper.getInstance().disconnect();
  686. if (app.globalData.client === null) {
  687. return;
  688. };
  689. app.globalData.client.end(true);
  690. app.globalData.client.end(true);
  691. app.globalData.client = null;
  692. },
  693. })