index.js 23 KB

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