index.js 21 KB

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