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 { h, type CSSProperties } from 'vue';
|
||||||
import { useAlarmStore } from '../stores';
|
import { useAlarmStore } from '../stores';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useDeviceCenterQuery, type VimpChannel, type VimpStation } from '../apis';
|
import { useDeviceCenterQuery } from '../apis';
|
||||||
import { isAlarmNode, isAlarmSiteNode, isAlarmAreaNode } from '../types';
|
import { isAlarmNode, isAlarmSiteNode, isAlarmAreaNode } from '../types';
|
||||||
|
|
||||||
const { isLoading } = useDeviceCenterQuery();
|
const { isLoading } = useDeviceCenterQuery();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { VimpChannel, VimpStation } from '../apis';
|
import type { VimpChannel, VimpStation } from '../apis';
|
||||||
import { h, ref } from 'vue';
|
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 {
|
interface BuildLineTabPanesParams {
|
||||||
sites: VimpStation[] | null;
|
sites: VimpStation[] | null;
|
||||||
@@ -79,22 +79,22 @@ export const useAlarmStore = defineStore('vimp-alarm', () => {
|
|||||||
}
|
}
|
||||||
if (!siteArea) continue; // 如果还是未找到区域,则跳过该警报器
|
if (!siteArea) continue; // 如果还是未找到区域,则跳过该警报器
|
||||||
|
|
||||||
// 构造区域节点
|
// 构造1级区域节点
|
||||||
if (!siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`)) {
|
if (!siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`)) {
|
||||||
const areaNode: AlarmAreaNodeOption = {
|
const mainAreaNode: AlarmMainAreaNodeOption = {
|
||||||
key: `${alarmSiteCode}${alarmMainAreaCode}`,
|
key: `${alarmSiteCode}${alarmMainAreaCode}`,
|
||||||
label: siteArea.name,
|
label: siteArea.name,
|
||||||
children: [],
|
children: [],
|
||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
site: site,
|
||||||
};
|
};
|
||||||
siteNode.children?.push(areaNode);
|
siteNode.children?.push(mainAreaNode);
|
||||||
}
|
}
|
||||||
const areaNode = siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`);
|
const targetMainAreaNode = siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`);
|
||||||
if (!areaNode) continue; // 如果区域节点不存在,则跳过该警报器
|
if (!targetMainAreaNode) continue; // 如果1级区域节点不存在,则跳过该警报器
|
||||||
|
|
||||||
// 构造子区域节点
|
// 构造2级区域节点
|
||||||
if (!areaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`)) {
|
if (!targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`)) {
|
||||||
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
||||||
if (alarmSiteType === 'station') {
|
if (alarmSiteType === 'station') {
|
||||||
subArea = codeStationAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
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 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
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; // 如果子区域节点不存在,则跳过该警报器
|
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该警报器
|
||||||
|
|
||||||
// 构造警报器节点
|
// 构造警报器节点
|
||||||
@@ -141,16 +141,16 @@ export const useAlarmStore = defineStore('vimp-alarm', () => {
|
|||||||
|
|
||||||
// 统计站点、区域、子区域的在线/离线/总警报器数量
|
// 统计站点、区域、子区域的在线/离线/总警报器数量
|
||||||
siteNode.stats.total++;
|
siteNode.stats.total++;
|
||||||
areaNode.stats.total++;
|
targetMainAreaNode.stats.total++;
|
||||||
subAreaNode.stats.total++;
|
subAreaNode.stats.total++;
|
||||||
if (alarm.status === 1) {
|
if (alarm.status === 1) {
|
||||||
siteNode.stats.online++;
|
siteNode.stats.online++;
|
||||||
areaNode.stats.online++;
|
targetMainAreaNode.stats.online++;
|
||||||
subAreaNode.stats.online++;
|
subAreaNode.stats.online++;
|
||||||
}
|
}
|
||||||
if (alarm.status === 0) {
|
if (alarm.status === 0) {
|
||||||
siteNode.stats.offline++;
|
siteNode.stats.offline++;
|
||||||
areaNode.stats.offline++;
|
targetMainAreaNode.stats.offline++;
|
||||||
subAreaNode.stats.offline++;
|
subAreaNode.stats.offline++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { VimpChannel, VimpStation } from '../apis';
|
import type { VimpChannel, VimpStation } from '../apis';
|
||||||
import { h, ref } from 'vue';
|
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 {
|
interface BuildLineTabPanesParams {
|
||||||
sites: VimpStation[] | null;
|
sites: VimpStation[] | null;
|
||||||
@@ -79,22 +79,22 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
|||||||
}
|
}
|
||||||
if (!siteArea) continue; // 如果还是未找到区域,则跳过该摄像机
|
if (!siteArea) continue; // 如果还是未找到区域,则跳过该摄像机
|
||||||
|
|
||||||
// 构造区域节点
|
// 构造1级区域节点
|
||||||
if (!siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`)) {
|
if (!siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`)) {
|
||||||
const areaNode: CameraAreaNodeOption = {
|
const mainAreaNode: CameraMainAreaNodeOption = {
|
||||||
key: `${cameraSiteCode}${cameraMainAreaCode}`,
|
key: `${cameraSiteCode}${cameraMainAreaCode}`,
|
||||||
label: siteArea.name,
|
label: siteArea.name,
|
||||||
children: [],
|
children: [],
|
||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
site: site,
|
||||||
};
|
};
|
||||||
siteNode.children?.push(areaNode);
|
siteNode.children?.push(mainAreaNode);
|
||||||
}
|
}
|
||||||
const areaNode = siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`);
|
const targetMainAreaNode = siteNode.children?.find((areaNode) => areaNode.key === `${cameraSiteCode}${cameraMainAreaCode}`);
|
||||||
if (!areaNode) continue; // 如果区域节点不存在,则跳过该摄像机
|
if (!targetMainAreaNode) continue; // 如果1级区域节点不存在,则跳过该摄像机
|
||||||
|
|
||||||
// 构造子区域节点
|
// 构造2级区域节点
|
||||||
if (!areaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`)) {
|
if (!targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${cameraSiteCode}${cameraAreaCode}`)) {
|
||||||
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
||||||
if (cameraSiteType === 'station') {
|
if (cameraSiteType === 'station') {
|
||||||
subArea = codeStationAreas.find((area) => area.code === cameraMainAreaCode)?.subs.find((subArea) => subArea.code === cameraAreaCode);
|
subArea = codeStationAreas.find((area) => area.code === cameraMainAreaCode)?.subs.find((subArea) => subArea.code === cameraAreaCode);
|
||||||
@@ -107,7 +107,7 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!subArea) continue; // 如果还是未找到子区域,则跳过该摄像机
|
if (!subArea) continue; // 如果还是未找到2级区域,则跳过该摄像机
|
||||||
|
|
||||||
const subAreaNode: CameraSubAreaNodeOption = {
|
const subAreaNode: CameraSubAreaNodeOption = {
|
||||||
key: `${cameraSiteCode}${cameraAreaCode}`,
|
key: `${cameraSiteCode}${cameraAreaCode}`,
|
||||||
@@ -116,9 +116,9 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
|||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
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; // 如果子区域节点不存在,则跳过该摄像机
|
if (!subAreaNode) continue; // 如果子区域节点不存在,则跳过该摄像机
|
||||||
|
|
||||||
// 构造摄像机节点
|
// 构造摄像机节点
|
||||||
@@ -143,16 +143,16 @@ export const useCameraStore = defineStore('vimp-camera', () => {
|
|||||||
|
|
||||||
// 统计站点、区域、子区域的在线/离线/总摄像机数量
|
// 统计站点、区域、子区域的在线/离线/总摄像机数量
|
||||||
siteNode.stats.total++;
|
siteNode.stats.total++;
|
||||||
areaNode.stats.total++;
|
targetMainAreaNode.stats.total++;
|
||||||
subAreaNode.stats.total++;
|
subAreaNode.stats.total++;
|
||||||
if (camera.status === 1) {
|
if (camera.status === 1) {
|
||||||
siteNode.stats.online++;
|
siteNode.stats.online++;
|
||||||
areaNode.stats.online++;
|
targetMainAreaNode.stats.online++;
|
||||||
subAreaNode.stats.online++;
|
subAreaNode.stats.online++;
|
||||||
}
|
}
|
||||||
if (camera.status === 0) {
|
if (camera.status === 0) {
|
||||||
siteNode.stats.offline++;
|
siteNode.stats.offline++;
|
||||||
areaNode.stats.offline++;
|
targetMainAreaNode.stats.offline++;
|
||||||
subAreaNode.stats.offline++;
|
subAreaNode.stats.offline++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
export * from './camera';
|
export * from './camera-store';
|
||||||
export * from './alarm';
|
export * from './alarm-store';
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ export interface CameraSubAreaNodeOption extends TreeOption {
|
|||||||
site: VimpStation;
|
site: VimpStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CameraAreaNodeOption extends TreeOption {
|
export interface CameraMainAreaNodeOption extends TreeOption {
|
||||||
children?: CameraSubAreaNodeOption[];
|
children?: CameraSubAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CameraSiteNodeOption extends TreeOption {
|
export interface CameraSiteNodeOption extends TreeOption {
|
||||||
children?: CameraAreaNodeOption[];
|
children?: CameraMainAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
online: boolean;
|
online: boolean;
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ export function isCameraSiteNode(option: TreeOption): option is CameraSiteNodeOp
|
|||||||
return 'online' in option && !('camera' in option);
|
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);
|
return 'site' in option && !('camera' in option) && !('online' in option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,14 +72,14 @@ export interface AlarmSubAreaNodeOption extends TreeOption {
|
|||||||
site: VimpStation;
|
site: VimpStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlarmAreaNodeOption extends TreeOption {
|
export interface AlarmMainAreaNodeOption extends TreeOption {
|
||||||
children?: AlarmSubAreaNodeOption[];
|
children?: AlarmSubAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpStation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlarmSiteNodeOption extends TreeOption {
|
export interface AlarmSiteNodeOption extends TreeOption {
|
||||||
children?: AlarmAreaNodeOption[];
|
children?: AlarmMainAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
online: boolean;
|
online: boolean;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ export function isAlarmSiteNode(option: TreeOption): option is AlarmSiteNodeOpti
|
|||||||
return 'online' in option && !('alarm' in option);
|
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);
|
return 'site' in option && !('alarm' in option) && !('online' in option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user