Browse Source

feature:修改mqtt的休眠的指令问题

zeng.chen 7 months atrás
parent
commit
7814e84a42
1 changed files with 56 additions and 33 deletions
  1. 56 33
      pages/deviceWake/deviceWake.js

+ 56 - 33
pages/deviceWake/deviceWake.js

@@ -278,17 +278,21 @@ Page({
           toast_visible: true,
         });
       };
-      app.PubMsg({
-        type: "get_dev_info",
-        DstDeviceName: _this.data.deviceMac
-      });
-      // 循环查询
-      const Interval = setInterval(() => {
-        if (_this.data.updataDeviceInfo) {
-          clearInterval(Interval);
-          other.on_off_timestamp = _this.data.time;
+      // app.PubMsg({
+      //   type: "get_dev_info",
+      //   DstDeviceName: _this.data.deviceMac
+      // });
+      if (!other) {
+        wx.showToast({
+          title: '设备已断开连接',
+          icon:"none"
+        })
+        return
+      }
+      other.on_off_timestamp = _this.data.time;
           other = this.setOther(other, 1);
-          if (other.week_actives.filter((v) => v === 1).length > 0) {
+          let week_actives = other.week_actives ?? []
+          if (week_actives.filter((v) => v === 1).length > 0) {
             // other.week_actives = [0,1,1,1,1,1,0],
             other.weekly_repeat = "1";
           } else {
@@ -299,33 +303,52 @@ Page({
             DstDeviceName: _this.data.deviceMac,
             other
           });
+
+        // 不要循环发送,也不要改alarm_id_0.enable
+      // 循环查询
+      // const Interval = setInterval(() => {
+      //   if (_this.data.updataDeviceInfo) {
+      //     clearInterval(Interval);
+          // other.on_off_timestamp = _this.data.time;
+          // other = this.setOther(other, 1);
+          // if (other.week_actives.filter((v) => v === 1).length > 0) {
+          //   // other.week_actives = [0,1,1,1,1,1,0],
+          //   other.weekly_repeat = "1";
+          // } else {
+          //   other.weekly_repeat = "0";
+          // };
+          // app.PubMsg({
+          //   type: "alert_set",
+          //   DstDeviceName: _this.data.deviceMac,
+          //   other
+          // });
           // 需打开休眠
-          if (_this.data.alarm_id_0.enable === "0") {
+          // if (_this.data.alarm_id_0.enable === "0") {
 
-            const thisTime = Math.round(new Date() / 1000);
-            const alarm_id_0 = this.setOther(_this.data.alarm_id_0, 1);
-            alarm_id_0.on_off_timestamp = _this.data.alarm_id_0_time;
+          //   const thisTime = Math.round(new Date() / 1000);
+          //   const alarm_id_0 = this.setOther(_this.data.alarm_id_0, 1);
+          //   alarm_id_0.on_off_timestamp = _this.data.alarm_id_0_time;
 
-            // 有重复
-            if (alarm_id_0.week_actives.filter((v) => v === 1).length > 0) {
-              alarm_id_0.weekly_repeat = "1";
-            } else {
-              alarm_id_0.weekly_repeat = "0";
-            };;
-            // 如果跨天了
-            if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-              const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-              alarm_id_0.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
-            };
-            app.PubMsg({
-              type: "alert_set",
-              DstDeviceName: _this.data.deviceMac,
-              other: alarm_id_0
-            });
-          }
+          //   // 有重复
+          //   if (alarm_id_0.week_actives.filter((v) => v === 1).length > 0) {
+          //     alarm_id_0.weekly_repeat = "1";
+          //   } else {
+          //     alarm_id_0.weekly_repeat = "0";
+          //   };;
+          //   // 如果跨天了
+          //   if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
+          //     const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+          //     alarm_id_0.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+          //   };
+          //   app.PubMsg({
+          //     type: "alert_set",
+          //     DstDeviceName: _this.data.deviceMac,
+          //     other: alarm_id_0
+          //   });
+          // }
 
-        }
-      }, 500);
+      //   }
+      // }, 500);
     } else {
       other = this.setOther(other, 0);
       app.PubMsg({