index.js 20 KB

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