index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. // 获取应用实例
  2. const app = getApp();
  3. const {
  4. getDevices,
  5. login,
  6. listByDevice
  7. } = require('../../utils/api.js');
  8. const {
  9. isCN
  10. } = require('../../utils/util.js');
  11. let _this = null;
  12. const interval = null;
  13. // import routeUtil from '../../utils/route_util.js'
  14. import routeUtil from '../../utils/route_util'
  15. import route_constant from '../../utils/route_constant.js'
  16. Page({
  17. data: {
  18. nvabarData: {
  19. showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
  20. title: 'OhPlay', //导航栏 中间的标题
  21. },
  22. bannerList: [
  23. // {
  24. // imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
  25. // },
  26. // {
  27. // imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
  28. // },
  29. // {
  30. // imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
  31. // }
  32. ],
  33. autoplay: true,
  34. interval: 3000, // 切换时间间隔
  35. duration: 500, // 滑动动画时长
  36. circular: true, // 衔接滑动
  37. indexPage: 0,
  38. ///是否展示频道
  39. showChannel: false,
  40. ////首页
  41. navBarHeight: app.globalData.navBarHeight,
  42. MenuButtonheight: app.globalData.MenuButtonheight,
  43. MenuButtonTop: app.globalData.MenuButtonTop,
  44. actionIndex: null,
  45. luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
  46. channelData: [],
  47. deviceList: [{
  48. "deviceId": "BLUFI_7cdfa1fcbb24",
  49. "name": "BLUFI_7cdfa1fcbb24",
  50. "state": "online",
  51. "ProdModel": "MW-2AX(WIFI-N)",
  52. "devName": "猫王小王子OTR-X"
  53. }, {
  54. "deviceId": "BLUFI_7cdfa1fcbb24",
  55. "name": "BLUFI_7cdfa1fcbb24",
  56. "state": "online",
  57. "ProdModel": "MW-2AX(WIFI-N)",
  58. "devName": "猫王小王子OTR-X"
  59. }, {
  60. "deviceId": "BLUFI_7cdfa1fcbb24",
  61. "name": "BLUFI_7cdfa1fcbb24",
  62. "state": "online",
  63. "ProdModel": "MW-2AX(WIFI-N)",
  64. "devName": "猫王小王子OTR-X"
  65. }, {
  66. "deviceId": "BLUFI_7cdfa1fcbb24",
  67. "name": "BLUFI_7cdfa1fcbb24",
  68. "state": "online",
  69. "ProdModel": "MW-2AX(WIFI-N)",
  70. "devName": "猫王小王子OTR-X"
  71. }, {
  72. "deviceId": "BLUFI_7cdfa1fcbb24",
  73. "name": "BLUFI_7cdfa1fcbb24",
  74. "state": "online",
  75. "ProdModel": "MW-2AX(WIFI-N)",
  76. "devName": "猫王小王子OTR-X"
  77. }, {
  78. "deviceId": "BLUFI_7cdfa1fcbb24",
  79. "name": "BLUFI_7cdfa1fcbb24",
  80. "state": "online",
  81. "ProdModel": "MW-2AX(WIFI-N)",
  82. "devName": "猫王小王子OTR-X"
  83. }, {
  84. "deviceId": "BLUFI_7cdfa1fcbb24",
  85. "name": "BLUFI_7cdfa1fcbb24",
  86. "state": "online",
  87. "ProdModel": "MW-2AX(WIFI-N)",
  88. "devName": "猫王小王子OTR-X"
  89. }, {
  90. "deviceId": "BLUFI_7cdfa1fcbb24",
  91. "name": "BLUFI_7cdfa1fcbb24",
  92. "state": "online",
  93. "ProdModel": "MW-2AX(WIFI-N)",
  94. "devName": "猫王小王子OTR-X"
  95. }],
  96. deviceListIndex: null,
  97. showLogin: false,
  98. isOneLoading: true,
  99. uid: null,
  100. isSetWake: false,
  101. thisDeviceMac: null,
  102. battery: 4, // 0≤电量<20,0格
  103. newVersion: false,
  104. ////我的界面
  105. loginStatus: true,
  106. userName: "未登录",
  107. userPic: './../../img/head_pic.png',
  108. islogin: false,
  109. },
  110. onLoad(options) {
  111. var that = this;
  112. that.onHomeLoad();
  113. that.onMeLoad();
  114. },
  115. onShow() {
  116. var that = this;
  117. that.onHomeShow();
  118. that.onMeShow();
  119. getDevices({}).then((res) => {
  120. console.log("gadfadfqwwerqewqr===" + JSON.stringify(res));
  121. // wx.setStorage({
  122. // key: "channelData",
  123. // data: res
  124. // });
  125. })
  126. },
  127. onHomeLoad() {
  128. _this = this;
  129. // 版本自动更新代码
  130. const updateManager = wx.getUpdateManager();
  131. updateManager.onUpdateReady(function () {
  132. _this.setData({
  133. newVersion: true
  134. });
  135. })
  136. updateManager.onUpdateFailed(function () {
  137. // 新的版本下载失败
  138. wx.showModal({
  139. title: '已有新版本咯',
  140. content: '请您删除当前小程序,重新打开呦~',
  141. showCancel: false
  142. })
  143. })
  144. wx.showLoading({
  145. title: '加载中',
  146. });
  147. const str = setTimeout(() => {
  148. clearTimeout(str);
  149. if (_this.data.isOneLoading) {
  150. _this.setData({
  151. isOneLoading: false,
  152. });
  153. }
  154. }, 500);
  155. // 获取缓存的频道数据
  156. wx.getStorage({
  157. key: "channelData",
  158. success(res) {
  159. _this.setData({
  160. channelData: res.data
  161. })
  162. }
  163. });
  164. // 登录
  165. this.login();
  166. },
  167. onMeLoad() {
  168. // wx.getStorage("userInfo")
  169. const _this = this;
  170. wx.getStorage({
  171. key: "userInfo",
  172. success(res) {
  173. if (!res.data.phone) {
  174. return;
  175. };
  176. _this.setData({
  177. userName: res.data.nickname || "",
  178. userPic: res.data.headUrl || "",
  179. islogin: true,
  180. })
  181. }
  182. })
  183. },
  184. onHomeShow() {
  185. if ((!this.data.isOneLoading)) {
  186. wx.getStorage({
  187. key: 'userInfo',
  188. fail(res) {
  189. // 取消订阅
  190. if (_this.data.thisDeviceMac !== null) {
  191. app.unsubscribe(`/${_this.data.thisDeviceMac}/user/pub_response`);
  192. };
  193. _this.setData({
  194. showLogin: true,
  195. });
  196. },
  197. success() {
  198. if (app.globalData.newDeviceId) {
  199. // 获取设备本地数据
  200. _this.getDeviceData();
  201. } else if (_this.data.deviceListIndex !== null) {
  202. // 更新
  203. _this.actionDevice(_this.data.deviceListIndex);
  204. }
  205. }
  206. });
  207. };
  208. },
  209. onMeShow() {
  210. this.onLoad();
  211. },
  212. ////开始是home的
  213. login() {
  214. wx.login({
  215. success: res => {
  216. let phone = undefined;
  217. try {
  218. var value = wx.getStorageSync('userInfo')
  219. if (value) {
  220. phone = value.phone || undefined;
  221. };
  222. } catch (e) {
  223. // Do something when catch error
  224. };
  225. // 请求登录
  226. login({
  227. code: res.code,
  228. phone
  229. }).then((res) => {
  230. app.globalData.userInfo = res;
  231. wx.setStorage({
  232. key: "userInfo",
  233. data: res
  234. });
  235. // 需要用授权登录
  236. if ((res.isNewUser && res.isNewUser === true) || !phone) {
  237. _this.setData({
  238. showLogin: true,
  239. });
  240. return;
  241. };
  242. // 获取设备本地数据
  243. this.getDeviceData();
  244. _this.setData({
  245. showLogin: false,
  246. });
  247. wx.setStorage({
  248. key: "token",
  249. data: JSON.stringify({
  250. id: res.userId,
  251. token: res.accessToken,
  252. }),
  253. });
  254. });
  255. },
  256. })
  257. },
  258. ///开始时home的
  259. getDeviceData() {
  260. // 获取设备数据
  261. wx.getStorage({
  262. key: 'devicelist',
  263. success(res) {
  264. wx.hideLoading();
  265. if (res.data) {
  266. const resData = JSON.parse(res.data);
  267. console.log("本地设备列表", resData)
  268. _this.setData({
  269. deviceList: resData
  270. });
  271. // 连接mqtt
  272. if (app.globalData.client === null) {
  273. app.connect();
  274. } else if (app.globalData.newDeviceId) {
  275. _this.setData({
  276. actionIndex: null,
  277. deviceListIndex: null,
  278. });
  279. // 监听
  280. let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
  281. app.subscribe(topic);
  282. const Timeout = setTimeout(() => {
  283. clearTimeout(Timeout);
  284. _this.actionDevice(0);
  285. }, 1000);
  286. }
  287. // // 有新设备
  288. // if(app.globalData.newDeviceId) {
  289. // _this.setData({
  290. // actionIndex: null,
  291. // deviceListIndex: null,
  292. // });
  293. // let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
  294. // app.subscribe(topic);
  295. // }
  296. }
  297. },
  298. fail(e) {
  299. wx.hideLoading();
  300. }
  301. });
  302. },
  303. // 回调
  304. mqttCallback(type, option) {
  305. // console.log("gadsfadsfqwerq===" + type + "===" + option);
  306. let payloads = null;
  307. if (option) {
  308. payloads = JSON.parse(option.payload);
  309. };
  310. switch (type) {
  311. case "connect":
  312. _this.connectSuccess();
  313. break;
  314. case "message_onoffline":
  315. _this.online(payloads);
  316. break;
  317. case "message":
  318. // 接收设备播放信息
  319. if (payloads.type === "get_position" && payloads.other) {
  320. let actionIndex = null;
  321. _this.data.channelData.map((v, index) => {
  322. if (v.channelNum === payloads.other.channel) {
  323. actionIndex = index;
  324. }
  325. });
  326. _this.setData({
  327. actionIndex,
  328. });
  329. } else if (payloads.type === "play" || payloads.type === "play_state") {
  330. if (_this.data.deviceListIndex === null) {
  331. return;
  332. }
  333. // 接收设备当前播放状态
  334. const obj = {
  335. DstDeviceName: _this.getThisDeviceID()
  336. }
  337. app.PubMsg({
  338. type: "get_position",
  339. ...obj
  340. });
  341. } else if (payloads.type === "get_dev_info") {
  342. // 接收设备当前信息
  343. this.getchannelData(payloads.other.ProdModel);
  344. // 电量
  345. _this.setData({
  346. battery: _this._battery(payloads.other.Power),
  347. })
  348. // 当前设备木有设置定时
  349. _this.setData({
  350. isSetWake: false,
  351. });
  352. payloads.other.alarm.map((v) => {
  353. if (v.enable === "1") {
  354. _this.setData({
  355. isSetWake: true
  356. });
  357. }
  358. });
  359. // 更新信息
  360. _this.data.deviceList.map((v, index) => {
  361. if (payloads.SrcDeviceName && payloads.SrcDeviceName.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
  362. _this.data.deviceList[index].ProdModel = payloads.other.ProdModel;
  363. _this.data.deviceList[index].devName = payloads.other.devName;
  364. }
  365. });
  366. // 更新缓存
  367. wx.setStorage({
  368. key: "devicelist",
  369. data: JSON.stringify(_this.data.deviceList),
  370. success() {
  371. _this.setData({
  372. deviceList: _this.data.deviceList
  373. })
  374. }
  375. });
  376. } else if (payloads.type === "battery" && payloads.other) {
  377. _this.setData({
  378. battery: _this._battery(payloads.other.battery),
  379. })
  380. }
  381. break;
  382. default:
  383. }
  384. },
  385. // 格式化电量
  386. _battery(battery) {
  387. let _battery = 0;
  388. if (battery < 20) {
  389. _battery = 0
  390. } else if (20 <= battery && battery < 40) {
  391. _battery = 1
  392. } else if (40 <= battery && battery < 60) {
  393. _battery = 2
  394. } else if (60 <= battery && battery < 80) {
  395. _battery = 3
  396. } else if (80 <= battery && battery <= 100) {
  397. _battery = 4
  398. } else if (battery > 100) {
  399. _battery = 5
  400. };
  401. return _battery
  402. },
  403. connectSuccess() {
  404. // 订阅设备在线信息
  405. _this.subscribeDevicesStatus();
  406. },
  407. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  408. online(payloads) {
  409. // 设置在线状态
  410. _this.data.deviceList.map((v, index) => {
  411. if (payloads.uuid && payloads.uuid.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
  412. _this.data.deviceList[index].state = payloads.state;
  413. }
  414. });
  415. _this.setData({
  416. deviceList: _this.data.deviceList,
  417. });
  418. // 更新缓存
  419. wx.setStorage({
  420. key: "devicelist",
  421. data: JSON.stringify(_this.data.deviceList)
  422. });
  423. // 如没有选中,选中最新的
  424. (() => {
  425. if (_this.data.deviceListIndex === null) {
  426. let itue = false;
  427. _this.data.deviceList.map((v, index) => {
  428. if (v.state === "online" && !itue) {
  429. itue = true;
  430. _this.actionDevice(index);
  431. }
  432. });
  433. }
  434. // else {
  435. // _this.actionDevice(_this.data.deviceListIndex);
  436. // };
  437. })();
  438. // 当前播放设备离线
  439. if (_this.data.deviceListIndex !== null && _this.data.deviceList[_this.data.deviceListIndex].state !== "online") {
  440. _this.setData({
  441. actionIndex: null,
  442. deviceListIndex: null,
  443. });
  444. };
  445. },
  446. // 订阅设备在线状态
  447. subscribeDevicesStatus() {
  448. this.data.deviceList.forEach((value) => {
  449. let topic = `/AIrSMArT_${value.name.split("BLUFI_")[1]}/status/onoffline`;
  450. app.subscribe(topic);
  451. })
  452. },
  453. subscribeCurrDevice() {
  454. if (!(app.globalData.client && app.globalData.client.connected)) {
  455. console.log("未连接MQTT服务器");
  456. const str = setInterval(() => {
  457. clearInterval(str);
  458. _this.subscribeCurrDevice();
  459. }, 500);
  460. return;
  461. };
  462. if (this.data.deviceList.length === 0 || this.data.deviceListIndex === null) {
  463. return
  464. };
  465. let topic = `/AIrSMArT_${this.data.deviceList[this.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
  466. app.subscribe(topic);
  467. const obj = {
  468. DstDeviceName: _this.getThisDeviceID()
  469. };
  470. app.PubMsg({
  471. type: "get_dev_info",
  472. ...obj
  473. });
  474. },
  475. actionMusic(e) {
  476. if (e.currentTarget.dataset.index === this.data.actionIndex) {
  477. return;
  478. };
  479. if (this.data.deviceListIndex === null) {
  480. wx.showToast({
  481. title: '请选择设备',
  482. icon: "none"
  483. })
  484. return;
  485. };
  486. this.setData({
  487. actionIndex: e.currentTarget.dataset.index
  488. });
  489. const other = {
  490. "url": "",
  491. "media_data": "",
  492. "user_id": `${app.globalData.userInfo.deviceUid}`,
  493. "timestamp": `${Math.round(new Date() / 1000)}`,
  494. "channel_id": `${this.data.channelData[e.currentTarget.dataset.index].channelNum}`,
  495. "order": "",
  496. "resource_from": "",
  497. "songAlbumID": "",
  498. "version": 3,
  499. "is_debug": app.globalData.is_debug
  500. };
  501. app.PubMsg({
  502. type: "play",
  503. DstDeviceName: _this.getThisDeviceID(),
  504. other
  505. });
  506. },
  507. actionDeviceIndex(e) {
  508. if (e.currentTarget.dataset.index === this.data.deviceListIndex) {
  509. return
  510. };
  511. this.actionDevice(e.currentTarget.dataset.index)
  512. },
  513. actionDevice(index) {
  514. const device = this.data.deviceList[index];
  515. if (device.state !== "online") {
  516. return;
  517. };
  518. // 取消订阅
  519. if (this.data.thisDeviceMac !== null) {
  520. app.unsubscribe(`/${this.data.thisDeviceMac}/user/pub_response`);
  521. };
  522. this.setData({
  523. deviceListIndex: index,
  524. thisDeviceMac: `AIrSMArT_${this.data.deviceList[index].name.split("BLUFI_")[1]}`
  525. });
  526. // app.PubMsg({
  527. // type: "get_dev_info",
  528. // DstDeviceName: _this.getThisDeviceID()
  529. // });
  530. this.subscribeCurrDevice();
  531. },
  532. getThisDeviceID() {
  533. return `AIrSMArT_${this.data.deviceList[this.data.deviceListIndex].name.split("BLUFI_")[1]}`
  534. },
  535. getchannelData(clientType) {
  536. let _this = this;
  537. if (this.data.deviceListIndex === null) {
  538. return;
  539. };
  540. listByDevice({
  541. clientType
  542. }).then((res) => {
  543. _this.setData({
  544. channelData: res
  545. });
  546. // 接收设备当前播放状态
  547. const obj = {
  548. DstDeviceName: _this.getThisDeviceID()
  549. }
  550. app.PubMsg({
  551. type: "get_position",
  552. ...obj
  553. });
  554. wx.setStorage({
  555. key: "channelData",
  556. data: res
  557. });
  558. // 有新设备
  559. if (app.globalData.newDeviceId) {
  560. app.globalData.newDeviceId = null;
  561. return;
  562. // 去掉此功能,先留着吧
  563. // const other= {
  564. // "url": "",
  565. // "media_data": "",
  566. // "user_id": `${app.globalData.userInfo.deviceUid}`,
  567. // "timestamp": `${Math.round(new Date() / 1000)}`,
  568. // "channel_id": `${res[1].channelNum}`,
  569. // "order": "",
  570. // "resource_from": "",
  571. // "songAlbumID":"",
  572. // "version":3,
  573. // "is_debug": app.globalData.is_debug
  574. // };
  575. // app.PubMsg({
  576. // type: "play",
  577. // DstDeviceName: _this.getThisDeviceID(),
  578. // other
  579. // });
  580. }
  581. })
  582. },
  583. goChnnel() {
  584. wx.setStorage({
  585. key: "channelDeta",
  586. data: this.data.channelData[this.data.actionIndex],
  587. success() {
  588. wx.navigateTo({
  589. url: './../channelDetails/channelDetails'
  590. })
  591. }
  592. })
  593. },
  594. updata() {
  595. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  596. wx.getUpdateManager().applyUpdate()
  597. },
  598. updataClone() {
  599. this.setData({
  600. newVersion: false
  601. })
  602. },
  603. onUnload() {
  604. if (app.globalData.client === null) {
  605. return;
  606. };
  607. app.globalData.client.end(true);
  608. app.globalData.client.end(true);
  609. app.globalData.client = null;
  610. },
  611. onTapIndex(e) {
  612. var that = this;
  613. var index = e.currentTarget.dataset.index;
  614. var indexPage = that.data.indexPage;
  615. if (indexPage != index) {
  616. that.setData({
  617. indexPage: index,
  618. });
  619. }
  620. },
  621. goMeAbout() {
  622. wx.navigateTo({
  623. url: './../about/about',
  624. })
  625. },
  626. goMeLogin() {
  627. const _this = this;
  628. if (this.data.islogin) {
  629. // 退出登录
  630. wx.removeStorage({
  631. key: 'userInfo',
  632. success(res) {
  633. _this.setData({
  634. islogin: false,
  635. userName: "未登录",
  636. userPic: "./../../img/head_pic.png",
  637. });
  638. wx.switchTab({
  639. url: `./../index/index`
  640. });
  641. }
  642. });
  643. wx.removeStorage({
  644. key: 'token',
  645. })
  646. } else {
  647. // 登录
  648. wx.navigateTo({
  649. url: './../login/login',
  650. });
  651. }
  652. },
  653. addDevice() {
  654. var that = this;
  655. var showLogin = that.data.showLogin;
  656. if (showLogin) {
  657. wx.navigateTo({
  658. url: './../login/login'
  659. });
  660. return;
  661. }
  662. that.goDeviceConnect();
  663. },
  664. goDeviceConnect() {
  665. wx.navigateTo({
  666. url: './../deviceConnect0/deviceConnect0',
  667. });
  668. },
  669. ///点击item
  670. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  671. onTapIem(e) {
  672. var that = this;
  673. var item = e.currentTarget.dataset.item;
  674. var devName = item.devName;
  675. if (devName == "猫王小王子OTR-X") {
  676. that.goWake();
  677. return;
  678. }
  679. },
  680. goWake() {
  681. if (this.data.deviceListIndex === null) {
  682. return;
  683. };
  684. wx.navigateTo({
  685. url: './../deviceWake/deviceWake?deviceId=' + this.data.deviceList[this.data.deviceListIndex].deviceId + "&clientType=" + this.data.deviceList[this.data.deviceListIndex].ProdModel,
  686. });
  687. },
  688. deleteDevice(e) {
  689. wx.showModal({
  690. title: '确定删除?',
  691. success: function (res) {
  692. if (res.confirm) {
  693. const id = this.data.deviceList[e.currentTarget.dataset.index].deviceId;
  694. let name = _this.data.deviceListIndex !== null ? this.data.deviceList[_this.data.deviceListIndex].name : null;
  695. const deviceList = this.data.deviceList.filter((v, i) => {
  696. return id !== v.deviceId
  697. });
  698. // 取消订阅
  699. app.unsubscribe(`/AIrSMArT_${_this.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
  700. wx.setStorage({
  701. key: "devicelist",
  702. data: JSON.stringify(deviceList),
  703. success() {
  704. _this.setData({
  705. deviceList,
  706. thisDeviceMac: null
  707. });
  708. // 当前没有设备
  709. if (deviceList.length === 0) {
  710. _this.setData({
  711. actionIndex: null,
  712. deviceListIndex: null,
  713. });
  714. }
  715. if (_this.data.deviceListIndex === null) {
  716. return
  717. };
  718. if (e.currentTarget.dataset.index === _this.data.deviceListIndex) {
  719. let index_ = null;
  720. deviceList.map((v, index) => {
  721. if (v.state === "online" && index_ === null) {
  722. index_ = index;
  723. }
  724. });
  725. if (index_ !== null) {
  726. _this.actionDevice(index_);
  727. } else {
  728. _this.setData({
  729. actionIndex: null,
  730. deviceListIndex: null,
  731. });
  732. };
  733. } else {
  734. deviceList.map((v, index) => {
  735. if (v.name === name) {
  736. _this.setData({
  737. deviceListIndex: index,
  738. });
  739. }
  740. });
  741. }
  742. }
  743. });
  744. }
  745. }
  746. });
  747. },
  748. })