refactor: remove unused queries
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
export * from './domains';
|
||||
|
||||
export * from './use-line-alarms-query';
|
||||
export * from './use-station-alarms-query';
|
||||
export * from './use-today-alarms-query';
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import type { Station } from '@/apis/domains';
|
||||
import { postNdmDeviceAlarmLogPage } 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 dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import type { StationAlarms } from './domains';
|
||||
|
||||
const createEmptyStationAlarms = (): StationAlarms => ({
|
||||
[DeviceType.Camera]: [],
|
||||
[DeviceType.Decoder]: [],
|
||||
[DeviceType.Keyboard]: [],
|
||||
[DeviceType.MediaServer]: [],
|
||||
[DeviceType.Nvr]: [],
|
||||
[DeviceType.SecurityBox]: [],
|
||||
[DeviceType.Switch]: [],
|
||||
[DeviceType.VideoServer]: [],
|
||||
unclassified: [],
|
||||
});
|
||||
|
||||
export function useStationAlarmsQuery(stationCode: Station['code']) {
|
||||
const stationStore = useStationStore();
|
||||
const { onlineStationList } = storeToRefs(stationStore);
|
||||
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { pollingEnabled } = storeToRefs(queryControlStore);
|
||||
|
||||
const isOnline = computed(() => onlineStationList.value.some((stn) => stn.code === stationCode));
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['station-alarms', stationCode],
|
||||
enabled: computed(() => isOnline.value && pollingEnabled.value),
|
||||
staleTime: Infinity,
|
||||
refetchOnMount: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnWindowFocus: false,
|
||||
queryFn: async ({ signal }): Promise<StationAlarms> => {
|
||||
// 如果车站离线,返回空数据
|
||||
if (!isOnline.value) {
|
||||
return createEmptyStationAlarms();
|
||||
}
|
||||
|
||||
try {
|
||||
const now = dayjs();
|
||||
const todayStart = now.startOf('date').valueOf();
|
||||
const todayEnd = now.endOf('date').valueOf();
|
||||
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(
|
||||
stationCode,
|
||||
{
|
||||
model: {},
|
||||
extra: {
|
||||
alarmDate_ge: todayStart,
|
||||
alarmDate_le: todayEnd,
|
||||
},
|
||||
size: 50000,
|
||||
current: 1,
|
||||
sort: 'id',
|
||||
order: 'descending',
|
||||
},
|
||||
signal,
|
||||
);
|
||||
|
||||
const cameraAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Camera);
|
||||
const decoderAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Decoder);
|
||||
const keyboardAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Keyboard);
|
||||
const mediaServerAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.MediaServer);
|
||||
const nvrAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Nvr);
|
||||
const securityBoxAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.SecurityBox);
|
||||
const switchAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Switch);
|
||||
const videoServerAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.VideoServer);
|
||||
|
||||
return {
|
||||
[DeviceType.Camera]: cameraAlarms,
|
||||
[DeviceType.Decoder]: decoderAlarms,
|
||||
[DeviceType.Keyboard]: keyboardAlarms,
|
||||
[DeviceType.MediaServer]: mediaServerAlarms,
|
||||
[DeviceType.Nvr]: nvrAlarms,
|
||||
[DeviceType.SecurityBox]: securityBoxAlarms,
|
||||
[DeviceType.Switch]: switchAlarms,
|
||||
[DeviceType.VideoServer]: videoServerAlarms,
|
||||
unclassified: alarmList ?? [],
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`获取车站 ${stationCode} 告警数据失败:`, error);
|
||||
// 如果获取失败,返回空数据
|
||||
return createEmptyStationAlarms();
|
||||
}
|
||||
},
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export function useTodayAlarmsQuery() {
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { globalPollingEnabled } = storeToRefs(queryControlStore);
|
||||
return useQuery({
|
||||
queryKey: ['today-alarms'],
|
||||
enabled: computed(() => globalPollingEnabled.value),
|
||||
placeholderData: (prev) => prev,
|
||||
queryFn: async () => {},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './domains';
|
||||
|
||||
export * from './use-line-devices-query';
|
||||
export * from './use-station-devices-query';
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user