index.js 21 KB

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