index.js 21 KB

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