From 158aed62e670f899eb1fac7af7fa4c180a0f5ac7 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 12 Nov 2024 09:49:53 +0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 33292ca9b85e40868dc18ca44ade04e5c464f285 Author: joylink_fanyuhong <18706759286@163.com> Date: Tue Nov 12 09:17:32 2024 +0800 订阅处理 commit cdcad825f7c0d26880080e0705f94722ddc02bd4 Author: joylink_fanyuhong <18706759286@163.com> Date: Tue Nov 12 09:13:54 2024 +0800 取消订阅调整 commit 44f7389132fcaab0029573d9c7b2ca164a2a9cb0 Merge: 425d8e9 a2ae992 Author: joylink_fanyuhong <18706759286@163.com> Date: Mon Nov 11 18:18:43 2024 +0800 Merge remote-tracking branch 'origin/develop' into develop commit 425d8e986b5e77c0ed206e3ba0973d8e1add74b3 Author: joylink_fanyuhong <18706759286@163.com> Date: Mon Nov 11 18:16:10 2024 +0800 处理订阅 commit a2ae99209f79e5d2884220a26e81ef621e329400 Author: joylink_zhaoerwei Date: Mon Nov 11 17:48:52 2024 +0800 订阅调整 --- src/drawApp/lineApp.ts | 20 ++++++++++++++++++-- src/drawApp/lineNetApp.ts | 18 +++++++++++++++--- src/pages/LineMonitorPage.vue | 8 ++++---- src/pages/MonitorPage.vue | 8 ++++---- src/stores/line-net-store.ts | 5 +++++ src/stores/line-store.ts | 11 ++++++++++- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 308d714..034a238 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -95,7 +95,10 @@ export function destroyLineApp(): void { export function initLineApp(lineId: number): IGraphicApp { lineApp = lineAppMap.get(lineId) || null; - if (lineApp) return lineApp; + if (lineApp) { + handleSubscribe(lineApp); + return lineApp; + } lineApp = newGraphicApp({ interactiveGraphicTypeIncludes: [ Signal.Type, @@ -258,6 +261,18 @@ export async function loadLineDatas(): Promise { } } +export function cancelSubscribe(lineApp: IGraphicApp) { + const lineStore = useLineStore(); + const lineId = lineStore.lineId; + if (lineId) { + lineApp.unsubscribe(`/queue/line/${lineId}/device`); + lineApp.unsubscribe(`/queue/line/${lineId}/train`); + monitorDestinations.forEach((destination) => { + lineApp.unsubscribe(destination); + }); + } +} +let monitorDestinations: string[] = []; function handleSubscribe(lineApp: IGraphicApp) { const lineStore = useLineStore(); const lineId = lineStore.lineId; @@ -312,7 +327,8 @@ function handleSubscribe(lineApp: IGraphicApp) { }); const lineNetStore = useLineNetStore(); const userStore = useUserStore(); - getMonitorPath(userStore.roles).destinations.forEach((destination) => { + monitorDestinations = getMonitorPath(userStore.roles).destinations; + monitorDestinations.forEach((destination) => { lineApp.subscribe({ destination, messageHandle: (message: Uint8Array) => { diff --git a/src/drawApp/lineNetApp.ts b/src/drawApp/lineNetApp.ts index e1fe7de..ab23b88 100644 --- a/src/drawApp/lineNetApp.ts +++ b/src/drawApp/lineNetApp.ts @@ -52,7 +52,10 @@ export function destroyLineNetApp(): void { } export function initLineNetApp(): IGraphicApp { - if (lineNetApp) return lineNetApp; + if (lineNetApp) { + handleSubscribe(lineNetApp); + return lineNetApp; + } lineNetApp = newGraphicApp({ interactiveGraphicTypeIncludes: [ RunLine.Type, @@ -146,7 +149,15 @@ export async function loadLineNetDatas(): Promise { } } -function handleSubscribe(lineNetApp: IGraphicApp) { +export function cancelSubscribe(lineNetApp: IGraphicApp) { + lineNetApp.unsubscribe('/queue/lineNet'); + monitorDestinations.forEach((destination) => { + lineNetApp.unsubscribe(destination); + }); +} + +let monitorDestinations: string[] = []; +export function handleSubscribe(lineNetApp: IGraphicApp) { const lineNetStore = useLineNetStore(); lineNetApp.enableWsMassaging({ wsUrl: `${getWebsocketUrl()}`, @@ -165,7 +176,8 @@ function handleSubscribe(lineNetApp: IGraphicApp) { }, }); const userStore = useUserStore(); - getMonitorPath(userStore.roles).destinations.forEach((destination) => { + monitorDestinations = getMonitorPath(userStore.roles).destinations; + monitorDestinations.forEach((destination) => { lineNetApp.subscribe({ destination, messageHandle: (message: Uint8Array) => { diff --git a/src/pages/LineMonitorPage.vue b/src/pages/LineMonitorPage.vue index 3c2bf0e..117cc43 100644 --- a/src/pages/LineMonitorPage.vue +++ b/src/pages/LineMonitorPage.vue @@ -7,7 +7,7 @@ diff --git a/src/pages/MonitorPage.vue b/src/pages/MonitorPage.vue index 579d4ba..71af585 100644 --- a/src/pages/MonitorPage.vue +++ b/src/pages/MonitorPage.vue @@ -7,7 +7,7 @@ diff --git a/src/stores/line-net-store.ts b/src/stores/line-net-store.ts index 5987389..c805161 100644 --- a/src/stores/line-net-store.ts +++ b/src/stores/line-net-store.ts @@ -4,6 +4,7 @@ import { initLineNetApp, getLineNetApp, destroyLineNetApp, + cancelSubscribe, } from 'src/drawApp/lineNetApp'; import { markRaw } from 'vue'; import { QTable } from 'quasar'; @@ -72,6 +73,10 @@ export const useLineNetStore = defineStore('lineNet', { this.selectedGraphics = []; return app; }, + cancelSubscribe() { + const app = this.getLineNetApp(); + cancelSubscribe(app); + }, destroy() { this.selectedGraphics = null; destroyLineNetApp(); diff --git a/src/stores/line-store.ts b/src/stores/line-store.ts index d2f09b8..e757f2a 100644 --- a/src/stores/line-store.ts +++ b/src/stores/line-store.ts @@ -1,6 +1,11 @@ import { defineStore } from 'pinia'; import { IJlCanvas, JlGraphic, IGraphicApp } from 'jl-graphic'; -import { initLineApp, getLineApp, destroyLineApp } from 'src/drawApp/lineApp'; +import { + initLineApp, + getLineApp, + destroyLineApp, + cancelSubscribe, +} from 'src/drawApp/lineApp'; import { markRaw } from 'vue'; export const useLineStore = defineStore('line', { @@ -50,6 +55,10 @@ export const useLineStore = defineStore('line', { this.selectedGraphics = null; destroyLineApp(); }, + cancelSubscribe() { + const app = this.getLineApp(); + cancelSubscribe(app); + }, setLineId(id: number | null) { this.lineId = id; },