订阅路径修改

This commit is contained in:
joylink_zhaoerwei 2024-10-22 11:30:53 +08:00
parent 2a7cf2e186
commit 330f7cc809
9 changed files with 71 additions and 28 deletions

View File

@ -25,6 +25,7 @@ export interface RoleInfo {
id: number;
name: string;
resList: number[];
roleConfigStr: string;
}
/**

View File

@ -47,7 +47,7 @@ const userStore = useUserStore();
const list = reactive([
{
show: true,
path: getMonitorPath(userStore.roles),
path: getMonitorPath(userStore.roles).monitorPath,
label: '监控',
icon: 'computer',
},

View File

@ -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 []);
},
});
});
}

View File

@ -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 []);
},
});
});
}

View File

@ -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;
});

View File

@ -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);
});
});
//

View File

@ -159,18 +159,19 @@ async function onRequest(props: any) {
interface RoleItemInfo extends Omit<RoleInfo, 'id'> {
id: string;
editPaths: { id: number }[];
config: string;
roleConfigStr: string;
}
const roleInfo = reactive<RoleItemInfo>({
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();
}
</script>

View File

@ -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;

View File

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