Explorar el Código

提交优化代码

wangming07 hace 1 mes
padre
commit
77a95eba31
Se han modificado 2 ficheros con 23 adiciones y 21 borrados
  1. 22 21
      src/pagesA/deviceDetail/deviceDetail.vue
  2. 1 0
      src/utils/globalMqtt.js

+ 22 - 21
src/pagesA/deviceDetail/deviceDetail.vue

@@ -985,10 +985,22 @@ export default {
     },
     onShow() {
         this.showModle = true;
+    },
+    onLoad(options) {
+        const devItem = JSON.parse(options.devItem);
+        const { devId, clientId } = devItem;
+        this.getFrequency(clientId);
+        this.getdevInfo(devId);
+        this.getdevRoomInfo(devId);
+        this.autoPlayinterval = setTimeout(() => {
+            this.autoSwipe();
+        }, 3000);
+        this.getCurrentDate();
+
         this.clientId = uni.getStorageSync("clientIDetail");
         console.log(this.clientId, "clientIDetail");
         if (this.mqttData) {
-            this.mqttData.end(); // 或 close() 根据你使用的 MQTT 库
+            this.mqttData.end(true);
             this.mqttData = null;
             console.log("页面 MQTT 已关闭");
         }
@@ -1013,36 +1025,25 @@ export default {
             });
         }
     },
-    onLoad(options) {
-        const devItem = JSON.parse(options.devItem);
-        const { devId, clientId } = devItem;
-        this.getFrequency(clientId);
-        this.getdevInfo(devId);
-        this.getdevRoomInfo(devId);
-        this.autoPlayinterval = setTimeout(() => {
-            this.autoSwipe();
-        }, 3000);
-        this.getCurrentDate();
-    },
     onUnload() {
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
         this.showModle = false;
         if (this.mqttData) {
-            this.mqttData.end(); // 或 close() 根据你使用的 MQTT 库
+            this.mqttData.end(true);
             this.mqttData = null;
             console.log("页面 MQTT1 已关闭");
         }
     },
     onHide() {
-        this.inactivityTimer = null;
-        this.autoPlayinterval = null;
-        this.showModle = false;
-        if (this.mqttData) {
-            this.mqttData.end(); // 或 close() 根据你使用的 MQTT 库
-            this.mqttData = null;
-            console.log("页面 MQTT2 已关闭");
-        }
+        // this.inactivityTimer = null;
+        // this.autoPlayinterval = null;
+        // this.showModle = false;
+        // if (this.mqttData) {
+        //     this.mqttData.end(true);
+        //     this.mqttData = null;
+        //     console.log("页面 MQTT2 已关闭");
+        // }
     },
     beforeDestroy() {
         console.log("组件销毁时调用");

+ 1 - 0
src/utils/globalMqtt.js

@@ -140,6 +140,7 @@ export function createMqttData(clientIdProp) {
     //     mqttDataConnected = false;
     //     console.log("DATA MQTT 已关闭");
     // });
+
     return mqttClientData;
 }
 // export function createMqttData(clientIdProp) {