fix: polling still running when modal open

This commit is contained in:
yangsy
2025-08-25 11:08:59 +08:00
parent 560ed3bad2
commit dea621a7a2
2 changed files with 16 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ import type {
} 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';
@@ -36,12 +37,16 @@ export interface LineDevices {
export function useLineDevicesQuery() {
const stationStore = useStationStore();
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore();
const { pollingEnabled } = storeToRefs(queryControlStore);
return useQuery({
queryKey: ['line-devices', updatedTime],
enabled: computed(() => onlineStationList.value.length > 0),
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
placeholderData: (prev) => prev,
queryFn: async (): Promise<LineDevices> => {
// console.time('useLineDevicesQuery');
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
const lineDevices: LineDevices = {};
@@ -108,6 +113,8 @@ export function useLineDevicesQuery() {
}
}
// console.timeEnd('useLineDevicesQuery');
return lineDevices;
},
});