Browse Source

提交首页

wangming 2 months ago
parent
commit
d93f79c666

+ 9 - 0
src/components/component/alarModel.vue

@@ -102,6 +102,7 @@ export default {
             apiTypeIndex: 0,
             currentIndex: 0,
             voipFlag: "",
+            mqttClientFlag: false,
         };
     },
     computed: {},
@@ -426,6 +427,10 @@ export default {
             //     }
             // }
 
+            if (this.mqttClientFlag) {
+                return;
+                console.log("主题已订阅");
+            }
             const THRESHOLD = 2;
             const params = {
                 keepalive: 60,
@@ -447,6 +452,7 @@ export default {
                         });
                     },
                 },
+                reconnectPeriod: 0,
                 rejectUnauthorized: false, // 仅开发环境使用,生产环境应设为true或移除
             };
             let client = "";
@@ -470,6 +476,7 @@ export default {
             this.mqttClientTwo = client;
             client.on("connect", () => {
                 console.log("MQTT连接成功");
+                this.mqttClientFlag = true;
                 let userId = uni.getStorageSync("userId");
                 client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
                     if (err) {
@@ -485,6 +492,7 @@ export default {
                 console.log("MQTT不在连接");
             });
             client.on("error", (err) => {
+                this.mqttClientFlag = false;
                 setTimeout(() => {
                     this.connectMQTTwo();
                 }, 1000);
@@ -556,6 +564,7 @@ export default {
                 });
         },
         closemqtt() {
+            this.mqttClientFlag = false;
             if (this.mqttClientTwo) {
                 this.mqttClientTwo.end();
                 this.mqttClientTwo = null;

+ 3 - 3
src/components/component/tenMinutes.vue

@@ -116,7 +116,6 @@ export default {
         authorizeIot() {
             this.hanledList("Voice");
             this.sn = this.clientId;
-            this.alarmModel = false;
             // const { name, sn, voipDevices } = this;
             const name = this.name;
             const sn = this.clientId;
@@ -204,7 +203,7 @@ export default {
         },
         async authorizeIot() {
             this.sn = this.clientId;
-            // this.alarmModel = false;
+            this.alarmModel = false;
             const name = this.name;
             const sn = this.sn;
             const voipDevices = this.voipDevices;
@@ -269,7 +268,7 @@ export default {
                 icon: "loading",
                 duration: 2000, //持续的时间
             });
-            // this.alarmModel = false;
+            this.alarmModel = false;
             this._caller = new AsyncValue();
             let options = {
                 sn: this.sn,
@@ -380,6 +379,7 @@ export default {
             wx.hideLoading();
         },
         async call(e) {
+            this.alarmModel = false;
             console.log(`call`, "走到了call方法");
             const { sn, idx, type: roomtype } = e;
             console.log(e, this.contactList, 888870);

+ 5 - 0
src/pages/home/home.vue

@@ -177,6 +177,11 @@ export default {
         gotoDevice(url) {
             if (uni.getStorageSync("userId")) {
                 if (this.devDevice.length == 1) {
+                    uni.setStorageSync("devIdDetail", this.devDevice[0].devId);
+                    uni.setStorageSync(
+                        "clientIDetail",
+                        this.devDevice[0].clientId
+                    );
                     uni.navigateTo({
                         url:
                             "/pagesA/deviceDetail/deviceDetail?devItem=" +

+ 10 - 8
src/pagesA/deviceDetail/deviceDetail.vue

@@ -411,9 +411,14 @@ export default {
                         },
                     },
                     rejectUnauthorized: false,
+                    reconnectPeriod: 0,
                 },
             };
 
+            if (this.isConnecting) {
+                console.log("mqtt已经链接,请勿重复链接");
+                return;
+            }
             // 清理之前的连接和定时器
             this.cleanupMQTT();
 
@@ -459,6 +464,7 @@ export default {
 
         // 处理连接成功
         handleConnectSuccess(clientId) {
+            this.isConnecting = true;
             this.mqttClient.subscribe(`/dev/${clientId}/dsp_data`, (err) => {
                 if (err) {
                     console.error("订阅失败", err);
@@ -470,6 +476,7 @@ export default {
 
         // 处理MQTT消息
         handleMessage(topic, message, clientId, CONFIG) {
+            this.isConnecting = false;
             // 清除不活动定时器
             clearTimeout(this.inactivityTimer);
             this.inactivityTimer = setTimeout(() => {
@@ -587,6 +594,7 @@ export default {
 
         // 处理重连
         handleReconnect(clientId, devId, delay) {
+            this.isConnecting = false;
             // 使用防抖避免频繁重连
             if (this.reconnectTimer) {
                 clearTimeout(this.reconnectTimer);
@@ -898,19 +906,13 @@ export default {
         this.isInitAlarm = false;
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
-        if (this.mqttClient) {
-            this.cleanupMQTT();
-            this.mqttClient.end();
-        }
+        this.cleanupMQTT();
     },
     onHide() {
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
         this.isInitAlarm = false;
-        if (this.mqttClient) {
-            this.cleanupMQTT();
-            this.mqttClient.end();
-        }
+        this.cleanupMQTT();
     },
 };
 </script>