线路订阅调整

This commit is contained in:
dong 2023-11-03 13:21:17 +08:00
parent ea363b44cd
commit ea54841d8a
2 changed files with 61 additions and 55 deletions

View File

@ -87,7 +87,7 @@ export function destroyLineApp(): void {
} }
} }
export function initLineApp(lineId: number): IGraphicApp { export function initLineApp(): IGraphicApp {
if (lineApp) return lineApp; if (lineApp) return lineApp;
const lineAppDataLoader: IGraphicAppConfig['dataLoader'] = async () => { const lineAppDataLoader: IGraphicAppConfig['dataLoader'] = async () => {
const lineStore = useLineStore(); const lineStore = useLineStore();
@ -186,6 +186,65 @@ export function initLineApp(lineId: number): IGraphicApp {
token: getJwtToken() as string, 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>(Station.Type)
.map<MenuItemOptions>((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>(
AxleCounting.Type
);
axleCountings.forEach((axleCounting) => {
axleCounting.visible = false;
});
const trainWindows = lineApp.queryStore.queryByType<TrainWindow>(
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({ lineApp.subscribe({
destination: `/queue/line/${lineId}/device`, destination: `/queue/line/${lineId}/device`,
messageConverter: (message: Uint8Array) => { messageConverter: (message: Uint8Array) => {
@ -235,21 +294,6 @@ export function initLineApp(lineId: number): IGraphicApp {
return states; 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(); const lineNetStore = useLineNetStore();
lineApp.subscribe({ lineApp.subscribe({
destination: '/queue/xian/ncc/alert', destination: '/queue/xian/ncc/alert',
@ -258,42 +302,4 @@ export function initLineApp(lineId: number): IGraphicApp {
lineNetStore.setAlarmInfo(storage.messages as []); lineNetStore.setAlarmInfo(storage.messages as []);
}, },
}); });
lineApp.reload().then(() => {
if (!lineApp) return;
const quickJumpMenu = new ContextMenu({
name: '快捷跳转',
groups: [
{
items: lineApp.queryStore
.queryByType<Station>(Station.Type)
.map<MenuItemOptions>((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>(
AxleCounting.Type
);
axleCountings.forEach((axleCounting) => {
axleCounting.visible = false;
});
const trainWindows = lineApp.queryStore.queryByType<TrainWindow>(
TrainWindow.Type
);
trainWindows.forEach((trainWindow) => {
trainWindow.visible = false;
});
});
return lineApp;
} }

View File

@ -39,7 +39,7 @@ export const useLineStore = defineStore('line', {
}, },
initLineApp(lineId: number) { initLineApp(lineId: number) {
this.setLineId(lineId); this.setLineId(lineId);
const app = initLineApp(lineId); const app = initLineApp();
app.on('graphicselected', (graphics) => { app.on('graphicselected', (graphics) => {
this.selectedGraphics = markRaw(graphics); this.selectedGraphics = markRaw(graphics);
}); });