From bdc6d8733ae6eeb3a9762e77dbabe21441336474 Mon Sep 17 00:00:00 2001
From: chenyao <1219716595@qq.com>
Date: Thu, 13 Mar 2025 17:20:36 +0800
Subject: [PATCH] 更新分享

---
 src/utils/mqtt/index.ts |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/utils/mqtt/index.ts b/src/utils/mqtt/index.ts
index fa25eaa..71e5e2b 100644
--- a/src/utils/mqtt/index.ts
+++ b/src/utils/mqtt/index.ts
@@ -81,25 +81,22 @@
 
   // 心跳
   const heartBeatSeq = ref(0)
-  const state = reactive({
-    heartState: new Map<string, {
-      pingInterval: any;
-    }>(),
-  })
+  const state = reactive({heartState: new Map()})
 
   // 监听云控控制权
   watch(() => deviceTopicInfo, (val, oldVal) => {
     if (val.subTopic !== '') {
-      // 1.订阅topic
       subscribeMqtt(deviceTopicInfo.subTopic)
-      // 2.发心跳
       publishDrcPing(deviceTopicInfo.sn)
     } else {
-      clearInterval(state.heartState.get(deviceTopicInfo.sn)?.pingInterval)
+      const heartState = state.heartState.get(deviceTopicInfo.sn)
+      if (heartState && heartState.pingInterval) {
+        clearInterval(heartState.pingInterval)
+      }
       state.heartState.delete(deviceTopicInfo.sn)
       heartBeatSeq.value = 0
     }
-  }, { immediate: true, deep: true })
+}, { immediate: true, deep: true })
 
   function publishDrcPing (sn: string) {
     const body = {

--
Gitblit v1.9.3