diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 308d714..003584f 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,14 @@ 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`); + } +} function handleSubscribe(lineApp: IGraphicApp) { const lineStore = useLineStore(); const lineId = lineStore.lineId; diff --git a/src/drawApp/lineNetApp.ts b/src/drawApp/lineNetApp.ts index e1fe7de..b0387e0 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,10 @@ export async function loadLineNetDatas(): Promise { } } -function handleSubscribe(lineNetApp: IGraphicApp) { +export function cancelSubscribe(lineApp: IGraphicApp) { + lineApp.unsubscribe('/queue/lineNet'); +} +export function handleSubscribe(lineNetApp: IGraphicApp) { const lineNetStore = useLineNetStore(); lineNetApp.enableWsMassaging({ wsUrl: `${getWebsocketUrl()}`, 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; },