refactor: extract interface LineDevices
This commit is contained in:
@@ -24,17 +24,10 @@ import type {
|
|||||||
NdmSwitchResultVO,
|
NdmSwitchResultVO,
|
||||||
NdmVideoServerResultVO,
|
NdmVideoServerResultVO,
|
||||||
} from '@/apis/models/device';
|
} from '@/apis/models/device';
|
||||||
|
import type { Station } from '@/apis/domains';
|
||||||
|
|
||||||
// 定义设备数据类型
|
// 定义设备数据类型
|
||||||
interface StationDevices {
|
export interface StationDevices {
|
||||||
// ndmCameraList: any[];
|
|
||||||
// ndmDecoderList: any[];
|
|
||||||
// ndmKeyboardList: any[];
|
|
||||||
// ndmMedisServerList: any[];
|
|
||||||
// ndmNvrList: any[];
|
|
||||||
// ndmSecurityBoxList: any[];
|
|
||||||
// ndmSwitchList: any[];
|
|
||||||
// ndmVideoServerList: any[];
|
|
||||||
[DeviceType.Camera]: NdmCameraResultVO[];
|
[DeviceType.Camera]: NdmCameraResultVO[];
|
||||||
[DeviceType.Decoder]: NdmDecoderResultVO[];
|
[DeviceType.Decoder]: NdmDecoderResultVO[];
|
||||||
[DeviceType.Keyboard]: NdmKeyboardResultVO[];
|
[DeviceType.Keyboard]: NdmKeyboardResultVO[];
|
||||||
@@ -45,6 +38,10 @@ interface StationDevices {
|
|||||||
[DeviceType.VideoServer]: NdmVideoServerResultVO[];
|
[DeviceType.VideoServer]: NdmVideoServerResultVO[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LineDevices {
|
||||||
|
[stationCode: Station['code']]: StationDevices;
|
||||||
|
}
|
||||||
|
|
||||||
export function useLineDevicesQuery() {
|
export function useLineDevicesQuery() {
|
||||||
const stationStore = useStationStore();
|
const stationStore = useStationStore();
|
||||||
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
||||||
@@ -53,10 +50,10 @@ export function useLineDevicesQuery() {
|
|||||||
queryKey: ['line-devices', updatedTime],
|
queryKey: ['line-devices', updatedTime],
|
||||||
enabled: computed(() => onlineStationList.value.length > 0),
|
enabled: computed(() => onlineStationList.value.length > 0),
|
||||||
placeholderData: (prev) => prev,
|
placeholderData: (prev) => prev,
|
||||||
queryFn: async (): Promise<Record<string, StationDevices>> => {
|
queryFn: async (): Promise<LineDevices> => {
|
||||||
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
||||||
|
|
||||||
const lineDevices: Record<string, StationDevices> = {};
|
const lineDevices: LineDevices = {};
|
||||||
|
|
||||||
// 如果没有车站列表,返回空对象
|
// 如果没有车站列表,返回空对象
|
||||||
if (!stationList?.value) {
|
if (!stationList?.value) {
|
||||||
@@ -68,14 +65,6 @@ export function useLineDevicesQuery() {
|
|||||||
// 如果车站离线,设置空数组
|
// 如果车站离线,设置空数组
|
||||||
if (!station.online) {
|
if (!station.online) {
|
||||||
lineDevices[station.code] = {
|
lineDevices[station.code] = {
|
||||||
// ndmCameraList: [],
|
|
||||||
// ndmDecoderList: [],
|
|
||||||
// ndmKeyboardList: [],
|
|
||||||
// ndmMedisServerList: [],
|
|
||||||
// ndmNvrList: [],
|
|
||||||
// ndmSecurityBoxList: [],
|
|
||||||
// ndmSwitchList: [],
|
|
||||||
// ndmVideoServerList: [],
|
|
||||||
[DeviceType.Camera]: [],
|
[DeviceType.Camera]: [],
|
||||||
[DeviceType.Decoder]: [],
|
[DeviceType.Decoder]: [],
|
||||||
[DeviceType.Keyboard]: [],
|
[DeviceType.Keyboard]: [],
|
||||||
@@ -103,14 +92,6 @@ export function useLineDevicesQuery() {
|
|||||||
|
|
||||||
// 存储该车站的设备数据
|
// 存储该车站的设备数据
|
||||||
lineDevices[station.code] = {
|
lineDevices[station.code] = {
|
||||||
// ndmCameraList: cameraData.records ?? [],
|
|
||||||
// ndmDecoderList: decoderData.records ?? [],
|
|
||||||
// ndmKeyboardList: keyboardData.records ?? [],
|
|
||||||
// ndmMedisServerList: mediaServerData.records ?? [],
|
|
||||||
// ndmNvrList: nvrData.records ?? [],
|
|
||||||
// ndmSecurityBoxList: securityBoxData.records ?? [],
|
|
||||||
// ndmSwitchList: switchData.records ?? [],
|
|
||||||
// ndmVideoServerList: videoServerData.records ?? [],
|
|
||||||
[DeviceType.Camera]: cameraData.records ?? [],
|
[DeviceType.Camera]: cameraData.records ?? [],
|
||||||
[DeviceType.Decoder]: decoderData.records ?? [],
|
[DeviceType.Decoder]: decoderData.records ?? [],
|
||||||
[DeviceType.Keyboard]: keyboardData.records ?? [],
|
[DeviceType.Keyboard]: keyboardData.records ?? [],
|
||||||
@@ -124,14 +105,6 @@ export function useLineDevicesQuery() {
|
|||||||
console.error(`获取车站 ${station.name} 设备数据失败:`, error);
|
console.error(`获取车站 ${station.name} 设备数据失败:`, error);
|
||||||
// 如果获取失败,设置空数组
|
// 如果获取失败,设置空数组
|
||||||
lineDevices[station.code] = {
|
lineDevices[station.code] = {
|
||||||
// ndmCameraList: [],
|
|
||||||
// ndmDecoderList: [],
|
|
||||||
// ndmKeyboardList: [],
|
|
||||||
// ndmMedisServerList: [],
|
|
||||||
// ndmNvrList: [],
|
|
||||||
// ndmSecurityBoxList: [],
|
|
||||||
// ndmSwitchList: [],
|
|
||||||
// ndmVideoServerList: [],
|
|
||||||
[DeviceType.Camera]: [],
|
[DeviceType.Camera]: [],
|
||||||
[DeviceType.Decoder]: [],
|
[DeviceType.Decoder]: [],
|
||||||
[DeviceType.Keyboard]: [],
|
[DeviceType.Keyboard]: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user