refactor(vimp): 抽离并重构vimp的摄像机、告警store与树形类型
- 新增camera-store.ts与alarm-store.ts,封装摄像机、告警业务逻辑为独立Pinia store - 重构tree.ts中的树形节点类型命名与关联判断函数 - 更新stores/index.ts的导出文件路径 - 移除alarm-tree.vue中的冗余类型导入
This commit is contained in:
@@ -3,7 +3,7 @@ import { NTabPane, NTabs, NTree, type TreeOverrideNodeClickBehavior, type TreePr
|
||||
import { h, type CSSProperties } from 'vue';
|
||||
import { useAlarmStore } from '../stores';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useDeviceCenterQuery, type VimpChannel, type VimpStation } from '../apis';
|
||||
import { useDeviceCenterQuery } from '../apis';
|
||||
import { isAlarmNode, isAlarmSiteNode, isAlarmAreaNode } from '../types';
|
||||
|
||||
const { isLoading } = useDeviceCenterQuery();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import type { VimpChannel, VimpStation } from '../apis';
|
||||
import { h, ref } from 'vue';
|
||||
import type { AlarmAreaNodeOption, AlarmNodeOption, CodeArea, CodeLines, CodeSites, AlarmLineTabPane, AlarmSiteNodeOption, AlarmSubAreaNodeOption } from '../types';
|
||||
import type { AlarmMainAreaNodeOption, AlarmNodeOption, CodeArea, CodeLines, CodeSites, AlarmLineTabPane, AlarmSiteNodeOption, AlarmSubAreaNodeOption } from '../types';
|
||||
|
||||
interface BuildLineTabPanesParams {
|
||||
sites: VimpStation[] | null;
|
||||
@@ -79,22 +79,22 @@ export const useAlarmStore = defineStore('vimp-alarm', () => {
|
||||
}
|
||||
if (!siteArea) continue; // 如果还是未找到区域,则跳过该警报器
|
||||
|
||||
// 构造区域节点
|
||||
// 构造1级区域节点
|
||||
if (!siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`)) {
|
||||
const areaNode: AlarmAreaNodeOption = {
|
||||
const mainAreaNode: AlarmMainAreaNodeOption = {
|
||||
key: `${alarmSiteCode}${alarmMainAreaCode}`,
|
||||
label: siteArea.name,
|
||||
children: [],
|
||||
stats: { online: 0, offline: 0, total: 0 },
|
||||
site: site,
|
||||
};
|
||||
siteNode.children?.push(areaNode);
|
||||
siteNode.children?.push(mainAreaNode);
|
||||
}
|
||||
const areaNode = siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`);
|
||||
if (!areaNode) continue; // 如果区域节点不存在,则跳过该警报器
|
||||
const targetMainAreaNode = siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`);
|
||||
if (!targetMainAreaNode) continue; // 如果1级区域节点不存在,则跳过该警报器
|
||||
|
||||
// 构造子区域节点
|
||||
if (!areaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`)) {
|
||||
// 构造2级区域节点
|
||||
if (!targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`)) {
|
||||
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
||||
if (alarmSiteType === 'station') {
|
||||
subArea = codeStationAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
||||
@@ -116,9 +116,9 @@ export const useAlarmStore = defineStore('vimp-alarm', () => {
|
||||
stats: { online: 0, offline: 0, total: 0 },
|
||||
site: site,
|
||||
};
|
||||
areaNode.children?.push(subAreaNode);
|
||||
targetMainAreaNode.children?.push(subAreaNode);
|
||||
}
|
||||
const subAreaNode = areaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`);
|
||||
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`);
|
||||
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该警报器
|
||||
|
||||
// 构造警报器节点
|
||||
@@ -141,16 +141,16 @@ export const useAlarmStore = defineStore('vimp-alarm', () => {
|
||||
|
||||
// 统计站点、区域、子区域的在线/离线/总警报器数量
|
||||
siteNode.stats.total++;
|
||||
areaNode.stats.total++;
|
||||
targetMainAreaNode.stats.total++;
|
||||
subAreaNode.stats.total++;
|
||||
if (alarm.status === 1) {
|
||||
siteNode.stats.online++;
|
||||
areaNode.stats.online++;
|
||||
targetMainAreaNode.stats.online++;
|
||||
subAreaNode.stats.online++;
|
||||
}
|
||||
if (alarm.status === 0) {
|
||||
siteNode.stats.offline++;
|
||||
areaNode.stats.offline++;
|
||||
targetMainAreaNode.stats.offline++;
|
||||
subAreaNode.stats.offline++;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import type { VimpChannel, VimpStation } from '../apis';
|
||||
import { h, ref } from 'vue';
|
||||
import type { CameraAreaNodeOption, CameraNodeOption, CodeArea, CodeLines, CodeSites, CameraLineTabPane, CameraSiteNodeOption, CameraSubAreaNodeOption } from '../types';
|
||||
import type { CameraMainAreaNodeOption, CameraNodeOption, CodeArea, CodeLines, CodeSites, CameraLineTabPane, CameraSiteNodeOption, CameraSubAreaNodeOption } from '../types';
|
||||
|
||||
interface BuildLineTabPanesParams {
|
||||
sites: VimpStation[] | null;
|
||||
@@ -79,22 +79,22 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
||||
}
|
||||
if (!siteArea) continue; // 如果还是未找到区域,则跳过该摄像机
|
||||
|
||||
// 构造区域节点
|
||||
// 构造1级区域节点
|
||||
if (!siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`)) {
|
||||
const areaNode: CameraAreaNodeOption = {
|
||||
const mainAreaNode: CameraMainAreaNodeOption = {
|
||||
key: `${cameraSiteCode}${cameraMainAreaCode}`,
|
||||
label: siteArea.name,
|
||||
children: [],
|
||||
stats: { online: 0, offline: 0, total: 0 },
|
||||
site: site,
|
||||
};
|
||||
siteNode.children?.push(areaNode);
|
||||
siteNode.children?.push(mainAreaNode);
|
||||
}
|
||||
const areaNode = siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`);
|
||||
if (!areaNode) continue; // 如果区域节点不存在,则跳过该摄像机
|
||||
const targetMainAreaNode = siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`);
|
||||
if (!targetMainAreaNode) continue; // 如果1级区域节点不存在,则跳过该摄像机
|
||||
|
||||
// 构造子区域节点
|
||||
if (!areaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`)) {
|
||||
// 构造2级区域节点
|
||||
if (!targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`)) {
|
||||
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
||||
if (cameraSiteType === 'station') {
|
||||
subArea = codeStationAreas.find((area) => area.code === cameraMainAreaCode)?.subs.find((subArea) => subArea.code === cameraAreaCode);
|
||||
@@ -107,7 +107,7 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (!subArea) continue; // 如果还是未找到子区域,则跳过该摄像机
|
||||
if (!subArea) continue; // 如果还是未找到2级区域,则跳过该摄像机
|
||||
|
||||
const subAreaNode: CameraSubAreaNodeOption = {
|
||||
key: `${cameraSiteCode}${cameraAreaCode}`,
|
||||
@@ -116,9 +116,9 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
||||
stats: { online: 0, offline: 0, total: 0 },
|
||||
site: site,
|
||||
};
|
||||
areaNode.children?.push(subAreaNode);
|
||||
targetMainAreaNode.children?.push(subAreaNode);
|
||||
}
|
||||
const subAreaNode = areaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`);
|
||||
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`);
|
||||
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该摄像机
|
||||
|
||||
// 构造摄像机节点
|
||||
@@ -143,16 +143,16 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
||||
|
||||
// 统计站点、区域、子区域的在线/离线/总摄像机数量
|
||||
siteNode.stats.total++;
|
||||
areaNode.stats.total++;
|
||||
targetMainAreaNode.stats.total++;
|
||||
subAreaNode.stats.total++;
|
||||
if (camera.status === 1) {
|
||||
siteNode.stats.online++;
|
||||
areaNode.stats.online++;
|
||||
targetMainAreaNode.stats.online++;
|
||||
subAreaNode.stats.online++;
|
||||
}
|
||||
if (camera.status === 0) {
|
||||
siteNode.stats.offline++;
|
||||
areaNode.stats.offline++;
|
||||
targetMainAreaNode.stats.offline++;
|
||||
subAreaNode.stats.offline++;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './camera';
|
||||
export * from './alarm';
|
||||
export * from './camera-store';
|
||||
export * from './alarm-store';
|
||||
|
||||
@@ -27,14 +27,14 @@ export interface CameraSubAreaNodeOption extends TreeOption {
|
||||
site: VimpStation;
|
||||
}
|
||||
|
||||
export interface CameraAreaNodeOption extends TreeOption {
|
||||
export interface CameraMainAreaNodeOption extends TreeOption {
|
||||
children?: CameraSubAreaNodeOption[];
|
||||
stats: CountStats;
|
||||
site: VimpStation;
|
||||
}
|
||||
|
||||
export interface CameraSiteNodeOption extends TreeOption {
|
||||
children?: CameraAreaNodeOption[];
|
||||
children?: CameraMainAreaNodeOption[];
|
||||
stats: CountStats;
|
||||
online: boolean;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export function isCameraSiteNode(option: TreeOption): option is CameraSiteNodeOp
|
||||
return 'online' in option && !('camera' in option);
|
||||
}
|
||||
|
||||
export function isCameraAreaNode(option: TreeOption): option is CameraAreaNodeOption | CameraSubAreaNodeOption {
|
||||
export function isCameraAreaNode(option: TreeOption): option is CameraMainAreaNodeOption | CameraSubAreaNodeOption {
|
||||
return 'site' in option && !('camera' in option) && !('online' in option);
|
||||
}
|
||||
|
||||
@@ -72,14 +72,14 @@ export interface AlarmSubAreaNodeOption extends TreeOption {
|
||||
site: VimpStation;
|
||||
}
|
||||
|
||||
export interface AlarmAreaNodeOption extends TreeOption {
|
||||
export interface AlarmMainAreaNodeOption extends TreeOption {
|
||||
children?: AlarmSubAreaNodeOption[];
|
||||
stats: CountStats;
|
||||
site: VimpStation;
|
||||
}
|
||||
|
||||
export interface AlarmSiteNodeOption extends TreeOption {
|
||||
children?: AlarmAreaNodeOption[];
|
||||
children?: AlarmMainAreaNodeOption[];
|
||||
stats: CountStats;
|
||||
online: boolean;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ export function isAlarmSiteNode(option: TreeOption): option is AlarmSiteNodeOpti
|
||||
return 'online' in option && !('alarm' in option);
|
||||
}
|
||||
|
||||
export function isAlarmAreaNode(option: TreeOption): option is AlarmAreaNodeOption | AlarmSubAreaNodeOption {
|
||||
export function isAlarmAreaNode(option: TreeOption): option is AlarmMainAreaNodeOption | AlarmSubAreaNodeOption {
|
||||
return 'site' in option && !('alarm' in option) && !('online' in option);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user