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. var deviceMacId = that.data.deviceMacId;
  467. var actionIndex = that.data.actionIndex;
  468. that.setData({
  469. deviceList: deviceList,
  470. deviceMacId: isCurrentIndex ? null : deviceMacId,
  471. actionIndex: isCurrentIndex ? null : actionIndex,
  472. deviceListSelect: isCurrentIndex ? null : deviceListSelect,
  473. indexPage: indexPage == 1 ? 0 : indexPage,
  474. });
  475. },
  476. /// 新添加蓝牙设备
  477. addBlueDevice(device) {
  478. var that = this;
  479. var addDeviceList = lexin_add.addBlueDevice(device);
  480. that.updateDeviceList(addDeviceList, false, false);
  481. that.setData({
  482. deviceListSelect: 0,
  483. autoConnected: true,
  484. });
  485. },
  486. // 新添加Wifi设备
  487. addWifiDevice(device) {
  488. var that = this;
  489. var isOK = app.globalData.client && app.globalData.client.connected;
  490. if (!isOK) {
  491. app.connect();
  492. setTimeout(() => {
  493. that.addWifiDevice(device);
  494. }, 500);
  495. return;
  496. };
  497. var deviceId = device.deviceId;
  498. var addDeviceList = lexin_add.addWifiDevice(device);
  499. that.updateDeviceList(addDeviceList, false, false);
  500. var indexPage = that.data.indexPage;
  501. that.setData({
  502. deviceListSelect: null,
  503. connectDeviceIding: deviceId,
  504. indexPage: indexPage == 1 ? 0 : indexPage,
  505. });
  506. lexin_subscribe.subscribeSingleDevice(device);
  507. },
  508. refreshCurrentDevice(device) {
  509. var that = this;
  510. var deviceList = that.getDeviceList();
  511. var selectIndex = null;
  512. for (var i = 0; i < deviceList.length; i++) {
  513. if (device.deviceId == deviceList[i].deviceId) {
  514. selectIndex = i;
  515. break;
  516. }
  517. }
  518. if (selectIndex != null) {
  519. var addDeviceList = lexin_add.addWifiDevice(device);
  520. that.updateDeviceList(addDeviceList, false, false);
  521. that.setData({
  522. autoConnected: true,
  523. deviceListSelect: selectIndex,
  524. connectDeviceIding: "",
  525. });
  526. }
  527. },
  528. /// 手机关闭蓝牙,所有蓝牙设备离线
  529. closeBlueResetOffline(isInit, closeAllBlue) {
  530. var that = this;
  531. var deviceList = that.getDeviceList();
  532. that.updateDeviceList(deviceList, isInit, closeAllBlue);
  533. },
  534. /// 更新列表排序
  535. updateDeviceList(deviceList, isInit, closeAllBlue) {
  536. var that = this;
  537. var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
  538. if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
  539. store.setStore("deviceList", finalList);
  540. that.setData({
  541. deviceList: finalList,
  542. });
  543. }
  544. },
  545. ///点击banner事件
  546. onTapBanner() {
  547. var that = this;
  548. var item = e.currentTarget.dataset.item;
  549. },
  550. ///添加设备
  551. jumpToAddDevice() {
  552. var that = this;
  553. var isLogin = that.getIsLogin();
  554. if (!isLogin) {
  555. route_util.jump(route_constant.login);
  556. return;
  557. }
  558. route_util.jump(route_constant.deviceList);
  559. },
  560. // 关于我们
  561. jumpToAboutUs() {
  562. lexin_jump.toAboutUs();
  563. },
  564. /// 是否已登录
  565. getIsLogin() {
  566. var that = this;
  567. var isLogin = that.data.isLogin;
  568. return isLogin;
  569. },
  570. /// 获取列表数据
  571. getDeviceList() {
  572. var that = this;
  573. var deviceList = that.data.deviceList;
  574. return deviceList;
  575. },
  576. ///获取当前选中的
  577. getDeviceListSelect() {
  578. var that = this;
  579. var deviceListSelect = that.data.deviceListSelect;
  580. return deviceListSelect;
  581. },
  582. ///获取是否已经第一次连接过
  583. getAutoConnected() {
  584. var that = this;
  585. var autoConnected = that.data.autoConnected;
  586. return autoConnected;
  587. },
  588. ///当前正在连接的设备id
  589. getConnectDeviceIding() {
  590. var that = this;
  591. var connectDeviceIding = that.data.connectDeviceIding
  592. return connectDeviceIding;
  593. },
  594. ///获取频道数据
  595. getChannelData() {
  596. var that = this;
  597. var channelData = that.data.channelData;
  598. return channelData;
  599. },
  600. /// 当前播放频道
  601. getActionIndex() {
  602. var that = this;
  603. var actionIndex = that.data.actionIndex;
  604. return actionIndex;
  605. },
  606. ///设置设备相关信息
  607. setDeviceInfor(other) {
  608. var that = this;
  609. // 接收设备当前信息
  610. that.getchannelData(other.ProdModel);
  611. // 电量
  612. var battery = lexin_message.getDeviceInfo(other.Power);
  613. that.setData({
  614. battery: battery,
  615. })
  616. // 当前设备木有设置定时
  617. that.setData({
  618. isSetWake: false,
  619. });
  620. other.alarm.map((v) => {
  621. if (v.enable === "1") {
  622. that.setData({
  623. isSetWake: true
  624. });
  625. }
  626. });
  627. },
  628. ///******************************* 可折叠 ********************************************///
  629. onUserInfoLoad() {
  630. var that = this;
  631. var userInfo = wx.getStorageSync("userInfo") || "";
  632. if (!strings.isEmpty(userInfo)) {
  633. var phone = userInfo.phone;
  634. if (!phone) {
  635. return;
  636. };
  637. var nickName = userInfo.nickname || "";
  638. var greeting = that.getGreetBuNickName(nickName);
  639. // 获取缓存的频道数据
  640. var channelData = wx.getStorageSync("channelData") || "";
  641. if (!strings.isEmpty(channelData)) {
  642. that.setData({
  643. channelData: channelData,
  644. greeting: greeting,
  645. nickName: nickName,
  646. userPic: userInfo.headUrl || "",
  647. isLogin: true,
  648. })
  649. } else {
  650. that.setData({
  651. greeting: greeting,
  652. nickName: nickName,
  653. userPic: userInfo.headUrl || "",
  654. isLogin: true,
  655. });
  656. }
  657. } else {
  658. var greeting = that.getGreetBuNickName("");
  659. that.setData({
  660. greeting: greeting,
  661. })
  662. }
  663. },
  664. getGreetBuNickName(nickName) {
  665. var greeting = timeUtil.getGreet();
  666. if (nickName != "" && nickName != "未登录") {
  667. greeting = greeting + ',' + nickName;;
  668. }
  669. return greeting;
  670. },
  671. onBannerLoad() {
  672. var that = this;
  673. // var bannerList = wx.getStorageSync("homeBanner") || [];
  674. // if (that.data.bannerList.length > 0) {
  675. // that.setData({
  676. // bannerList: bannerList
  677. // });
  678. // }
  679. },
  680. onBannerShow() {
  681. var that = this;
  682. // getBanner({}).then((res) => {
  683. // that.setData({
  684. // bannerList: res
  685. // });
  686. // store.setStore("homeBanner", res);
  687. // })
  688. },
  689. stopIntervalId1: function () {
  690. var that = this;
  691. if (!strings.isEmpty(that.data.intervalId1)) {
  692. clearInterval(that.data.intervalId1);
  693. that.data.intervalId1 = null;
  694. }
  695. },
  696. stopIntervalId2: function () {
  697. var that = this;
  698. if (!strings.isEmpty(that.data.intervalId2)) {
  699. clearInterval(that.data.intervalId2);
  700. that.data.intervalId2 = null;
  701. }
  702. },
  703. ///销毁蓝牙
  704. onUnload() {
  705. var that = this;
  706. that.stopIntervalId1();
  707. that.stopIntervalId2();
  708. if (!strings.isEmpty(that.data.intervalId)) {
  709. clearInterval(that.data.intervalId);
  710. that.data.intervalId = null;
  711. }
  712. BtHelper.getInstance().disconnect();
  713. if (app.globalData.client === null) {
  714. return;
  715. };
  716. app.globalData.client.end(true);
  717. app.globalData.client.end(true);
  718. app.globalData.client = null;
  719. },
  720. })