Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad9a0011a5 | |||
| 8403a41cef | |||
| e8aa9b96f8 | |||
| 6f14370751 | |||
| 6fed499d78 | |||
| fa44554593 | |||
| cbeddebbc0 | |||
| c78c8b8419 | |||
| 148be10186 | |||
| 650ca78464 |
@@ -13,9 +13,27 @@ import destr from 'destr';
|
|||||||
import { isFunction } from 'es-toolkit';
|
import { isFunction } from 'es-toolkit';
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
import { DownloadIcon, Trash2Icon, UploadIcon } from 'lucide-vue-next';
|
import { DownloadIcon, Trash2Icon, UploadIcon } from 'lucide-vue-next';
|
||||||
import { NButton, NButtonGroup, NDivider, NDrawer, NDrawerContent, NDropdown, NFlex, NFormItem, NIcon, NInput, NInputNumber, NModal, NSwitch, NText, NTooltip, type DropdownOption } from 'naive-ui';
|
import {
|
||||||
|
NButton,
|
||||||
|
NButtonGroup,
|
||||||
|
NDivider,
|
||||||
|
NDrawer,
|
||||||
|
NDrawerContent,
|
||||||
|
NDropdown,
|
||||||
|
NFlex,
|
||||||
|
NFormItem,
|
||||||
|
NIcon,
|
||||||
|
NInput,
|
||||||
|
NInputNumber,
|
||||||
|
NModal,
|
||||||
|
NSwitch,
|
||||||
|
NText,
|
||||||
|
NTooltip,
|
||||||
|
type DropdownOption,
|
||||||
|
type InputInst,
|
||||||
|
} from 'naive-ui';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -149,8 +167,14 @@ useEventListener('keydown', (event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const expectToShowDebugCodeInput = ref(false);
|
const expectToShowDebugCodeInput = ref(false);
|
||||||
|
const debugCodeInputRef = useTemplateRef<InputInst>('debug-code-input-ref');
|
||||||
const onModalAfterEnter = () => {
|
const onModalAfterEnter = () => {
|
||||||
expectToShowDebugCodeInput.value = !debugMode.value;
|
expectToShowDebugCodeInput.value = !debugMode.value;
|
||||||
|
if (expectToShowDebugCodeInput.value) {
|
||||||
|
nextTick(() => {
|
||||||
|
debugCodeInputRef.value?.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const onModalAfterLeave = () => {
|
const onModalAfterLeave = () => {
|
||||||
expectToShowDebugCodeInput.value = false;
|
expectToShowDebugCodeInput.value = false;
|
||||||
@@ -412,7 +436,7 @@ const onClickVersion = () => {
|
|||||||
<NText v-else>确认关闭调试模式</NText>
|
<NText v-else>确认关闭调试模式</NText>
|
||||||
</template>
|
</template>
|
||||||
<template #default>
|
<template #default>
|
||||||
<NInput v-if="expectToShowDebugCodeInput" v-model:value="debugCode" placeholder="输入调试码" @keyup.enter="enableDebugMode" />
|
<NInput ref="debug-code-input-ref" v-if="expectToShowDebugCodeInput" v-model:value="debugCode" placeholder="输入调试码" @keyup.enter="enableDebugMode" />
|
||||||
</template>
|
</template>
|
||||||
<template #action>
|
<template #action>
|
||||||
<NButton @click="showDebugCodeModal = false">取消</NButton>
|
<NButton @click="showDebugCodeModal = false">取消</NButton>
|
||||||
|
|||||||
@@ -1,9 +1,59 @@
|
|||||||
import type { AxiosError, AxiosRequestConfig, CreateAxiosDefaults } from 'axios';
|
import type { AxiosError, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from 'axios';
|
||||||
import axios from 'axios';
|
import axios, { isAxiosError } from 'axios';
|
||||||
import type { VimpResponse, VimpResult } from '../../types';
|
import type { VimpResponse, VimpResult } from '../../types';
|
||||||
|
import { useUserStore } from '@/stores';
|
||||||
|
import { getAppEnvConfig } from '@/utils';
|
||||||
|
import router from '@/router';
|
||||||
|
|
||||||
|
export interface VimpRequestOptions extends CreateAxiosDefaults {
|
||||||
|
requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
|
||||||
|
responseInterceptor?: (resp: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>;
|
||||||
|
responseErrorInterceptor?: (error: any) => any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createVimpClient = (config?: VimpRequestOptions) => {
|
||||||
|
const defaultRequestInterceptor = (config: InternalAxiosRequestConfig) => config;
|
||||||
|
const defaultResponseInterceptor = (response: AxiosResponse) => response;
|
||||||
|
const defaultResponseErrorInterceptor = (error: any) => {
|
||||||
|
if (isAxiosError(error)) {
|
||||||
|
if (error.status === 401) {
|
||||||
|
// 处理 401 错误
|
||||||
|
}
|
||||||
|
if (error.status === 404) {
|
||||||
|
// 处理 404 错误
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestInterceptor = config?.requestInterceptor ?? defaultRequestInterceptor;
|
||||||
|
const responseInterceptor = config?.responseInterceptor ?? defaultResponseInterceptor;
|
||||||
|
const responseErrorInterceptor = config?.responseErrorInterceptor ?? defaultResponseErrorInterceptor;
|
||||||
|
|
||||||
export const createVimpClient = (config?: CreateAxiosDefaults) => {
|
|
||||||
const instance = axios.create(config);
|
const instance = axios.create(config);
|
||||||
|
instance.interceptors.request.use(requestInterceptor);
|
||||||
|
instance.interceptors.response.use(responseInterceptor, responseErrorInterceptor);
|
||||||
|
|
||||||
|
const vimpGet = <T>(url: string, options?: AxiosRequestConfig & { retRaw?: boolean }): Promise<VimpResponse<T>> => {
|
||||||
|
const { retRaw, ...reqConfig } = options ?? {};
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
instance
|
||||||
|
.get(url, {
|
||||||
|
...reqConfig,
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (retRaw) {
|
||||||
|
resolve([null, res.data as T, null]);
|
||||||
|
} else {
|
||||||
|
const resData = res.data as VimpResult<T>;
|
||||||
|
resolve([null, resData.data, resData]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
resolve([err as AxiosError, null, null]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const vimpPost = <T>(url: string, data?: AxiosRequestConfig['data'], options?: Partial<Omit<AxiosRequestConfig, 'data'>> & { retRaw?: boolean; upload?: boolean }): Promise<VimpResponse<T>> => {
|
const vimpPost = <T>(url: string, data?: AxiosRequestConfig['data'], options?: Partial<Omit<AxiosRequestConfig, 'data'>> & { retRaw?: boolean; upload?: boolean }): Promise<VimpResponse<T>> => {
|
||||||
const { retRaw, upload, ...reqConfig } = options ?? {};
|
const { retRaw, upload, ...reqConfig } = options ?? {};
|
||||||
@@ -24,9 +74,40 @@ export const createVimpClient = (config?: CreateAxiosDefaults) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const httpPut = <T>(url: string, data?: AxiosRequestConfig['data'], options?: Partial<Omit<AxiosRequestConfig, 'data'>>): Promise<VimpResponse<T>> => {
|
||||||
|
const reqConfig = options ?? {};
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
instance
|
||||||
|
.put<VimpResult<T>>(url, data, { ...reqConfig })
|
||||||
|
.then((res) => {
|
||||||
|
resolve([null, res.data.data, res.data]);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
resolve([err as AxiosError, null, null]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const httpDelete = <T>(url: string, idList: string[], options?: Partial<Omit<AxiosRequestConfig, 'data'>>): Promise<VimpResponse<T>> => {
|
||||||
|
const reqConfig = options ?? {};
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
instance
|
||||||
|
.delete<VimpResult<T>>(url, { ...reqConfig, data: idList })
|
||||||
|
.then((res) => {
|
||||||
|
resolve([null, res.data.data, res.data]);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
resolve([err as AxiosError, null, null]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
instance,
|
instance,
|
||||||
|
get: vimpGet,
|
||||||
post: vimpPost,
|
post: vimpPost,
|
||||||
|
put: httpPut,
|
||||||
|
delete: httpDelete,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,4 +123,30 @@ export const unwrapVimpResponse = <T>(resp: VimpResponse<T>) => {
|
|||||||
|
|
||||||
export const vimpClient = createVimpClient({
|
export const vimpClient = createVimpClient({
|
||||||
baseURL: `/vimp/api/client`,
|
baseURL: `/vimp/api/client`,
|
||||||
|
requestInterceptor: (config) => {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig();
|
||||||
|
const newAuthorization = window.btoa(`${lampClientId}:${lampClientSecret}`);
|
||||||
|
const authorization = lampAuthorization.trim() !== '' ? lampAuthorization : newAuthorization;
|
||||||
|
config.headers.set('accept-language', 'zh-CN,zh;q=0.9');
|
||||||
|
config.headers.set('accept', 'application/json, text/plain, */*');
|
||||||
|
config.headers.set('Applicationid', '');
|
||||||
|
config.headers.set('Tenantid', '1');
|
||||||
|
config.headers.set('Authorization', authorization);
|
||||||
|
config.headers.set('token', userStore.userLoginResult?.token ?? '');
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
responseInterceptor: (response) => {
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
responseErrorInterceptor: (error) => {
|
||||||
|
const err = error as AxiosError;
|
||||||
|
if (err.response?.status === 401) {
|
||||||
|
window.$message.error('登录超时,请重新登录');
|
||||||
|
const userStore = useUserStore();
|
||||||
|
userStore.resetStore();
|
||||||
|
router.push({ path: '/login' });
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export * from './vimp-channel';
|
export * from './vimp-channel';
|
||||||
export * from './vimp-station';
|
export * from './vimp-site';
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export interface VimpRawSite {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
online?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VimpSite {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
online: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const normalizeVimpSite = (site: VimpRawSite): VimpSite => ({
|
||||||
|
code: site.code,
|
||||||
|
name: site.name,
|
||||||
|
online: site.online ?? true,
|
||||||
|
});
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
export interface VimpStation {
|
|
||||||
code: string;
|
|
||||||
name: string;
|
|
||||||
online: boolean;
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { unwrapVimpResponse, vimpClient } from '../client';
|
import { unwrapVimpResponse, vimpClient } from '../client';
|
||||||
import type { VimpStation } from '../model';
|
import { normalizeVimpSite, type VimpRawSite } from '../model';
|
||||||
|
|
||||||
export const catalogAllDeviceApi = async (options?: { signal?: AbortSignal }) => {
|
export const catalogAllDeviceApi = async (options?: { signal?: AbortSignal }) => {
|
||||||
const { signal } = options ?? {};
|
const { signal } = options ?? {};
|
||||||
const client = vimpClient;
|
const client = vimpClient;
|
||||||
const endpoint = `/catalog/allDevice`;
|
const endpoint = `/catalog/allDevice`;
|
||||||
const resp = await client.post<VimpStation[]>(endpoint, {}, { signal });
|
const resp = await client.post<VimpRawSite[]>(endpoint, {}, { signal });
|
||||||
const data = unwrapVimpResponse(resp);
|
const data = unwrapVimpResponse(resp);
|
||||||
return data;
|
return data?.map(normalizeVimpSite) ?? null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NTabPane, NTabs, NTree, type TreeOverrideNodeClickBehavior, type TreeProps } from 'naive-ui';
|
import { NIcon, NTabPane, NTabs, NTree, type TreeOverrideNodeClickBehavior, type TreeProps } from 'naive-ui';
|
||||||
import { h, type CSSProperties } from 'vue';
|
import { h, type CSSProperties } from 'vue';
|
||||||
import { useAlarmStore, useResourcePanelStore } from '../stores';
|
import { useAlarmStore, useResourcePanelStore } from '../stores';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useDeviceCenterQuery } from '../composables';
|
import { useChannelsQuery } from '../composables';
|
||||||
import { isAlarmNode, isAlarmSiteNode, isAlarmAreaNode } from '../types';
|
import { isAlarmNode, isAlarmSiteNode, isAlarmAreaNode } from '../types';
|
||||||
|
import { SirenIcon } from 'lucide-vue-next';
|
||||||
|
|
||||||
const { isLoading } = useDeviceCenterQuery();
|
const { isLoading } = useChannelsQuery();
|
||||||
|
|
||||||
const alarmStore = useAlarmStore();
|
const alarmStore = useAlarmStore();
|
||||||
const { lineTabPanes } = storeToRefs(alarmStore);
|
const { lineTabPanes } = storeToRefs(alarmStore);
|
||||||
@@ -51,6 +52,9 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
const alarmNodeStyle: CSSProperties = {
|
const alarmNodeStyle: CSSProperties = {
|
||||||
opacity: alarmOnline() ? 1 : 0.5,
|
opacity: alarmOnline() ? 1 : 0.5,
|
||||||
cursor: alarmOnline() ? 'pointer' : 'not-allowed',
|
cursor: alarmOnline() ? 'pointer' : 'not-allowed',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '6px',
|
||||||
};
|
};
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
@@ -69,7 +73,7 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
event.dataTransfer?.setData('name', alarm.name);
|
event.dataTransfer?.setData('name', alarm.name);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
alarm.name,
|
[h(NIcon, () => h(SirenIcon)), h('span', alarm.name)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +81,21 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
return option.label;
|
return option.label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderNodeSuffix: TreeProps['renderSuffix'] = ({ option }) => {
|
||||||
|
if (isAlarmSiteNode(option)) {
|
||||||
|
const { online, offline, total } = option.stats;
|
||||||
|
return `(${online}/${offline}/${total})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAlarmAreaNode(option)) {
|
||||||
|
const { online, offline, total } = option.stats;
|
||||||
|
const suffixStyle: CSSProperties = option.areaLevel === 1 ? { marginRight: '8px', opacity: 0.6 } : { marginRight: '16px', opacity: 0.4 };
|
||||||
|
return h('div', { style: suffixStyle }, `(${online}/${offline}/${total})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
const resourcePanelStore = useResourcePanelStore();
|
const resourcePanelStore = useResourcePanelStore();
|
||||||
const { searchPattern } = storeToRefs(resourcePanelStore);
|
const { searchPattern } = storeToRefs(resourcePanelStore);
|
||||||
|
|
||||||
@@ -98,6 +117,7 @@ const searchFilter: TreeProps['filter'] = (pattern, node) => {
|
|||||||
virtual-scroll
|
virtual-scroll
|
||||||
style="height: 100%"
|
style="height: 100%"
|
||||||
:render-label="renderNodeLabel"
|
:render-label="renderNodeLabel"
|
||||||
|
:render-suffix="renderNodeSuffix"
|
||||||
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
||||||
:default-expand-all="searchPattern.trim().length > 0"
|
:default-expand-all="searchPattern.trim().length > 0"
|
||||||
:show-irrelevant-nodes="false"
|
:show-irrelevant-nodes="false"
|
||||||
@@ -107,22 +127,42 @@ const searchFilter: TreeProps['filter'] = (pattern, node) => {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="lineTabPanes.length > 1">
|
<template v-if="lineTabPanes.length > 1">
|
||||||
<NTabs :type="'card'" :placement="'left'" style="height: 100%">
|
<NTabs
|
||||||
<NTabPane v-for="{ lineCode, lineName, alarmTree } in lineTabPanes" :key="lineCode" :name="lineName" :tab="lineName">
|
:type="'card'"
|
||||||
<NTree
|
:placement="'left'"
|
||||||
block-line
|
style="height: 100%"
|
||||||
block-node
|
:tab-style="{
|
||||||
show-line
|
width: '64px',
|
||||||
virtual-scroll
|
height: '36px',
|
||||||
style="height: 100%"
|
}"
|
||||||
:render-label="renderNodeLabel"
|
:style="{
|
||||||
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
'--n-bar-color': '#0000',
|
||||||
:default-expand-all="false"
|
'--n-pane-padding-top': '0',
|
||||||
:show-irrelevant-nodes="false"
|
'--n-tab-gap-vertical': '0',
|
||||||
:data="alarmTree"
|
// '--n-tab-padding-vertical': '14px 12px'
|
||||||
:pattern="searchPattern"
|
}"
|
||||||
:filter="searchFilter"
|
>
|
||||||
/>
|
<NTabPane v-for="{ lineCode, lineName, alarmTree } in lineTabPanes" :key="lineCode" :name="lineName">
|
||||||
|
<template #tab>
|
||||||
|
<span style="font-size: 12px">{{ lineName }}</span>
|
||||||
|
</template>
|
||||||
|
<template #default>
|
||||||
|
<NTree
|
||||||
|
block-line
|
||||||
|
block-node
|
||||||
|
show-line
|
||||||
|
virtual-scroll
|
||||||
|
style="height: 100%"
|
||||||
|
:render-label="renderNodeLabel"
|
||||||
|
:render-suffix="renderNodeSuffix"
|
||||||
|
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
||||||
|
:default-expand-all="false"
|
||||||
|
:show-irrelevant-nodes="false"
|
||||||
|
:data="alarmTree"
|
||||||
|
:pattern="searchPattern"
|
||||||
|
:filter="searchFilter"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
</NTabs>
|
</NTabs>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { NIcon, NTabPane, NTabs, NTree, type TreeOverrideNodeClickBehavior, type
|
|||||||
import { h, type CSSProperties } from 'vue';
|
import { h, type CSSProperties } from 'vue';
|
||||||
import { useCameraStore, useResourcePanelStore } from '../stores';
|
import { useCameraStore, useResourcePanelStore } from '../stores';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useDeviceCenterQuery } from '../composables';
|
import { useChannelsQuery } from '../composables';
|
||||||
import { isCameraNode, isCameraSiteNode, isCameraAreaNode } from '../types';
|
import { isCameraNode, isCameraSiteNode, isCameraAreaNode } from '../types';
|
||||||
import PtzCamera from './icon/ptz-camera.vue';
|
import PtzCamera from './icon/ptz-camera.vue';
|
||||||
import HemiPtzCamera from './icon/hemi-ptz-camera.vue';
|
import HemiPtzCamera from './icon/hemi-ptz-camera.vue';
|
||||||
import BulletCamera from './icon/bullet-camera.vue';
|
import BulletCamera from './icon/bullet-camera.vue';
|
||||||
|
|
||||||
const { isLoading } = useDeviceCenterQuery();
|
const { isLoading } = useChannelsQuery();
|
||||||
|
|
||||||
const cameraStore = useCameraStore();
|
const cameraStore = useCameraStore();
|
||||||
const { lineTabPanes } = storeToRefs(cameraStore);
|
const { lineTabPanes } = storeToRefs(cameraStore);
|
||||||
@@ -54,7 +54,11 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
const cameraNodeStyle: CSSProperties = {
|
const cameraNodeStyle: CSSProperties = {
|
||||||
opacity: cameraOnline() ? 1 : 0.5,
|
opacity: cameraOnline() ? 1 : 0.5,
|
||||||
cursor: cameraOnline() ? 'pointer' : 'not-allowed',
|
cursor: cameraOnline() ? 'pointer' : 'not-allowed',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '6px',
|
||||||
};
|
};
|
||||||
|
const cameraIcon = option.type === '004' ? h(NIcon, () => h(PtzCamera)) : option.type === '005' ? h(NIcon, () => h(HemiPtzCamera)) : option.type === '006' ? h(NIcon, () => h(BulletCamera)) : null;
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
{
|
{
|
||||||
@@ -72,7 +76,7 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
event.dataTransfer?.setData('name', camera.name);
|
event.dataTransfer?.setData('name', camera.name);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
camera.name,
|
[cameraIcon, h('span', camera.name)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,16 +84,6 @@ const renderNodeLabel: TreeProps['renderLabel'] = ({ option }) => {
|
|||||||
return option.label;
|
return option.label;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNodePrefix: TreeProps['renderPrefix'] = ({ option }) => {
|
|
||||||
if (!isCameraNode(option)) return null;
|
|
||||||
|
|
||||||
if (option.type === '004') return h(NIcon, () => h(PtzCamera));
|
|
||||||
if (option.type === '005') return h(NIcon, () => h(HemiPtzCamera));
|
|
||||||
if (option.type === '006') return h(NIcon, () => h(BulletCamera));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNodeSuffix: TreeProps['renderSuffix'] = ({ option }) => {
|
const renderNodeSuffix: TreeProps['renderSuffix'] = ({ option }) => {
|
||||||
if (isCameraSiteNode(option)) {
|
if (isCameraSiteNode(option)) {
|
||||||
const { online, offline, total } = option.stats;
|
const { online, offline, total } = option.stats;
|
||||||
@@ -126,7 +120,6 @@ const searchFilter: TreeProps['filter'] = (pattern, node) => {
|
|||||||
virtual-scroll
|
virtual-scroll
|
||||||
style="height: 100%"
|
style="height: 100%"
|
||||||
:render-label="renderNodeLabel"
|
:render-label="renderNodeLabel"
|
||||||
:render-prefix="renderNodePrefix"
|
|
||||||
:render-suffix="renderNodeSuffix"
|
:render-suffix="renderNodeSuffix"
|
||||||
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
||||||
:default-expand-all="searchPattern.trim().length > 0"
|
:default-expand-all="searchPattern.trim().length > 0"
|
||||||
@@ -137,24 +130,42 @@ const searchFilter: TreeProps['filter'] = (pattern, node) => {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="lineTabPanes.length > 1">
|
<template v-if="lineTabPanes.length > 1">
|
||||||
<NTabs :type="'card'" :placement="'left'" style="height: 100%">
|
<NTabs
|
||||||
<NTabPane v-for="{ lineCode, lineName, cameraTree } in lineTabPanes" :key="lineCode" :name="lineName" :tab="lineName">
|
:type="'card'"
|
||||||
<NTree
|
:placement="'left'"
|
||||||
block-line
|
style="height: 100%"
|
||||||
block-node
|
:tab-style="{
|
||||||
show-line
|
width: '64px',
|
||||||
virtual-scroll
|
height: '36px',
|
||||||
style="height: 100%"
|
}"
|
||||||
:render-label="renderNodeLabel"
|
:style="{
|
||||||
:render-prefix="renderNodePrefix"
|
'--n-bar-color': '#0000',
|
||||||
:render-suffix="renderNodeSuffix"
|
'--n-pane-padding-top': '0',
|
||||||
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
'--n-tab-gap-vertical': '0',
|
||||||
:default-expand-all="false"
|
// '--n-tab-padding-vertical': '14px 12px'
|
||||||
:show-irrelevant-nodes="false"
|
}"
|
||||||
:data="cameraTree"
|
>
|
||||||
:pattern="searchPattern"
|
<NTabPane v-for="{ lineCode, lineName, cameraTree } in lineTabPanes" :key="lineCode" :name="lineName">
|
||||||
:filter="searchFilter"
|
<template #tab>
|
||||||
/>
|
<span style="font-size: 12px">{{ lineName }}</span>
|
||||||
|
</template>
|
||||||
|
<template #default>
|
||||||
|
<NTree
|
||||||
|
block-line
|
||||||
|
block-node
|
||||||
|
show-line
|
||||||
|
virtual-scroll
|
||||||
|
style="height: 100%"
|
||||||
|
:render-label="renderNodeLabel"
|
||||||
|
:render-suffix="renderNodeSuffix"
|
||||||
|
:override-default-node-click-behavior="overrideNodeClickBehavior"
|
||||||
|
:default-expand-all="false"
|
||||||
|
:show-irrelevant-nodes="false"
|
||||||
|
:data="cameraTree"
|
||||||
|
:pattern="searchPattern"
|
||||||
|
:filter="searchFilter"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
</NTabs>
|
</NTabs>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export * from './use-device-center-query';
|
export * from './use-channels-query';
|
||||||
|
|||||||
+31
-10
@@ -2,9 +2,10 @@ import { useQuery } from '@tanstack/vue-query';
|
|||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import type { AxiosRequestConfig } from 'axios';
|
import type { AxiosRequestConfig } from 'axios';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { compileCodeAreas, type CodeArea, type CodeLines, type CodeSites, type CompiledCodeAreaMaps, type CompiledCodeAreas } from '../../types';
|
import { compileCodeAreas, type CodeArea, type CodeLines, type CodeSites } from '../../types';
|
||||||
import { useCameraStore, useAlarmStore } from '../../stores';
|
import { useCameraStore, useAlarmStore } from '../../stores';
|
||||||
import { catalogAllDeviceApi, catalogChannelApi, type VimpChannel, type VimpStation } from '../../apis';
|
import { catalogAllDeviceApi, catalogChannelApi, type VimpChannel, type VimpSite } from '../../apis';
|
||||||
|
import { VIMP_CHANNELS_QUERY_KEY } from '../../constants';
|
||||||
|
|
||||||
const config: AxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -30,12 +31,26 @@ const buildTrainAreas = () => {
|
|||||||
return codeTrainAreas;
|
return codeTrainAreas;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDeviceCenterQuery = () => {
|
const compareByCode = <T extends { code: string }>(a: T, b: T) => {
|
||||||
|
if (a.code < b.code) return -1;
|
||||||
|
if (a.code > b.code) return 1;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
const sortSitesByCode = (sites: VimpSite[]) => {
|
||||||
|
sites.sort(compareByCode);
|
||||||
|
};
|
||||||
|
const sortChannelsMapByCode = (siteCodeToChannelsMap: Map<string, VimpChannel[]>) => {
|
||||||
|
for (const channels of siteCodeToChannelsMap.values()) {
|
||||||
|
channels.sort(compareByCode);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useChannelsQuery = () => {
|
||||||
const cameraStore = useCameraStore();
|
const cameraStore = useCameraStore();
|
||||||
const alarmStore = useAlarmStore();
|
const alarmStore = useAlarmStore();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => ['vimp-device']),
|
queryKey: computed(() => [VIMP_CHANNELS_QUERY_KEY]),
|
||||||
refetchInterval: 10 * 1000,
|
refetchInterval: 10 * 1000,
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
@@ -59,8 +74,8 @@ export const useDeviceCenterQuery = () => {
|
|||||||
// 从 /allDevice 接口获取的站点信息并不保证真实性和完整性,
|
// 从 /allDevice 接口获取的站点信息并不保证真实性和完整性,
|
||||||
// 例如有一个站点的编码是 010699 开头,但是其下的通道是 010199 和 010599 开头,
|
// 例如有一个站点的编码是 010699 开头,但是其下的通道是 010199 和 010599 开头,
|
||||||
// 而 010699 是一个不存在的站点编码,所以需要基于通道的编码来确定所有的站点。
|
// 而 010699 是一个不存在的站点编码,所以需要基于通道的编码来确定所有的站点。
|
||||||
const cameraSites: VimpStation[] = [];
|
const cameraSites: VimpSite[] = [];
|
||||||
const alarmSites: VimpStation[] = [];
|
const alarmSites: VimpSite[] = [];
|
||||||
const cameraBuiltSitesSet = new Set<string>();
|
const cameraBuiltSitesSet = new Set<string>();
|
||||||
const alarmBuiltSitesSet = new Set<string>();
|
const alarmBuiltSitesSet = new Set<string>();
|
||||||
const siteCodeToCamerasMap = new Map<string, VimpChannel[]>();
|
const siteCodeToCamerasMap = new Map<string, VimpChannel[]>();
|
||||||
@@ -105,6 +120,13 @@ export const useDeviceCenterQuery = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. 站点数组排序:稳定线路面板顺序和站点节点顺序
|
||||||
|
sortSitesByCode(cameraSites);
|
||||||
|
sortSitesByCode(alarmSites);
|
||||||
|
// 2. 每站通道数组排序:稳定区域节点顺序和通道节点顺序
|
||||||
|
sortChannelsMapByCode(siteCodeToCamerasMap);
|
||||||
|
sortChannelsMapByCode(siteCodeToAlarmsMap);
|
||||||
|
|
||||||
cameraStore.buildLineTabPanes({
|
cameraStore.buildLineTabPanes({
|
||||||
sites: cameraSites,
|
sites: cameraSites,
|
||||||
siteCodeToCamerasMap: siteCodeToCamerasMap,
|
siteCodeToCamerasMap: siteCodeToCamerasMap,
|
||||||
@@ -112,17 +134,16 @@ export const useDeviceCenterQuery = () => {
|
|||||||
codeSites,
|
codeSites,
|
||||||
compiledCodeAreas,
|
compiledCodeAreas,
|
||||||
});
|
});
|
||||||
|
cameraStore.buildCameraRecord(siteCodeToCamerasMap);
|
||||||
|
|
||||||
alarmStore.buildLineTabPanes({
|
alarmStore.buildLineTabPanes({
|
||||||
sites: alarmSites,
|
sites: alarmSites,
|
||||||
siteCodeToAlarmsMap,
|
siteCodeToAlarmsMap,
|
||||||
codeLines,
|
codeLines,
|
||||||
codeSites,
|
codeSites,
|
||||||
codeStationAreas,
|
compiledCodeAreas,
|
||||||
codeParkingAreas,
|
|
||||||
codeOccAreas,
|
|
||||||
codeTrainAreas,
|
|
||||||
});
|
});
|
||||||
|
alarmStore.buildAlarmRecord(siteCodeToAlarmsMap);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './query';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const VIMP_CHANNELS_QUERY_KEY = 'vimp-channels';
|
||||||
@@ -1,45 +1,53 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { VimpChannel, VimpStation } from '../apis';
|
import type { VimpChannel, VimpSite } from '../apis';
|
||||||
import { h, shallowRef } from 'vue';
|
import { shallowRef } from 'vue';
|
||||||
import type { AlarmMainAreaNodeOption, AlarmNodeOption, CodeArea, CodeLines, CodeSites, AlarmLineTabPane, AlarmSiteNodeOption, AlarmSubAreaNodeOption } from '../types';
|
import type { AlarmMainAreaNodeOption, AlarmNodeOption, CodeLines, CodeSites, AlarmLineTabPane, AlarmSiteNodeOption, AlarmSubAreaNodeOption, CompiledCodeAreas } from '../types';
|
||||||
import { NIcon } from 'naive-ui';
|
|
||||||
import { SirenIcon } from 'lucide-vue-next';
|
|
||||||
|
|
||||||
interface BuildLineTabPanesParams {
|
interface BuildLineTabPanesParams {
|
||||||
sites: VimpStation[];
|
sites: VimpSite[];
|
||||||
siteCodeToAlarmsMap: Map<string, VimpChannel[]>;
|
siteCodeToAlarmsMap: Map<string, VimpChannel[]>;
|
||||||
codeLines: CodeLines;
|
codeLines: CodeLines;
|
||||||
codeSites: CodeSites;
|
codeSites: CodeSites;
|
||||||
codeStationAreas: CodeArea[];
|
compiledCodeAreas: CompiledCodeAreas;
|
||||||
codeParkingAreas: CodeArea[];
|
|
||||||
codeOccAreas: CodeArea[];
|
|
||||||
codeTrainAreas: CodeArea[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildMainAreaNodeKey = (siteCode: string, mainAreaCode: string) => `${siteCode}${mainAreaCode}`;
|
||||||
|
const buildSubAreaNodeKey = (siteCode: string, areaCode: string) => `${siteCode}${areaCode}`;
|
||||||
|
|
||||||
export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
||||||
const lineTabPanes = shallowRef<AlarmLineTabPane[]>([]);
|
const lineTabPanes = shallowRef<AlarmLineTabPane[]>([]);
|
||||||
|
const alarmRecord = shallowRef<Record<string, VimpChannel>>({});
|
||||||
|
|
||||||
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
||||||
const { sites, siteCodeToAlarmsMap, codeLines, codeSites, codeStationAreas, codeParkingAreas, codeOccAreas, codeTrainAreas } = params;
|
const { sites, siteCodeToAlarmsMap, codeLines, codeSites, compiledCodeAreas } = params;
|
||||||
|
|
||||||
// 线路TabPane
|
const result: AlarmLineTabPane[] = [];
|
||||||
const _lineTabPanes: AlarmLineTabPane[] = [];
|
|
||||||
|
// 1. 线路索引 lineCode -> AlarmLineTabPane
|
||||||
|
const linePaneMap = new Map<string, AlarmLineTabPane>();
|
||||||
|
|
||||||
// 遍历所有站点
|
// 遍历所有站点
|
||||||
for (const site of sites) {
|
for (const site of sites) {
|
||||||
|
// 2. 站点节点 siteNode 只在当前轮次中顺序创建,不需要建立索引
|
||||||
|
|
||||||
const lineCode = site.code.substring(0, 3);
|
const lineCode = site.code.substring(0, 3);
|
||||||
const lineName = codeLines[lineCode]?.name ?? '';
|
const lineName = codeLines[lineCode]?.name ?? '';
|
||||||
if (!_lineTabPanes.some((lineNode) => lineNode.lineCode === lineCode)) {
|
|
||||||
_lineTabPanes.push({
|
let linePane = linePaneMap.get(lineCode);
|
||||||
lineCode,
|
if (!linePane) {
|
||||||
lineName,
|
linePane = { lineCode, lineName, alarmTree: [] };
|
||||||
alarmTree: [],
|
linePaneMap.set(lineCode, linePane);
|
||||||
});
|
result.push(linePane);
|
||||||
}
|
}
|
||||||
|
|
||||||
const siteCode = site.code;
|
const siteCode = site.code;
|
||||||
const siteName = codeSites[siteCode]?.name;
|
const siteMeta = codeSites[siteCode];
|
||||||
if (!siteName) continue;
|
if (!siteMeta) continue;
|
||||||
|
const siteName = siteMeta.name;
|
||||||
|
const siteType = siteMeta.type;
|
||||||
|
|
||||||
|
const compiledCodeAreaMaps = compiledCodeAreas[siteType];
|
||||||
|
const mainAreaCodeLength = siteType === 'train' ? 3 : 2;
|
||||||
|
|
||||||
// 构造站点节点
|
// 构造站点节点
|
||||||
const siteNode: AlarmSiteNodeOption = {
|
const siteNode: AlarmSiteNodeOption = {
|
||||||
@@ -49,79 +57,76 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
online: site.online,
|
online: site.online,
|
||||||
};
|
};
|
||||||
_lineTabPanes.find((lineTabPane) => lineTabPane.lineCode === lineCode)?.alarmTree.push(siteNode);
|
linePane.alarmTree.push(siteNode);
|
||||||
|
|
||||||
// 获取所有警报器
|
// 获取所有警报器
|
||||||
const alarms = siteCodeToAlarmsMap.get(siteCode);
|
const alarms = siteCodeToAlarmsMap.get(siteCode);
|
||||||
if (!alarms || alarms.length === 0) continue;
|
if (!alarms) continue;
|
||||||
|
|
||||||
|
// 3. 1级区域索引 mainAreaNodeKey -> AlarmMainAreaNodeOption
|
||||||
|
// mainAreaNodeKey = ${siteCode}${alarmMainAreaCode}
|
||||||
|
const mainAreaNodeMap = new Map<string, AlarmMainAreaNodeOption>();
|
||||||
|
// 4. 2级区域索引 subAreaNodeKey -> AlarmSubAreaNodeOption
|
||||||
|
// subAreaNodeKey = ${siteCode}${alarmAreaCode}
|
||||||
|
const subAreaNodeMap = new Map<string, AlarmSubAreaNodeOption>();
|
||||||
|
// 5. 警报器索引 subAreaNodeKey -> Set<AlarmGbCode>
|
||||||
|
const subAreaNodeKeyToAlarmGbCodeSetMap = new Map<string, Set<string>>();
|
||||||
|
|
||||||
// 遍历警报器
|
// 遍历警报器
|
||||||
for (const alarm of alarms) {
|
for (const alarm of alarms) {
|
||||||
// 计算相关编码
|
// 计算相关编码
|
||||||
const { code: alarmGbCode, name: alarmName } = alarm;
|
const { code: alarmGbCode, name: alarmName } = alarm;
|
||||||
const alarmSiteCode = alarmGbCode.substring(0, 6);
|
|
||||||
const alarmSiteType = codeSites[alarmSiteCode]?.type;
|
|
||||||
const alarmAreaCode = alarmGbCode.substring(6, 11);
|
const alarmAreaCode = alarmGbCode.substring(6, 11);
|
||||||
const alarmMainAreaCode = alarmAreaCode.slice(0, alarmSiteType === 'train' ? 3 : 2);
|
const alarmMainAreaCode = alarmAreaCode.slice(0, mainAreaCodeLength);
|
||||||
|
|
||||||
// 构造车站/基地/OCC/车次区域
|
// 查找1级区域,如果未找到则跳过该警报器
|
||||||
let siteArea: CodeArea | undefined = undefined;
|
const mainArea = compiledCodeAreaMaps.mainAreaMap.get(alarmMainAreaCode);
|
||||||
if (alarmSiteType === 'station') {
|
if (!mainArea) continue;
|
||||||
siteArea = codeStationAreas.find((area) => area.code === alarmMainAreaCode);
|
|
||||||
} else if (alarmSiteType === 'parking') {
|
|
||||||
siteArea = codeParkingAreas.find((area) => area.code === alarmMainAreaCode);
|
|
||||||
} else if (alarmSiteType === 'occ') {
|
|
||||||
siteArea = codeOccAreas.find((area) => area.code === alarmMainAreaCode);
|
|
||||||
} else if (alarmSiteType === 'train') {
|
|
||||||
siteArea = codeTrainAreas.find((area) => area.code === alarmMainAreaCode);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!siteArea) continue; // 如果还是未找到区域,则跳过该警报器
|
|
||||||
|
|
||||||
// 构造1级区域节点
|
// 尝试从索引中获取1级区域节点,若不存在则创建
|
||||||
if (!siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`)) {
|
const mainAreaNodeKey = buildMainAreaNodeKey(siteCode, alarmMainAreaCode);
|
||||||
const mainAreaNode: AlarmMainAreaNodeOption = {
|
let mainAreaNode = mainAreaNodeMap.get(mainAreaNodeKey);
|
||||||
key: `${alarmSiteCode}${alarmMainAreaCode}`,
|
if (!mainAreaNode) {
|
||||||
label: siteArea.name,
|
mainAreaNode = {
|
||||||
|
key: mainAreaNodeKey,
|
||||||
|
label: mainArea.name,
|
||||||
children: [],
|
children: [],
|
||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
site: site,
|
||||||
|
areaLevel: 1,
|
||||||
};
|
};
|
||||||
|
mainAreaNodeMap.set(mainAreaNodeKey, mainAreaNode);
|
||||||
siteNode.children?.push(mainAreaNode);
|
siteNode.children?.push(mainAreaNode);
|
||||||
}
|
}
|
||||||
const targetMainAreaNode = siteNode.children?.find((areaNode) => areaNode.key === `${alarmSiteCode}${alarmMainAreaCode}`);
|
|
||||||
if (!targetMainAreaNode) continue; // 如果1级区域节点不存在,则跳过该警报器
|
|
||||||
|
|
||||||
// 构造2级区域节点
|
// 查找2级区域,如果未找到则跳过该警报器
|
||||||
if (!targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`)) {
|
const subArea = compiledCodeAreaMaps.subAreaMap.get(alarmAreaCode);
|
||||||
let subArea: CodeArea['subs'][number] | undefined = undefined;
|
if (!subArea) continue;
|
||||||
if (alarmSiteType === 'station') {
|
|
||||||
subArea = codeStationAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
|
||||||
} else if (alarmSiteType === 'parking') {
|
|
||||||
subArea = codeParkingAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
|
||||||
} else if (alarmSiteType === 'occ') {
|
|
||||||
subArea = codeOccAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
|
||||||
} else if (alarmSiteType === 'train') {
|
|
||||||
subArea = codeTrainAreas.find((area) => area.code === alarmMainAreaCode)?.subs.find((subArea) => subArea.code === alarmAreaCode);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!subArea) continue; // 如果还是未找到2级区域,则跳过该警报器
|
|
||||||
|
|
||||||
const subAreaNode: AlarmSubAreaNodeOption = {
|
// 尝试从索引中获取2级区域节点,若不存在则创建
|
||||||
key: `${alarmSiteCode}${alarmAreaCode}`,
|
const subAreaNodeKey = buildSubAreaNodeKey(siteCode, alarmAreaCode);
|
||||||
|
let subAreaNode = subAreaNodeMap.get(subAreaNodeKey);
|
||||||
|
if (!subAreaNode) {
|
||||||
|
subAreaNode = {
|
||||||
|
key: subAreaNodeKey,
|
||||||
label: subArea.name,
|
label: subArea.name,
|
||||||
children: [],
|
children: [],
|
||||||
stats: { online: 0, offline: 0, total: 0 },
|
stats: { online: 0, offline: 0, total: 0 },
|
||||||
site: site,
|
site: site,
|
||||||
|
areaLevel: 2,
|
||||||
};
|
};
|
||||||
targetMainAreaNode.children?.push(subAreaNode);
|
subAreaNodeMap.set(subAreaNodeKey, subAreaNode);
|
||||||
|
mainAreaNode.children?.push(subAreaNode);
|
||||||
}
|
}
|
||||||
const subAreaNode = targetMainAreaNode.children?.find((subAreaNode) => subAreaNode.key === `${alarmSiteCode}${alarmAreaCode}`);
|
|
||||||
if (!subAreaNode) continue; // 如果2级区域节点不存在,则跳过该警报器
|
|
||||||
|
|
||||||
// 构造警报器节点
|
// 构造警报器节点
|
||||||
|
let alarmGbCodeSet = subAreaNodeKeyToAlarmGbCodeSetMap.get(subAreaNodeKey);
|
||||||
|
if (!alarmGbCodeSet) {
|
||||||
|
alarmGbCodeSet = new Set<string>();
|
||||||
|
subAreaNodeKeyToAlarmGbCodeSetMap.set(subAreaNodeKey, alarmGbCodeSet);
|
||||||
|
}
|
||||||
|
if (alarmGbCodeSet.has(alarmGbCode)) continue;
|
||||||
|
alarmGbCodeSet.add(alarmGbCode);
|
||||||
const alarmType = alarm.code.substring(11, 14);
|
const alarmType = alarm.code.substring(11, 14);
|
||||||
const alarmNode: AlarmNodeOption = {
|
const alarmNode: AlarmNodeOption = {
|
||||||
key: alarmGbCode,
|
key: alarmGbCode,
|
||||||
@@ -129,53 +134,42 @@ export const useAlarmStore = defineStore('vimp-alarm-store', () => {
|
|||||||
type: alarmType,
|
type: alarmType,
|
||||||
alarm: alarm,
|
alarm: alarm,
|
||||||
site: site,
|
site: site,
|
||||||
prefix: () => {
|
|
||||||
return h(NIcon, () => h(SirenIcon));
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
subAreaNode.children?.push(alarmNode);
|
||||||
// 添加警报器节点到子区域节点
|
|
||||||
if (!subAreaNode.children?.find((alarmNode) => alarmNode.key === alarmGbCode)) {
|
|
||||||
subAreaNode.children?.push(alarmNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 统计站点、区域、子区域的在线/离线/总警报器数量
|
// 统计站点、区域、子区域的在线/离线/总警报器数量
|
||||||
siteNode.stats.total++;
|
siteNode.stats.total++;
|
||||||
targetMainAreaNode.stats.total++;
|
mainAreaNode.stats.total++;
|
||||||
subAreaNode.stats.total++;
|
subAreaNode.stats.total++;
|
||||||
if (alarm.status === 1) {
|
if (alarm.status === 1) {
|
||||||
siteNode.stats.online++;
|
siteNode.stats.online++;
|
||||||
targetMainAreaNode.stats.online++;
|
mainAreaNode.stats.online++;
|
||||||
subAreaNode.stats.online++;
|
subAreaNode.stats.online++;
|
||||||
}
|
} else if (alarm.status === 0) {
|
||||||
if (alarm.status === 0) {
|
|
||||||
siteNode.stats.offline++;
|
siteNode.stats.offline++;
|
||||||
targetMainAreaNode.stats.offline++;
|
mainAreaNode.stats.offline++;
|
||||||
subAreaNode.stats.offline++;
|
subAreaNode.stats.offline++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
siteNode.suffix = () => {
|
|
||||||
const { online, offline, total } = siteNode.stats;
|
|
||||||
return `(${online}/${offline}/${total})`;
|
|
||||||
};
|
|
||||||
siteNode.children?.forEach((areaNode) => {
|
|
||||||
areaNode.suffix = () => {
|
|
||||||
const { online, offline, total } = areaNode.stats;
|
|
||||||
return h('div', { style: { marginRight: '8px', opacity: 0.6 } }, `(${online}/${offline}/${total})`);
|
|
||||||
};
|
|
||||||
areaNode.children?.forEach((subAreaNode) => {
|
|
||||||
subAreaNode.suffix = () => {
|
|
||||||
const { online, offline, total } = subAreaNode.stats;
|
|
||||||
return h('div', { style: { marginRight: '16px', opacity: 0.4 } }, `(${online}/${offline}/${total})`);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
lineTabPanes.value = _lineTabPanes;
|
lineTabPanes.value = result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildAlarmRecord = (siteCodeToAlarmsMap: Map<string, VimpChannel[]>) => {
|
||||||
|
const record: Record<string, VimpChannel> = {};
|
||||||
|
for (const [, alarms] of siteCodeToAlarmsMap) {
|
||||||
|
for (const alarm of alarms) {
|
||||||
|
record[alarm.code] = alarm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alarmRecord.value = record;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lineTabPanes,
|
lineTabPanes,
|
||||||
|
alarmRecord,
|
||||||
|
|
||||||
buildLineTabPanes,
|
buildLineTabPanes,
|
||||||
|
buildAlarmRecord,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { VimpChannel, VimpStation } from '../apis';
|
import type { VimpChannel, VimpSite } from '../apis';
|
||||||
import { shallowRef } from 'vue';
|
import { ref, shallowRef } from 'vue';
|
||||||
import type { CameraMainAreaNodeOption, CameraNodeOption, CodeLines, CodeSites, CameraLineTabPane, CameraSiteNodeOption, CameraSubAreaNodeOption, CompiledCodeAreas } from '../types';
|
import type { CameraMainAreaNodeOption, CameraNodeOption, CodeLines, CodeSites, CameraLineTabPane, CameraSiteNodeOption, CameraSubAreaNodeOption, CompiledCodeAreas } from '../types';
|
||||||
|
|
||||||
interface BuildLineTabPanesParams {
|
interface BuildLineTabPanesParams {
|
||||||
sites: VimpStation[];
|
sites: VimpSite[];
|
||||||
siteCodeToCamerasMap: Map<string, VimpChannel[]>;
|
siteCodeToCamerasMap: Map<string, VimpChannel[]>;
|
||||||
codeLines: CodeLines;
|
codeLines: CodeLines;
|
||||||
codeSites: CodeSites;
|
codeSites: CodeSites;
|
||||||
@@ -16,6 +16,7 @@ const buildSubAreaNodeKey = (siteCode: string, areaCode: string) => `${siteCode}
|
|||||||
|
|
||||||
export const useCameraStore = defineStore('vimp-camera-store', () => {
|
export const useCameraStore = defineStore('vimp-camera-store', () => {
|
||||||
const lineTabPanes = shallowRef<CameraLineTabPane[]>([]);
|
const lineTabPanes = shallowRef<CameraLineTabPane[]>([]);
|
||||||
|
const cameraRecord = shallowRef<Record<string, VimpChannel>>({});
|
||||||
|
|
||||||
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
const buildLineTabPanes = (params: BuildLineTabPanesParams) => {
|
||||||
const { sites, siteCodeToCamerasMap, codeLines, codeSites, compiledCodeAreas } = params;
|
const { sites, siteCodeToCamerasMap, codeLines, codeSites, compiledCodeAreas } = params;
|
||||||
@@ -153,8 +154,21 @@ export const useCameraStore = defineStore('vimp-camera-store', () => {
|
|||||||
lineTabPanes.value = result;
|
lineTabPanes.value = result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildCameraRecord = (siteCodeToCamerasMap: Map<string, VimpChannel[]>) => {
|
||||||
|
const record: Record<string, VimpChannel> = {};
|
||||||
|
for (const [, cameras] of siteCodeToCamerasMap) {
|
||||||
|
for (const camera of cameras) {
|
||||||
|
record[camera.code] = camera;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cameraRecord.value = record;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lineTabPanes,
|
lineTabPanes,
|
||||||
|
cameraRecord,
|
||||||
|
|
||||||
buildLineTabPanes,
|
buildLineTabPanes,
|
||||||
|
buildCameraRecord,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TabPaneProps, TreeOption } from 'naive-ui';
|
import type { TabPaneProps, TreeOption } from 'naive-ui';
|
||||||
import type { VimpChannel, VimpStation } from '../apis/model';
|
import type { VimpChannel, VimpSite } from '../apis/model';
|
||||||
|
|
||||||
export type SiteType = 'station' | 'parking' | 'occ' | 'train';
|
export type SiteType = 'station' | 'parking' | 'occ' | 'train';
|
||||||
export type CodeLines = Record<string, { name: string; color: string }>;
|
export type CodeLines = Record<string, { name: string; color: string }>;
|
||||||
@@ -57,20 +57,20 @@ export interface CountStats {
|
|||||||
export interface CameraNodeOption extends TreeOption {
|
export interface CameraNodeOption extends TreeOption {
|
||||||
camera: VimpChannel;
|
camera: VimpChannel;
|
||||||
type: string;
|
type: string;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CameraSubAreaNodeOption extends TreeOption {
|
export interface CameraSubAreaNodeOption extends TreeOption {
|
||||||
children?: CameraNodeOption[];
|
children?: CameraNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
areaLevel: 2;
|
areaLevel: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CameraMainAreaNodeOption extends TreeOption {
|
export interface CameraMainAreaNodeOption extends TreeOption {
|
||||||
children?: CameraSubAreaNodeOption[];
|
children?: CameraSubAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
areaLevel: 1;
|
areaLevel: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,19 +104,21 @@ export interface CameraLineTabPane extends TabPaneProps {
|
|||||||
export interface AlarmNodeOption extends TreeOption {
|
export interface AlarmNodeOption extends TreeOption {
|
||||||
alarm: VimpChannel;
|
alarm: VimpChannel;
|
||||||
type: string;
|
type: string;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlarmSubAreaNodeOption extends TreeOption {
|
export interface AlarmSubAreaNodeOption extends TreeOption {
|
||||||
children?: AlarmNodeOption[];
|
children?: AlarmNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
|
areaLevel: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlarmMainAreaNodeOption extends TreeOption {
|
export interface AlarmMainAreaNodeOption extends TreeOption {
|
||||||
children?: AlarmSubAreaNodeOption[];
|
children?: AlarmSubAreaNodeOption[];
|
||||||
stats: CountStats;
|
stats: CountStats;
|
||||||
site: VimpStation;
|
site: VimpSite;
|
||||||
|
areaLevel: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlarmSiteNodeOption extends TreeOption {
|
export interface AlarmSiteNodeOption extends TreeOption {
|
||||||
|
|||||||
Reference in New Issue
Block a user