refactor: remove unused queries

This commit is contained in:
yangsy
2025-08-27 14:31:14 +08:00
parent b4e49c0104
commit 5cc4b2f537
5 changed files with 0 additions and 192 deletions

View File

@@ -1,4 +1,3 @@
export * from './domains';
export * from './use-line-devices-query';
export * from './use-station-devices-query';

View File

@@ -1,79 +0,0 @@
import type { Station } from '@/apis/domains';
import type { PageParams } from '@/apis/models';
import { postNdmCameraPage, postNdmDecoderPage, postNdmKeyboardPage, postNdmMediaServerPage, postNdmNvrPage, postNdmSecurityBoxPage, postNdmSwitchPage, postNdmVideoServerPage } from '@/apis/requests';
import { DeviceType } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
import { useStationStore } from '@/stores/station';
import { useQuery } from '@tanstack/vue-query';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import type { StationDevices } from './domains';
const createEmptyStationDevices = (): StationDevices => {
return {
[DeviceType.Camera]: [],
[DeviceType.Decoder]: [],
[DeviceType.Keyboard]: [],
[DeviceType.MediaServer]: [],
[DeviceType.Nvr]: [],
[DeviceType.SecurityBox]: [],
[DeviceType.Switch]: [],
[DeviceType.VideoServer]: [],
};
};
export function useStationDevicesQuery(stationCode: Station['code']) {
const stationStore = useStationStore();
const { onlineStationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore();
const { pollingEnabled } = storeToRefs(queryControlStore);
const isOnline = computed(() => onlineStationList.value.some((s) => s.code === stationCode));
return useQuery({
queryKey: ['station-devices', stationCode],
enabled: computed(() => isOnline.value && pollingEnabled.value),
staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
queryFn: async ({ signal }): Promise<StationDevices> => {
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
// 如果车站离线,返回空数据
if (!isOnline.value) {
return createEmptyStationDevices();
}
try {
const [cameraData, decoderData, keyboardData, mediaServerData, nvrData, securityBoxData, switchData, videoServerData] = await Promise.all([
postNdmCameraPage(stationCode, pageQuery, signal),
postNdmDecoderPage(stationCode, pageQuery, signal),
postNdmKeyboardPage(stationCode, pageQuery, signal),
postNdmMediaServerPage(stationCode, pageQuery, signal),
postNdmNvrPage(stationCode, pageQuery, signal),
postNdmSecurityBoxPage(stationCode, pageQuery, signal),
postNdmSwitchPage(stationCode, pageQuery, signal),
postNdmVideoServerPage(stationCode, pageQuery, signal),
]);
return {
[DeviceType.Camera]: cameraData.records ?? [],
[DeviceType.Decoder]: decoderData.records ?? [],
[DeviceType.Keyboard]: keyboardData.records ?? [],
[DeviceType.MediaServer]: mediaServerData.records ?? [],
[DeviceType.Nvr]: nvrData.records ?? [],
[DeviceType.SecurityBox]: securityBoxData.records ?? [],
[DeviceType.Switch]: switchData.records ?? [],
[DeviceType.VideoServer]: videoServerData.records ?? [],
};
} catch (error) {
console.error(`获取车站 ${stationCode} 设备数据失败:`, error);
// 如果获取失败,返回空数据
return createEmptyStationDevices();
}
},
placeholderData: (prev) => prev,
});
}