Commit c063a4790a398a61512dd1cb75b22bbe44b9f768
1 parent
9160be19
fix(src/store/): 修复ws绑定组件,然后删除后,ws还继续发送信息问题
Showing
2 changed files
with
26 additions
and
3 deletions
@@ -5,7 +5,7 @@ import { SocketReceiveMessageType } from "@/store/external/modules/socketStore.d | @@ -5,7 +5,7 @@ import { SocketReceiveMessageType } from "@/store/external/modules/socketStore.d | ||
5 | import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; | 5 | import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; |
6 | import { getJwtToken, getShareJwtToken } from "@/utils/external/auth"; | 6 | import { getJwtToken, getShareJwtToken } from "@/utils/external/auth"; |
7 | import { useWebSocket, WebSocketResult } from "@vueuse/core"; | 7 | import { useWebSocket, WebSocketResult } from "@vueuse/core"; |
8 | -import { onMounted, unref } from "vue"; | 8 | +import {onMounted, ref, unref} from "vue"; |
9 | import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d"; | 9 | import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d"; |
10 | import { isShareMode } from "@/views/share/hook"; | 10 | import { isShareMode } from "@/views/share/hook"; |
11 | 11 | ||
@@ -17,6 +17,8 @@ interface SocketConnectionPoolType { | @@ -17,6 +17,8 @@ interface SocketConnectionPoolType { | ||
17 | 17 | ||
18 | const socketConnectionPool: SocketConnectionPoolType[] = [] | 18 | const socketConnectionPool: SocketConnectionPoolType[] = [] |
19 | 19 | ||
20 | +const saveHistoryWsMessage=ref() | ||
21 | + | ||
20 | const parse = (value: string) => { | 22 | const parse = (value: string) => { |
21 | try { | 23 | try { |
22 | return JSON.parse(value) | 24 | return JSON.parse(value) |
@@ -88,13 +90,25 @@ export const useChartDataSocket = () => { | @@ -88,13 +90,25 @@ export const useChartDataSocket = () => { | ||
88 | const { subscribeMessage } = message | 90 | const { subscribeMessage } = message |
89 | const { send, data } = getSocketInstance(request) | 91 | const { send, data } = getSocketInstance(request) |
90 | send(JSON.stringify(subscribeMessage)) | 92 | send(JSON.stringify(subscribeMessage)) |
93 | + saveHistoryWsMessage.value=subscribeMessage | ||
91 | return socketStore.getComponentValueByKeys(targetComponent, parse(unref(data))) | 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 | return { | 108 | return { |
96 | initial, | 109 | initial, |
97 | - sendMessage | 110 | + sendMessage, |
111 | + disconnectWs | ||
98 | } | 112 | } |
99 | } | 113 | } |
100 | 114 |
@@ -31,6 +31,7 @@ import { | @@ -31,6 +31,7 @@ import { | ||
31 | 31 | ||
32 | // THINGS_KIT 引入store解决报错 Uncaught Error: [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia? | 32 | // THINGS_KIT 引入store解决报错 Uncaught Error: [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia? |
33 | import { pinia } from '@/store' | 33 | import { pinia } from '@/store' |
34 | +import {useChartDataSocket} from "@/hooks/external/useChartDataSocket"; | ||
34 | const chartHistoryStore = useChartHistoryStore(pinia) | 35 | const chartHistoryStore = useChartHistoryStore(pinia) |
35 | const settingStore = useSettingStore(pinia) | 36 | const settingStore = useSettingStore(pinia) |
36 | 37 | ||
@@ -316,6 +317,14 @@ export const useChartEditStore = defineStore({ | @@ -316,6 +317,14 @@ export const useChartEditStore = defineStore({ | ||
316 | const index = this.fetchTargetIndex(ids) | 317 | const index = this.fetchTargetIndex(ids) |
317 | if (index !== -1) { | 318 | if (index !== -1) { |
318 | history.push(this.getComponentList[index]) | 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 | this.componentList.splice(index, 1) | 328 | this.componentList.splice(index, 1) |
320 | } | 329 | } |
321 | }) | 330 | }) |
@@ -512,7 +521,7 @@ export const useChartEditStore = defineStore({ | @@ -512,7 +521,7 @@ export const useChartEditStore = defineStore({ | ||
512 | item.id = getUUID() | 521 | item.id = getUUID() |
513 | }) | 522 | }) |
514 | } | 523 | } |
515 | - | 524 | + |
516 | return e | 525 | return e |
517 | } | 526 | } |
518 | const isCut = recordCharts.type === HistoryActionTypeEnum.CUT | 527 | const isCut = recordCharts.type === HistoryActionTypeEnum.CUT |