refactor(vimp): 修复重复站点问题并重构告警逻辑
- 新增站点去重逻辑避免重复条目 - 更新告警面板构建函数的参数与内部实现 - 修正摄像机和告警区域的注释表述
This commit is contained in:
@@ -52,6 +52,7 @@ export const useDeviceCenterQuery = () => {
|
|||||||
// 例如有一个站点的编码是 010699 开头,但是其下的通道是 010199 和 010599 开头,
|
// 例如有一个站点的编码是 010699 开头,但是其下的通道是 010199 和 010599 开头,
|
||||||
// 而 010699 是一个不存在的站点编码,所以需要基于通道的编码来确定所有的站点。
|
// 而 010699 是一个不存在的站点编码,所以需要基于通道的编码来确定所有的站点。
|
||||||
const sites: VimpStation[] = [];
|
const sites: VimpStation[] = [];
|
||||||
|
const builtSitesSet = new Set<string>();
|
||||||
const siteCamerasMap = new Map<string, VimpChannel[]>();
|
const siteCamerasMap = new Map<string, VimpChannel[]>();
|
||||||
const siteAlarmsMap = new Map<string, VimpChannel[]>();
|
const siteAlarmsMap = new Map<string, VimpChannel[]>();
|
||||||
|
|
||||||
@@ -61,12 +62,13 @@ export const useDeviceCenterQuery = () => {
|
|||||||
|
|
||||||
channels.forEach((channel) => {
|
channels.forEach((channel) => {
|
||||||
const siteCode = channel.code.substring(0, 6);
|
const siteCode = channel.code.substring(0, 6);
|
||||||
if (siteCode in codeSites && !sites.some((site) => site.code === siteCode)) {
|
if (siteCode in codeSites && !builtSitesSet.has(siteCode)) {
|
||||||
sites.push({
|
sites.push({
|
||||||
code: siteCode,
|
code: siteCode,
|
||||||
name: codeSites[siteCode]?.name ?? '',
|
name: codeSites[siteCode]?.name ?? '',
|
||||||
online: siteFromApi.online,
|
online: siteFromApi.online,
|
||||||
});
|
});
|
||||||
|
builtSitesSet.add(siteCode);
|
||||||
}
|
}
|
||||||
const typeCode = Number(channel.code.substring(11, 14));
|
const typeCode = Number(channel.code.substring(11, 14));
|
||||||
if (typeCode >= 4 && typeCode <= 6) {
|
if (typeCode >= 4 && typeCode <= 6) {
|
||||||
@@ -94,16 +96,16 @@ export const useDeviceCenterQuery = () => {
|
|||||||
codeTrainAreas,
|
codeTrainAreas,
|
||||||
});
|
});
|
||||||
|
|
||||||
// alarmStore.buildLineTabPanes({
|
alarmStore.buildLineTabPanes({
|
||||||
// sitesFromApi,
|
sites,
|
||||||
// siteAlarmsMapFromApi,
|
siteAlarmsMap,
|
||||||
// codeLines,
|
codeLines,
|
||||||
// codeSites,
|
codeSites,
|
||||||
// codeStationAreas,
|
codeStationAreas,
|
||||||
// codeParkingAreas,
|
codeParkingAreas,
|
||||||
// codeOccAreas,
|
codeOccAreas,
|
||||||
// codeTrainAreas,
|
codeTrainAreas,
|
||||||
// });
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import { NIcon } from 'naive-ui';
|
|||||||
import { SirenIcon } from 'lucide-vue-next';
|
import { SirenIcon } from 'lucide-vue-next';
|
||||||
|
|
||||||
interface BuildLineTabPanesParams {
|
interface BuildLineTabPanesParams {
|
||||||
sitesFromApi: VimpStation[] | null;
|
sites: VimpStation[];
|
||||||
siteAlarmsMapFromApi: Record<string, VimpChannel[]>;
|
siteAlarmsMap: Map<string, VimpChannel[]>;
|
||||||
codeLines: CodeLines;
|
codeLines: CodeLines;
|
||||||
codeSites: CodeSites;
|
codeSites: CodeSites;
|
||||||
codeStationAreas: CodeArea[];
|
codeStationAreas: CodeArea[];
|
||||||
@@ -20,26 +20,24 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
const lineTabPanes = ref<AlarmLineTabPane[]>([]);
|
const lineTabPanes = ref<AlarmLineTabPane[]>([]);
|
||||||
|
|
||||||
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
||||||
const { sitesFromApi, siteAlarmsMapFromApi, codeLines, codeSites, codeStationAreas, codeParkingAreas, codeOccAreas, codeTrainAreas } = params;
|
const { sites, siteAlarmsMap, codeLines, codeSites, codeStationAreas, codeParkingAreas, codeOccAreas, codeTrainAreas } = params;
|
||||||
if (!sitesFromApi) {
|
|
||||||
lineTabPanes.value = [];
|
// 线路TabPane
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 构造线路TabPane
|
|
||||||
const _lineTabPanes: AlarmLineTabPane[] = [];
|
const _lineTabPanes: AlarmLineTabPane[] = [];
|
||||||
const lineCode = sitesFromApi.at(0)?.code.substring(0, 3) ?? '';
|
|
||||||
const lineName = codeLines[lineCode]?.name ?? '';
|
|
||||||
if (!_lineTabPanes.some((lineNode) => lineNode.lineCode === lineCode)) {
|
|
||||||
_lineTabPanes.push({
|
|
||||||
lineCode,
|
|
||||||
lineName,
|
|
||||||
alarmTree: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 遍历所有站点
|
// 遍历所有站点
|
||||||
for (const site of sitesFromApi) {
|
for (const site of sites) {
|
||||||
const siteCode = site.code.substring(0, 6);
|
const lineCode = site.code.substring(0, 3);
|
||||||
|
const lineName = codeLines[lineCode]?.name ?? '';
|
||||||
|
if (!_lineTabPanes.some((lineNode) => lineNode.lineCode === lineCode)) {
|
||||||
|
_lineTabPanes.push({
|
||||||
|
lineCode,
|
||||||
|
lineName,
|
||||||
|
alarmTree: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const siteCode = site.code;
|
||||||
const siteName = codeSites[siteCode]?.name;
|
const siteName = codeSites[siteCode]?.name;
|
||||||
if (!siteName) continue;
|
if (!siteName) continue;
|
||||||
|
|
||||||
@@ -54,7 +52,7 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
_lineTabPanes.find((lineTabPane) => lineTabPane.lineCode === lineCode)?.alarmTree.push(siteNode);
|
_lineTabPanes.find((lineTabPane) => lineTabPane.lineCode === lineCode)?.alarmTree.push(siteNode);
|
||||||
|
|
||||||
// 获取所有警报器
|
// 获取所有警报器
|
||||||
const alarms = siteAlarmsMapFromApi[siteCode];
|
const alarms = siteAlarmsMap.get(siteCode);
|
||||||
if (!alarms || alarms.length === 0) continue;
|
if (!alarms || alarms.length === 0) continue;
|
||||||
|
|
||||||
// 遍历警报器
|
// 遍历警报器
|
||||||
@@ -109,7 +107,7 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!subArea) continue; // 如果还是未找到子区域,则跳过该警报器
|
if (!subArea) continue; // 如果还是未找到2级区域,则跳过该警报器
|
||||||
|
|
||||||
const subAreaNode: AlarmSubAreaNodeOption = {
|
const subAreaNode: AlarmSubAreaNodeOption = {
|
||||||
key: `${alarmSiteCode}${alarmAreaCode}`,
|
key: `${alarmSiteCode}${alarmAreaCode}`,
|
||||||
@@ -121,7 +119,7 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
targetMainAreaNode.children?.push(subAreaNode);
|
targetMainAreaNode.children?.push(subAreaNode);
|
||||||
}
|
}
|
||||||
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`);
|
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`);
|
||||||
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该警报器
|
if (!subAreaNode) continue; // 如果2级区域节点不存在,则跳过该警报器
|
||||||
|
|
||||||
// 构造警报器节点
|
// 构造警报器节点
|
||||||
const alarmType = alarm.code.substring(11, 14);
|
const alarmType = alarm.code.substring(11, 14);
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export const useCameraStore = defineStore('vimp-camera-store', () => {
|
|||||||
targetMainAreaNode.children?.push(subAreaNode);
|
targetMainAreaNode.children?.push(subAreaNode);
|
||||||
}
|
}
|
||||||
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`);
|
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`);
|
||||||
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该摄像机
|
if (!subAreaNode) continue; // 如果2级区域节点不存在,则跳过该摄像机
|
||||||
|
|
||||||
// 构造摄像机节点
|
// 构造摄像机节点
|
||||||
const cameraType = camera.code.substring(11, 14);
|
const cameraType = camera.code.substring(11, 14);
|
||||||
|
|||||||
Reference in New Issue
Block a user