ソースを参照

feature: 整理

Damon 8 ヶ月 前
コミット
91adf4a517
1 ファイル変更71 行追加67 行削除
  1. 71 67
      pages/index/index.js

+ 71 - 67
pages/index/index.js

@@ -566,80 +566,16 @@ Page({
     })
   },
 
-  deleteDevice(e) {
-    wx.showModal({
-      title: '确定删除?',
-      success: function (res) {
-        if (res.confirm) {
-          const id = this.data.deviceList[e.currentTarget.dataset.index].deviceId;
-          let name = _this.data.deviceListIndex !== null ? this.data.deviceList[_this.data.deviceListIndex].name : null;
-          const deviceList = this.data.deviceList.filter((v, i) => {
-            return id !== v.deviceId
-          });
-          // 取消订阅
-          app.unsubscribe(`/AIrSMArT_${_this.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
-
-          wx.setStorage({
-            key: "devicelist",
-            data: JSON.stringify(deviceList),
-            success() {
-
-              _this.setData({
-                deviceList,
-                thisDeviceMac: null
-              });
-
-              // 当前没有设备
-              if (deviceList.length === 0) {
-                _this.setData({
-                  actionIndex: null,
-                  deviceListIndex: null,
-                });
-              }
-
-              if (_this.data.deviceListIndex === null) {
-                return
-              };
-              if (e.currentTarget.dataset.index === _this.data.deviceListIndex) {
-                let index_ = null;
-                deviceList.map((v, index) => {
-                  if (v.state === "online" && index_ === null) {
-                    index_ = index;
-                  }
-                });
-                if (index_ !== null) {
-                  _this.actionDevice(index_);
-                } else {
-                  _this.setData({
-                    actionIndex: null,
-                    deviceListIndex: null,
-                  });
-                };
-              } else {
-                deviceList.map((v, index) => {
-                  if (v.name === name) {
-                    _this.setData({
-                      deviceListIndex: index,
-                    });
-                  }
-                });
-              }
-            }
-          });
-        }
-      }
-    });
-
-  },
   goWake() {
     if (this.data.deviceListIndex === null) {
       return;
     };
+
     wx.navigateTo({
       url: './../deviceWake/deviceWake?deviceId=' + this.data.deviceList[this.data.deviceListIndex].deviceId + "&clientType=" + this.data.deviceList[this.data.deviceListIndex].ProdModel,
     });
-
   },
+
   goChnnel() {
     wx.setStorage({
       key: "channelDeta",
@@ -650,17 +586,19 @@ Page({
         })
       }
     })
-
   },
+
   updata() {
     // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
     wx.getUpdateManager().applyUpdate()
   },
+
   updataClone() {
     this.setData({
       newVersion: false
     })
   },
+
   onUnload() {
     if (app.globalData.client === null) {
       return;
@@ -737,6 +675,72 @@ Page({
     });
   },
 
+  ///点击item
   onTapIem() {},
 
+  deleteDevice(e) {
+    wx.showModal({
+      title: '确定删除?',
+      success: function (res) {
+        if (res.confirm) {
+          const id = this.data.deviceList[e.currentTarget.dataset.index].deviceId;
+          let name = _this.data.deviceListIndex !== null ? this.data.deviceList[_this.data.deviceListIndex].name : null;
+          const deviceList = this.data.deviceList.filter((v, i) => {
+            return id !== v.deviceId
+          });
+          // 取消订阅
+          app.unsubscribe(`/AIrSMArT_${_this.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
+
+          wx.setStorage({
+            key: "devicelist",
+            data: JSON.stringify(deviceList),
+            success() {
+
+              _this.setData({
+                deviceList,
+                thisDeviceMac: null
+              });
+
+              // 当前没有设备
+              if (deviceList.length === 0) {
+                _this.setData({
+                  actionIndex: null,
+                  deviceListIndex: null,
+                });
+              }
+
+              if (_this.data.deviceListIndex === null) {
+                return
+              };
+              if (e.currentTarget.dataset.index === _this.data.deviceListIndex) {
+                let index_ = null;
+                deviceList.map((v, index) => {
+                  if (v.state === "online" && index_ === null) {
+                    index_ = index;
+                  }
+                });
+                if (index_ !== null) {
+                  _this.actionDevice(index_);
+                } else {
+                  _this.setData({
+                    actionIndex: null,
+                    deviceListIndex: null,
+                  });
+                };
+              } else {
+                deviceList.map((v, index) => {
+                  if (v.name === name) {
+                    _this.setData({
+                      deviceListIndex: index,
+                    });
+                  }
+                });
+              }
+            }
+          });
+        }
+      }
+    });
+  },
+
 })