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