index.js 21 KB

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