chenyao
2025-03-13 bdc6d8733ae6eeb3a9762e77dbabe21441336474
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 = {