index.js 23 KB

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