From ea54841d8a9bb3375cdf414ac7d677323a7b9e03 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Fri, 3 Nov 2023 13:21:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E8=B7=AF=E8=AE=A2=E9=98=85=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/lineApp.ts | 114 ++++++++++++++++++++------------------- src/stores/line-store.ts | 2 +- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 1eca009..2decdbf 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -87,7 +87,7 @@ export function destroyLineApp(): void { } } -export function initLineApp(lineId: number): IGraphicApp { +export function initLineApp(): IGraphicApp { if (lineApp) return lineApp; const lineAppDataLoader: IGraphicAppConfig['dataLoader'] = async () => { const lineStore = useLineStore(); @@ -186,6 +186,65 @@ export function initLineApp(lineId: number): IGraphicApp { token: getJwtToken() as string, }); + let msgNotify: null | ((props?: QNotifyUpdateOptions | undefined) => void) = + null; + lineApp.on('websocket-connect-state-change', (connected) => { + if (!connected && !msgNotify) { + msgNotify = Notify.create({ + type: 'negative', + timeout: 0, + position: 'top-right', + message: '通信链接已断开!', + }); + } else if (msgNotify && connected) { + msgNotify(); + msgNotify = null; + } + }); + + lineApp.reload().then(() => { + if (!lineApp) return; + const quickJumpMenu = new ContextMenu({ + name: '快捷跳转', + groups: [ + { + items: lineApp.queryStore + .queryByType(Station.Type) + .map((station) => ({ + name: station.datas.name ?? '', + handler: () => { + lineApp?.makeGraphicCenterShow(station); + }, + })), + }, + ], + }); + lineApp.registerMenu(quickJumpMenu); + lineApp.canvas.on('_rightclick', (e) => { + quickJumpMenu.open(e.global); + }); + + const axleCountings = lineApp.queryStore.queryByType( + AxleCounting.Type + ); + axleCountings.forEach((axleCounting) => { + axleCounting.visible = false; + }); + const trainWindows = lineApp.queryStore.queryByType( + TrainWindow.Type + ); + trainWindows.forEach((trainWindow) => { + trainWindow.visible = false; + }); + handleSubscribe(lineApp); + }); + + return lineApp; +} + +function handleSubscribe(lineApp: IGraphicApp) { + const lineStore = useLineStore(); + const lineId = lineStore.lineId; lineApp.subscribe({ destination: `/queue/line/${lineId}/device`, messageConverter: (message: Uint8Array) => { @@ -235,21 +294,6 @@ export function initLineApp(lineId: number): IGraphicApp { return states; }, }); - let msgNotify: null | ((props?: QNotifyUpdateOptions | undefined) => void) = - null; - lineApp.on('websocket-connect-state-change', (connected) => { - if (!connected && !msgNotify) { - msgNotify = Notify.create({ - type: 'negative', - timeout: 0, - position: 'top-right', - message: '通信链接已断开!', - }); - } else if (msgNotify && connected) { - msgNotify(); - msgNotify = null; - } - }); const lineNetStore = useLineNetStore(); lineApp.subscribe({ destination: '/queue/xian/ncc/alert', @@ -258,42 +302,4 @@ export function initLineApp(lineId: number): IGraphicApp { lineNetStore.setAlarmInfo(storage.messages as []); }, }); - - lineApp.reload().then(() => { - if (!lineApp) return; - const quickJumpMenu = new ContextMenu({ - name: '快捷跳转', - groups: [ - { - items: lineApp.queryStore - .queryByType(Station.Type) - .map((station) => ({ - name: station.datas.name ?? '', - handler: () => { - lineApp?.makeGraphicCenterShow(station); - }, - })), - }, - ], - }); - lineApp.registerMenu(quickJumpMenu); - lineApp.canvas.on('_rightclick', (e) => { - quickJumpMenu.open(e.global); - }); - - const axleCountings = lineApp.queryStore.queryByType( - AxleCounting.Type - ); - axleCountings.forEach((axleCounting) => { - axleCounting.visible = false; - }); - const trainWindows = lineApp.queryStore.queryByType( - TrainWindow.Type - ); - trainWindows.forEach((trainWindow) => { - trainWindow.visible = false; - }); - }); - - return lineApp; } diff --git a/src/stores/line-store.ts b/src/stores/line-store.ts index a58caa7..2572c55 100644 --- a/src/stores/line-store.ts +++ b/src/stores/line-store.ts @@ -39,7 +39,7 @@ export const useLineStore = defineStore('line', { }, initLineApp(lineId: number) { this.setLineId(lineId); - const app = initLineApp(lineId); + const app = initLineApp(); app.on('graphicselected', (graphics) => { this.selectedGraphics = markRaw(graphics); });