refactor: extract interface LineDevices
This commit is contained in:
@@ -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<Record<string, StationDevices>> => {
|
||||
queryFn: async (): Promise<LineDevices> => {
|
||||
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
||||
|
||||
const lineDevices: Record<string, StationDevices> = {};
|
||||
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]: [],
|
||||
|
||||
Reference in New Issue
Block a user