Commit c063a4790a398a61512dd1cb75b22bbe44b9f768

Authored by fengwotao
1 parent 9160be19

fix(src/store/): 修复ws绑定组件,然后删除后,ws还继续发送信息问题

... ... @@ -5,7 +5,7 @@ import { SocketReceiveMessageType } from "@/store/external/modules/socketStore.d
5 5 import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore";
6 6 import { getJwtToken, getShareJwtToken } from "@/utils/external/auth";
7 7 import { useWebSocket, WebSocketResult } from "@vueuse/core";
8   -import { onMounted, unref } from "vue";
  8 +import {onMounted, ref, unref} from "vue";
9 9 import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d";
10 10 import { isShareMode } from "@/views/share/hook";
11 11
... ... @@ -17,6 +17,8 @@ interface SocketConnectionPoolType {
17 17
18 18 const socketConnectionPool: SocketConnectionPoolType[] = []
19 19
  20 +const saveHistoryWsMessage=ref()
  21 +
20 22 const parse = (value: string) => {
21 23 try {
22 24 return JSON.parse(value)
... ... @@ -88,13 +90,25 @@ export const useChartDataSocket = () => {
88 90 const { subscribeMessage } = message
89 91 const { send, data } = getSocketInstance(request)
90 92 send(JSON.stringify(subscribeMessage))
  93 + saveHistoryWsMessage.value=subscribeMessage
91 94 return socketStore.getComponentValueByKeys(targetComponent, parse(unref(data)))
92 95 }
93 96
  97 + //删除组件 发送断开消息
  98 + const disconnectWs=(targetComponent:CreateComponentType)=>{
  99 + const { request } = unref(targetComponent)
  100 + const message = socketStore.subscribe(unref(targetComponent))
  101 + if (!message) return
  102 + if((request.requestContentType as RequestContentTypeEnum) !== RequestContentTypeEnum.WEB_SOCKET)return
  103 + const { send } = getSocketInstance(request)
  104 + saveHistoryWsMessage.value.tsSubCmds[0].unsubscribe=true
  105 + send(JSON.stringify(saveHistoryWsMessage.value))
  106 + }
94 107
95 108 return {
96 109 initial,
97   - sendMessage
  110 + sendMessage,
  111 + disconnectWs
98 112 }
99 113 }
100 114
... ...
... ... @@ -31,6 +31,7 @@ import {
31 31
32 32 // THINGS_KIT 引入store解决报错 Uncaught Error: [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia?
33 33 import { pinia } from '@/store'
  34 +import {useChartDataSocket} from "@/hooks/external/useChartDataSocket";
34 35 const chartHistoryStore = useChartHistoryStore(pinia)
35 36 const settingStore = useSettingStore(pinia)
36 37
... ... @@ -316,6 +317,14 @@ export const useChartEditStore = defineStore({
316 317 const index = this.fetchTargetIndex(ids)
317 318 if (index !== -1) {
318 319 history.push(this.getComponentList[index])
  320 + /**
  321 + * THINGS_KIT 这里升级版本有冲突
  322 + * 修改ws绑定组件,然后删除这个组件,ws还在继续发送消息问题
  323 + * 修改代码在//之间,其余源码未做修改
  324 + */
  325 + const {disconnectWs}=useChartDataSocket()
  326 + disconnectWs(this.getComponentList[index])
  327 + //
319 328 this.componentList.splice(index, 1)
320 329 }
321 330 })
... ... @@ -512,7 +521,7 @@ export const useChartEditStore = defineStore({
512 521 item.id = getUUID()
513 522 })
514 523 }
515   -
  524 +
516 525 return e
517 526 }
518 527 const isCut = recordCharts.type === HistoryActionTypeEnum.CUT
... ...