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; },