From 330f7cc8097759df1d8b0d1be71d0fd53ea05ae9 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 22 Oct 2024 11:30:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E8=B7=AF=E5=BE=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/AuthApi.ts | 1 + src/components/SysMenu.vue | 2 +- src/drawApp/lineApp.ts | 17 +++++++++++------ src/drawApp/lineNetApp.ts | 17 +++++++++++------ src/layouts/MainLayout.vue | 2 +- src/pages/AlarmInfoList.vue | 14 +++++++++++--- src/pages/RoleManage.vue | 9 +++++---- src/pages/UserLogin.vue | 2 +- src/router/routes.ts | 35 +++++++++++++++++++++++++++++------ 9 files changed, 71 insertions(+), 28 deletions(-) diff --git a/src/api/AuthApi.ts b/src/api/AuthApi.ts index c39fb6f..3180760 100644 --- a/src/api/AuthApi.ts +++ b/src/api/AuthApi.ts @@ -25,6 +25,7 @@ export interface RoleInfo { id: number; name: string; resList: number[]; + roleConfigStr: string; } /** diff --git a/src/components/SysMenu.vue b/src/components/SysMenu.vue index 9e569ae..0bf85b9 100644 --- a/src/components/SysMenu.vue +++ b/src/components/SysMenu.vue @@ -47,7 +47,7 @@ const userStore = useUserStore(); const list = reactive([ { show: true, - path: getMonitorPath(userStore.roles), + path: getMonitorPath(userStore.roles).monitorPath, label: '监控', icon: 'computer', }, diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 94d8ab5..79ac160 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -73,6 +73,8 @@ import { import { Notify, QNotifyUpdateOptions } from 'quasar'; import { useLineNetStore } from 'src/stores/line-net-store'; import { alert } from 'src/protos/alertInfo'; +import { useUserStore } from 'src/stores/user-store'; +import { getMonitorPath } from 'src/router/routes'; let lineApp: IGraphicApp | null = null; @@ -304,11 +306,14 @@ function handleSubscribe(lineApp: IGraphicApp) { }, }); const lineNetStore = useLineNetStore(); - lineApp.subscribe({ - destination: '/queue/xian/ncc/alert', - messageHandle: (message: Uint8Array) => { - const storage = alert.NccAlertInfoMessage.deserialize(message); - lineNetStore.setAlarmInfo(storage.messages as []); - }, + const userStore = useUserStore(); + getMonitorPath(userStore.roles).destinations.forEach((destination) => { + lineApp.subscribe({ + destination, + messageHandle: (message: Uint8Array) => { + const storage = alert.NccAlertInfoMessage.deserialize(message); + lineNetStore.setAlarmInfo(storage.messages as []); + }, + }); }); } diff --git a/src/drawApp/lineNetApp.ts b/src/drawApp/lineNetApp.ts index 1f00a57..5f39c40 100644 --- a/src/drawApp/lineNetApp.ts +++ b/src/drawApp/lineNetApp.ts @@ -35,6 +35,8 @@ import { getWebsocketUrl } from 'src/configs/UrlManage'; import { getJwtToken } from 'src/configs/TokenManage'; import { alert } from 'src/protos/alertInfo'; import { Notify } from 'quasar'; +import { useUserStore } from 'src/stores/user-store'; +import { getMonitorPath } from 'src/router/routes'; let lineNetApp: IGraphicApp | null = null; @@ -161,11 +163,14 @@ function handleSubscribe(lineNetApp: IGraphicApp) { return states; }, }); - lineNetApp.subscribe({ - destination: '/queue/xian/ncc/alert', - messageHandle: (message: Uint8Array) => { - const storage = alert.NccAlertInfoMessage.deserialize(message); - lineNetStore.setAlarmInfo(storage.messages as []); - }, + const userStore = useUserStore(); + getMonitorPath(userStore.roles).destinations.forEach((destination) => { + lineNetApp.subscribe({ + destination, + messageHandle: (message: Uint8Array) => { + const storage = alert.NccAlertInfoMessage.deserialize(message); + lineNetStore.setAlarmInfo(storage.messages as []); + }, + }); }); } diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index ae392dc..a8013cc 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -161,7 +161,7 @@ const showBackMonitor = computed(() => { const userStore = useUserStore(); const isShow = route.path.includes('line/monitor/') && - getMonitorPath(userStore.roles) == '/monitor'; + getMonitorPath(userStore.roles).lineType == 'NCC'; return isShow; }); diff --git a/src/pages/AlarmInfoList.vue b/src/pages/AlarmInfoList.vue index c134790..d5add68 100644 --- a/src/pages/AlarmInfoList.vue +++ b/src/pages/AlarmInfoList.vue @@ -237,6 +237,8 @@ import { webSocketConnect, closeWebSocketConnect, } from 'src/components/webSocketConnect'; +import { getMonitorPath } from 'src/router/routes'; +import { useUserStore } from 'src/stores/user-store'; const $q = useQuasar(); const lineNetStore = useLineNetStore(); @@ -246,6 +248,7 @@ const props = withDefaults( }>(), { sizeHeight: 500 } ); +const userStore = useUserStore(); const tableHeight = computed(() => { return props.sizeHeight - 32; @@ -369,10 +372,13 @@ async function onRequest(props: any) { onMounted(() => { queryLineInfo(); + destinations = getMonitorPath(userStore.roles).destinations; setTimeout(() => { tableRef.value.requestServerInteraction(); lineNetStore.alarmInfoListTable = tableRef.value; - socket = webSocketConnect(destination, handler); + destinations.forEach((destination) => { + socket = webSocketConnect(destination, handler); + }); }); }); @@ -552,14 +558,16 @@ function openAlarmDialog(row: any) { } let socket: StompMessagingClient | null = null; -const destination = '/queue/xian/ncc/alert'; +let destinations: string[] = []; function handler(message: Uint8Array) { const storage = alert.NccAlertInfoMessage.deserialize(message); lineNetStore.setAlarmInfo(storage.messages as []); } onUnmounted(() => { - closeWebSocketConnect(socket, destination); + destinations.forEach((destination) => { + closeWebSocketConnect(socket, destination); + }); }); //报警统计 diff --git a/src/pages/RoleManage.vue b/src/pages/RoleManage.vue index 46456c1..59f8651 100644 --- a/src/pages/RoleManage.vue +++ b/src/pages/RoleManage.vue @@ -159,18 +159,19 @@ async function onRequest(props: any) { interface RoleItemInfo extends Omit { id: string; editPaths: { id: number }[]; - config: string; + roleConfigStr: string; } const roleInfo = reactive({ id: '', editPaths: [], name: '', resList: [], - config: '', + roleConfigStr: '', }); function edieRoleData(row: RoleInfo) { roleInfo.id = row.id + ''; roleInfo.name = row.name; + roleInfo.roleConfigStr=row.roleConfigStr editFormShow.value = true; } @@ -182,7 +183,7 @@ function roleConfigFn() { if (res) { operateDisabled.value = true; try { - await roleConfig(+roleInfo.id, roleInfo.config); + await roleConfig(+roleInfo.id, roleInfo.roleConfigStr); editFormShow.value = false; successNotify('修改成功'); } catch (err) { @@ -201,7 +202,7 @@ function roleConfigFn() { function onReset() { roleInfo.id = ''; roleInfo.name = ''; - roleInfo.config = ''; + roleInfo.roleConfigStr = ''; myForm.value?.resetValidation(); } diff --git a/src/pages/UserLogin.vue b/src/pages/UserLogin.vue index dc27df0..ea9a1df 100644 --- a/src/pages/UserLogin.vue +++ b/src/pages/UserLogin.vue @@ -86,7 +86,7 @@ async function doLogin() { () => handleRefreshToken(), userInfo.remainingSecond * 1000 - 10000 ); - router.replace(getMonitorPath(userInfo.roles)); + router.replace(getMonitorPath(userInfo.roles).monitorPath); } catch (err) { visible.value = false; const apiErr = err as ApiError; diff --git a/src/router/routes.ts b/src/router/routes.ts index e25c36f..0568314 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -170,20 +170,43 @@ const routes: RouteRecordRaw[] = [ export default routes; export function getMonitorPath(roles: role[]) { - let monitorPath = ''; - const allOCCLineIds: number[] = []; + const configInfo: { + monitorPath: string; + lineIds: number[]; + lineType: string; + destinations: string[]; + } = { + monitorPath: '', + lineIds: [], + lineType: '', + destinations: [], + }; + let allOCCLineIds: number[] = []; for (let i = 0; i < roles.length; i++) { const roleConfig = roles[i].roleConfig; for (let j = 0; j < roleConfig.length; j++) { if (roleConfig[j].lineType == 'NCC') { - monitorPath = '/monitor'; - return monitorPath; + configInfo.monitorPath = '/monitor'; + configInfo.lineIds = roleConfig.map((config) => { + configInfo.destinations.push( + `/queue/xian/NCC/${config.lineId}/alert` + ); + return config.lineId; + }); + configInfo.lineType = 'NCC'; + return configInfo; } else { allOCCLineIds.push(roleConfig[j].lineId); } } } + allOCCLineIds = [...new Set(allOCCLineIds)]; const minId = Math.min(...allOCCLineIds); - monitorPath = `/line/monitor/${minId}`; - return monitorPath; + configInfo.monitorPath = `/line/monitor/${minId}`; + configInfo.lineIds = allOCCLineIds; + configInfo.lineType = 'OCC'; + allOCCLineIds.forEach((lineId) => { + configInfo.destinations.push(`/queue/xian/OCC/${lineId}/alert`); + }); + return configInfo; }