index.js 21 KB

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