cc2c83baf7
- 将站点摄像机和告警的映射存储从普通对象改为Map,提升查询性能 - 新增站点在线状态缓存和已访问站点集合,简化重复站点判断逻辑 - 移动buildTrainAreas和axios配置对象至顶层作用域 - 调整代码结构并临时注释告警存储的线路面板构建调用
102 lines
3.6 KiB
TypeScript
102 lines
3.6 KiB
TypeScript
import { useQuery } from '@tanstack/vue-query';
|
|
import { computed } from 'vue';
|
|
import type { AxiosRequestConfig } from 'axios';
|
|
import axios from 'axios';
|
|
import type { CodeArea, CodeLines, CodeSites } from '../../types';
|
|
import { useCameraStore, useAlarmStore } from '../../stores';
|
|
import { catalogAllDeviceApi, catalogChannelApi, type VimpChannel } from '../../apis';
|
|
|
|
const config: AxiosRequestConfig = {
|
|
headers: {
|
|
'Cache-Control': 'no-store',
|
|
},
|
|
};
|
|
|
|
const buildTrainAreas = () => {
|
|
const codeTrainAreas: CodeArea[] = [];
|
|
for (let i = 0; i < 999; i++) {
|
|
const codeTrain = i.toString().padStart(3, '0');
|
|
// 市域线name为车组,改造线name为车次
|
|
const area: CodeArea = { code: codeTrain, name: '车次' + codeTrain, subs: [] };
|
|
for (let j = 0; j <= 99; j++) {
|
|
const codeCarriage = j.toString().padStart(2, '0');
|
|
const subArea: CodeArea['subs'][number] = { code: codeTrain + codeCarriage, name: '车厢' + codeCarriage };
|
|
area.subs.push(subArea);
|
|
}
|
|
// const areaPreserve: CodeArea['subs'][number] = { code: codeTrain + '51', name: '预留' };
|
|
// area.subs.push(areaPreserve);
|
|
codeTrainAreas.push(area);
|
|
}
|
|
return codeTrainAreas;
|
|
};
|
|
|
|
export const useDeviceCenterQuery = () => {
|
|
const cameraStore = useCameraStore();
|
|
const alarmStore = useAlarmStore();
|
|
|
|
return useQuery({
|
|
queryKey: computed(() => ['vimp-device']),
|
|
refetchInterval: 10 * 1000,
|
|
refetchOnWindowFocus: false,
|
|
queryFn: async ({ signal }) => {
|
|
const codeLines = (await axios.get<CodeLines>('/cdn/vimp/codes/codeLines.json', config)).data;
|
|
const codeSites = (await axios.get<CodeSites>('/cdn/vimp/codes/codeStations.json', config)).data;
|
|
const codeStationAreas = (await axios.get<CodeArea[]>('/cdn/vimp/codes/codeStationAreas.json', config)).data;
|
|
const codeParkingAreas = (await axios.get<CodeArea[]>('/cdn/vimp/codes/codeParkingAreas.json', config)).data;
|
|
const codeOccAreas = (await axios.get<CodeArea[]>('/cdn/vimp/codes/codeOccAreas.json', config)).data;
|
|
const codeTrainAreas = buildTrainAreas();
|
|
|
|
const siteCamerasMapFromApi = new Map<string, VimpChannel[]>();
|
|
const siteAlarmsMapFromApi = new Map<string, VimpChannel[]>();
|
|
const sitesFromApi = await catalogAllDeviceApi({ signal });
|
|
|
|
if (!!sitesFromApi) {
|
|
for (const site of sitesFromApi) {
|
|
const channels = await catalogChannelApi(site.code, { signal });
|
|
if (!channels || channels.length === 0) continue;
|
|
|
|
const cameras: VimpChannel[] = [];
|
|
const alarms: VimpChannel[] = [];
|
|
|
|
channels.forEach((channel) => {
|
|
const typeCode = Number(channel.code.substring(11, 14));
|
|
if (typeCode >= 4 && typeCode <= 6) {
|
|
cameras.push(channel);
|
|
} else if ((typeCode >= 101 && typeCode <= 108) || (typeCode >= 810 && typeCode <= 815)) {
|
|
alarms.push(channel);
|
|
}
|
|
});
|
|
|
|
const siteCode = site.code.substring(0, 6);
|
|
siteCamerasMapFromApi.set(siteCode, cameras);
|
|
siteAlarmsMapFromApi.set(siteCode, alarms);
|
|
}
|
|
}
|
|
|
|
cameraStore.buildLineTabPanes({
|
|
sitesFromApi,
|
|
siteCamerasMapFromApi,
|
|
codeLines,
|
|
codeSites,
|
|
codeStationAreas,
|
|
codeParkingAreas,
|
|
codeOccAreas,
|
|
codeTrainAreas,
|
|
});
|
|
|
|
// alarmStore.buildLineTabPanes({
|
|
// sitesFromApi,
|
|
// siteAlarmsMapFromApi,
|
|
// codeLines,
|
|
// codeSites,
|
|
// codeStationAreas,
|
|
// codeParkingAreas,
|
|
// codeOccAreas,
|
|
// codeTrainAreas,
|
|
// });
|
|
|
|
return null;
|
|
},
|
|
});
|
|
};
|