From 104400500e136ee4ca417cf226adf5371f6ff908 Mon Sep 17 00:00:00 2001 From: yangsy Date: Mon, 18 Aug 2025 11:01:09 +0800 Subject: [PATCH] refactor: extract interface LineDevices --- .../query/use-line-devices-query.ts | 43 ++++--------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/composables/query/use-line-devices-query.ts b/src/composables/query/use-line-devices-query.ts index a2e6df3..295b0cf 100644 --- a/src/composables/query/use-line-devices-query.ts +++ b/src/composables/query/use-line-devices-query.ts @@ -24,17 +24,10 @@ import type { NdmSwitchResultVO, NdmVideoServerResultVO, } from '@/apis/models/device'; +import type { Station } from '@/apis/domains'; // 定义设备数据类型 -interface StationDevices { - // ndmCameraList: any[]; - // ndmDecoderList: any[]; - // ndmKeyboardList: any[]; - // ndmMedisServerList: any[]; - // ndmNvrList: any[]; - // ndmSecurityBoxList: any[]; - // ndmSwitchList: any[]; - // ndmVideoServerList: any[]; +export interface StationDevices { [DeviceType.Camera]: NdmCameraResultVO[]; [DeviceType.Decoder]: NdmDecoderResultVO[]; [DeviceType.Keyboard]: NdmKeyboardResultVO[]; @@ -45,6 +38,10 @@ interface StationDevices { [DeviceType.VideoServer]: NdmVideoServerResultVO[]; } +export interface LineDevices { + [stationCode: Station['code']]: StationDevices; +} + export function useLineDevicesQuery() { const stationStore = useStationStore(); const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore); @@ -53,10 +50,10 @@ export function useLineDevicesQuery() { queryKey: ['line-devices', updatedTime], enabled: computed(() => onlineStationList.value.length > 0), placeholderData: (prev) => prev, - queryFn: async (): Promise> => { + queryFn: async (): Promise => { const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' }; - const lineDevices: Record = {}; + const lineDevices: LineDevices = {}; // 如果没有车站列表,返回空对象 if (!stationList?.value) { @@ -68,14 +65,6 @@ export function useLineDevicesQuery() { // 如果车站离线,设置空数组 if (!station.online) { lineDevices[station.code] = { - // ndmCameraList: [], - // ndmDecoderList: [], - // ndmKeyboardList: [], - // ndmMedisServerList: [], - // ndmNvrList: [], - // ndmSecurityBoxList: [], - // ndmSwitchList: [], - // ndmVideoServerList: [], [DeviceType.Camera]: [], [DeviceType.Decoder]: [], [DeviceType.Keyboard]: [], @@ -103,14 +92,6 @@ export function useLineDevicesQuery() { // 存储该车站的设备数据 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.Decoder]: decoderData.records ?? [], [DeviceType.Keyboard]: keyboardData.records ?? [], @@ -124,14 +105,6 @@ export function useLineDevicesQuery() { console.error(`获取车站 ${station.name} 设备数据失败:`, error); // 如果获取失败,设置空数组 lineDevices[station.code] = { - // ndmCameraList: [], - // ndmDecoderList: [], - // ndmKeyboardList: [], - // ndmMedisServerList: [], - // ndmNvrList: [], - // ndmSecurityBoxList: [], - // ndmSwitchList: [], - // ndmVideoServerList: [], [DeviceType.Camera]: [], [DeviceType.Decoder]: [], [DeviceType.Keyboard]: [],