index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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. // PlayState: ///播放状态:0默认状态,1播放状态,2暂停状态, 3停止状态,4缓冲状态。
  132. case "message":
  133. if (payloads) {
  134. var payloadType = payloads.type;
  135. var other = payloads.other;
  136. ///获取频道位置
  137. if (payloadType === "get_position" && other) {
  138. lexin_message.getPosition(other, function (actionIndex) {
  139. that.setData({
  140. actionIndex: actionIndex,
  141. });
  142. });
  143. }
  144. // 获取歌曲信息
  145. else if (payloadType === "get_dev_info" && other) {
  146. that.setDeviceInfor(other);
  147. lexin_message.getDeviceInfo(payloads);
  148. }
  149. ///获取电量
  150. else if (payloadType === "battery" && other) {
  151. var battery = lexin_message.getDeviceInfo(other.battery);
  152. that.setData({
  153. battery: battery,
  154. });
  155. }
  156. ///获取播放状态
  157. else if (payloadType === "play" || payloadType === "play_state") {
  158. lexin_message.getPlay();
  159. }
  160. }
  161. break;
  162. default:
  163. }
  164. },
  165. ///去连接设备数据
  166. actionDevice(device) {
  167. var that = this;
  168. // 取消订阅
  169. var deviceMacId = that.data.deviceMacId;
  170. if (!strings.isEmpty(deviceMacId)) {
  171. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  172. app.unsubscribe(pubResponse);
  173. };
  174. var deviceId = device.deviceId;
  175. deviceMacId = lexin_util.getDeviceMacId(deviceId);
  176. that.setData({
  177. deviceMacId: deviceMacId,
  178. });
  179. that.subscribeCurrDevice(device);
  180. },
  181. ///数据处理
  182. subscribeCurrDevice(device) {
  183. var that = this;
  184. var isOK = app.globalData.client && app.globalData.client.connected;
  185. if (!isOK) {
  186. app.connect();
  187. setTimeout(() => {
  188. that.subscribeCurrDevice(device);
  189. }, 500);
  190. return;
  191. };
  192. var deviceId = device.deviceId;
  193. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  194. const obj = {
  195. DstDeviceName: deviceMacId
  196. };
  197. /// /AIrSMArT_7cdfa1fd3af0/user/pub_response
  198. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  199. app.subscribe(pubResponse);
  200. app.PubMsg({
  201. type: "get_dev_info",
  202. ...obj
  203. });
  204. },
  205. onTapActionMusic(e) {
  206. var that = this;
  207. var actionIndex = that.data.actionIndex;
  208. if (strings.isEmpty(actionIndex)) {
  209. return;
  210. }
  211. var index = e.currentTarget.dataset.index;
  212. if (index === actionIndex) {
  213. return;
  214. };
  215. var deviceList = that.getDeviceList();
  216. var deviceListSelect = that.getDeviceListSelect();
  217. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  218. wx.showToast({
  219. title: '请选择设备',
  220. icon: "none"
  221. });
  222. return;
  223. };
  224. that.setData({
  225. actionIndex: index,
  226. });
  227. var channelData = that.getChannelData();
  228. var deviceId = deviceList[deviceListSelect].deviceId;
  229. const other = {
  230. "url": "",
  231. "media_data": "",
  232. "user_id": `${app.globalData.userInfo.deviceUid}`,
  233. "timestamp": `${Math.round(new Date() / 1000)}`,
  234. "channel_id": `${channelData[index].channelNum}`,
  235. "order": "",
  236. "resource_from": "",
  237. "songAlbumID": "",
  238. "version": 3,
  239. "is_debug": app.globalData.is_debug
  240. };
  241. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  242. app.PubMsg({
  243. type: "play",
  244. DstDeviceName: deviceMacId,
  245. other
  246. });
  247. },
  248. getchannelData(clientType) {
  249. var that = this;
  250. var deviceList = that.getDeviceList();
  251. var deviceListSelect = that.getDeviceListSelect();
  252. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  253. return;
  254. };
  255. var deviceId = deviceList[deviceListSelect].deviceId;
  256. listByDevice({
  257. clientType: clientType,
  258. unShowLoad: true,
  259. }).then((res) => {
  260. that.setData({
  261. channelData: res
  262. });
  263. // 接收设备当前播放状态
  264. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  265. const obj = {
  266. DstDeviceName: deviceMacId
  267. }
  268. app.PubMsg({
  269. type: "get_position",
  270. ...obj
  271. });
  272. wx.setStorageSync("channelData", res);
  273. })
  274. },
  275. ///去频道详情
  276. onTapToChannel() {
  277. var that = this;
  278. var actionIndex = that.data.actionIndex;
  279. if (strings.isEmpty(actionIndex)) {
  280. return;
  281. }
  282. var channelData = that.getChannelData();
  283. if (channelData.length > actionIndex) {
  284. wx.setStorageSync("channelDeta", channelData[actionIndex]);
  285. wx.navigateTo({
  286. url: './../channelDetails/channelDetails'
  287. });
  288. }
  289. },
  290. onTapIndex(e) {
  291. var that = this;
  292. var index = e.currentTarget.dataset.index;
  293. var indexPage = that.data.indexPage;
  294. if (indexPage != index) {
  295. that.setData({
  296. indexPage: index,
  297. });
  298. }
  299. },
  300. onTapLogin() {
  301. var that = this;
  302. ///退出登录
  303. var isLogin = that.getIsLogin();
  304. if (isLogin) {
  305. that.logOut();
  306. return;
  307. }
  308. route_util.jump(route_constant.login);
  309. },
  310. ///退出登录
  311. logOut() {
  312. var that = this;
  313. wx.removeStorageSync('userInfo');
  314. wx.removeStorageSync('token');
  315. var nickName = "未登录";
  316. var greeting = that.getGreetBuNickName(nickName);
  317. that.setData({
  318. isLogin: false,
  319. greeting: greeting,
  320. nickName: nickName,
  321. userPic: "./../../img/head_pic.png",
  322. });
  323. var deviceList = that.getDeviceList();
  324. var deviceListSelect = that.getDeviceListSelect();
  325. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  326. return;
  327. };
  328. ///有设备在线被选中,则让它不被选择
  329. if (deviceList[deviceListSelect].connectType == 3) {
  330. var deviceMacId = that.data.deviceMacId;
  331. if (!strings.isEmpty(deviceMacId)) {
  332. var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
  333. app.unsubscribe(pubResponse);
  334. that.setData({
  335. actionIndex: null,
  336. deviceListSelect: null,
  337. });
  338. };
  339. }
  340. },
  341. ///点击item
  342. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  343. onTapItem(e) {
  344. var that = this;
  345. var isLogin = that.getIsLogin();
  346. if (!isLogin) {
  347. route_util.jump(route_constant.login);
  348. return;
  349. }
  350. var index = e.currentTarget.dataset.index;
  351. var device = e.currentTarget.dataset.item;
  352. var connectType = device.connectType;
  353. var deviceListSelect = that.getDeviceListSelect();
  354. // wifi只支持在线点击
  355. if (connectType == 3 && device.state === "online") {
  356. if (index === deviceListSelect) {
  357. that.goWake();
  358. } else {
  359. that.addWifiDevice(device);
  360. }
  361. return;
  362. }
  363. ///去蓝牙连接处理
  364. if (index === deviceListSelect) {
  365. route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
  366. } else if (device.state === "offline") {
  367. console.log("去连接蓝牙")
  368. } else {
  369. // {"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 妙播收音机"}
  370. device.name = device.devName;
  371. BtHelper.getInstance().connect(device, function (data) {
  372. if (data) {
  373. that.addBlueDevice(device);
  374. }
  375. });
  376. }
  377. },
  378. // 去唤醒界面
  379. goWake() {
  380. var that = this;
  381. var deviceList = that.getDeviceList();
  382. var deviceListSelect = that.getDeviceListSelect();
  383. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  384. return
  385. };
  386. var device = deviceList[deviceListSelect];
  387. wx.navigateTo({
  388. url: './../deviceWake/deviceWake?deviceId=' + device.deviceId + "&clientType=" + device.ProdModel,
  389. });
  390. },
  391. ///删除当前设备
  392. deleteDevice(e) {
  393. var that = this;
  394. var index = e.currentTarget.dataset.index;
  395. wx.showModal({
  396. title: '确定删除?',
  397. success: function (res) {
  398. if (res.confirm) {
  399. var deviceList = that.getDeviceList();
  400. if (deviceList[index].connectType == 3) {
  401. that.cancelWifi(index, false);
  402. } else {
  403. that.cancelBlue(index, false);
  404. }
  405. }
  406. }
  407. });
  408. },
  409. ///是否是同一个蓝牙
  410. isTheSameBlue(connectDevice) {
  411. var that = this;
  412. var deviceList = that.getDeviceList();
  413. var deviceListSelect = that.getDeviceListSelect();
  414. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  415. return false;
  416. };
  417. if (deviceList[deviceListSelect].connectType == 3) {
  418. return false;
  419. } else {
  420. if (deviceList[deviceListSelect].deviceId == connectDevice.deviceId) {
  421. return true;
  422. } else {
  423. return false;
  424. }
  425. }
  426. },
  427. ///断开当前的
  428. async cancelCurrent() {
  429. var that = this;
  430. var deviceList = that.getDeviceList();
  431. var deviceListSelect = that.getDeviceListSelect();
  432. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  433. return;
  434. };
  435. if (deviceList[deviceListSelect].connectType == 3) {
  436. await that.cancelWifi(deviceListSelect, true);
  437. } else {
  438. await that.cancelBlue(deviceListSelect, true);
  439. }
  440. },
  441. /// 断开蓝牙连接
  442. async cancelBlue(index, onlyCancel) {
  443. var that = this;
  444. if (onlyCancel) {
  445. return;
  446. }
  447. var deviceList = that.getDeviceList();
  448. var deviceId = deviceList[index].deviceId;
  449. ///删除当前设备
  450. deviceList = deviceList.filter((item, i) => {
  451. return deviceId !== item.deviceId;
  452. });
  453. store.setStore("deviceList", deviceList);
  454. that.setData({
  455. deviceListSelect: null,
  456. deviceList: deviceList,
  457. });
  458. },
  459. /// 断开连接wifi
  460. async cancelWifi(index, onlyCancel) {
  461. var that = this;
  462. var deviceList = that.getDeviceList();
  463. if (index === null || deviceList.length <= index) {
  464. return;
  465. };
  466. var deviceId = deviceList[index].deviceId;
  467. // 取消订阅
  468. var pubResponse = lexin_util.getResponseByDeviceId(deviceId);
  469. app.unsubscribe(pubResponse);
  470. if (onlyCancel) {
  471. return;
  472. }
  473. deviceList = deviceList.filter((item, i) => {
  474. return deviceId !== item.deviceId;
  475. });
  476. store.setStore("deviceList", deviceList);
  477. that.setData({
  478. deviceList: deviceList,
  479. deviceMacId: null,
  480. actionIndex: null,
  481. deviceListSelect: null,
  482. });
  483. },
  484. // 新添加Wifi设备
  485. addWifiDevice(device) {
  486. var that = this;
  487. var that = this;
  488. var isOK = app.globalData.client && app.globalData.client.connected;
  489. if (!isOK) {
  490. app.connect();
  491. setTimeout(() => {
  492. that.addWifiDevice(device);
  493. }, 500);
  494. return;
  495. };
  496. var deviceId = device.deviceId;
  497. var addDeviceList = lexin_add.addWifiDevice(device);
  498. that.updateDeviceList(addDeviceList, false, false);
  499. that.setData({
  500. deviceListSelect: null,
  501. connectDeviceIding: deviceId,
  502. });
  503. lexin_subscribe.subscribeSingleDevice(deviceId);
  504. },
  505. refreshCurrentDevice(device) {
  506. var that = this;
  507. var deviceList = that.getDeviceList();
  508. var selectIndex = null;
  509. for (var i = 0; i < deviceList.length; i++) {
  510. if (device.deviceId == deviceList[i].deviceId) {
  511. selectIndex = i;
  512. break;
  513. }
  514. }
  515. if (selectIndex != null) {
  516. var addDeviceList = lexin_add.addWifiDevice(device);
  517. that.updateDeviceList(addDeviceList, false, false);
  518. that.setData({
  519. autoConnected: true,
  520. deviceListSelect: selectIndex,
  521. connectDeviceIding: "",
  522. });
  523. }
  524. },
  525. /// 新添加蓝牙设备
  526. addBlueDevice(device) {
  527. var that = this;
  528. var addDeviceList = lexin_add.addBlueDevice(device);
  529. that.updateDeviceList(addDeviceList, false, false);
  530. that.setData({
  531. deviceListSelect: 0,
  532. autoConnected: true,
  533. });
  534. },
  535. /// 手机关闭蓝牙,所有蓝牙设备离线
  536. closeBlueResetOffline(isInit, closeAllBlue) {
  537. var that = this;
  538. var deviceList = that.getDeviceList();
  539. that.updateDeviceList(deviceList, isInit, closeAllBlue);
  540. },
  541. /// 更新列表排序
  542. updateDeviceList(deviceList, isInit, closeAllBlue) {
  543. var that = this;
  544. var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
  545. if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
  546. store.setStore("deviceList", finalList);
  547. that.setData({
  548. deviceList: finalList,
  549. });
  550. }
  551. },
  552. ///点击banner事件
  553. onTapBanner() {
  554. var that = this;
  555. var item = e.currentTarget.dataset.item;
  556. },
  557. ///添加设备
  558. jumpToAddDevice() {
  559. var that = this;
  560. var isLogin = that.getIsLogin();
  561. if (!isLogin) {
  562. route_util.jump(route_constant.login);
  563. return;
  564. }
  565. route_util.jump(route_constant.deviceList);
  566. },
  567. // 关于我们
  568. jumpToAboutUs() {
  569. lexin_jump.toAboutUs();
  570. },
  571. /// 是否已登录
  572. getIsLogin() {
  573. var that = this;
  574. var isLogin = that.data.isLogin;
  575. return isLogin;
  576. },
  577. /// 获取列表数据
  578. getDeviceList() {
  579. var that = this;
  580. var deviceList = that.data.deviceList;
  581. return deviceList;
  582. },
  583. ///获取当前选中的
  584. getDeviceListSelect() {
  585. var that = this;
  586. var deviceListSelect = that.data.deviceListSelect;
  587. return deviceListSelect;
  588. },
  589. ///获取是否已经第一次连接过
  590. getAutoConnected() {
  591. var that = this;
  592. var autoConnected = that.data.autoConnected;
  593. return autoConnected;
  594. },
  595. ///当前正在连接的设备id
  596. getConnectDeviceIding() {
  597. var that = this;
  598. var connectDeviceIding = that.data.connectDeviceIding
  599. return connectDeviceIding;
  600. },
  601. ///获取频道数据
  602. getChannelData() {
  603. var that = this;
  604. var channelData = that.data.channelData;
  605. return channelData;
  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. // wx.setStorageSync("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. })