fix: polling still running when modal open
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Station } from '@/apis/domains';
|
|||||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
||||||
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||||
import { DeviceType } from '@/enums/device-type';
|
import { DeviceType } from '@/enums/device-type';
|
||||||
|
import { useQueryControlStore } from '@/stores/query-control';
|
||||||
import { useStationStore } from '@/stores/station';
|
import { useStationStore } from '@/stores/station';
|
||||||
import { useQuery } from '@tanstack/vue-query';
|
import { useQuery } from '@tanstack/vue-query';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
@@ -32,12 +33,16 @@ export interface LineAlarms {
|
|||||||
export function useLineAlarmsQuery() {
|
export function useLineAlarmsQuery() {
|
||||||
const stationStore = useStationStore();
|
const stationStore = useStationStore();
|
||||||
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
||||||
|
const queryControlStore = useQueryControlStore();
|
||||||
|
const { pollingEnabled } = storeToRefs(queryControlStore);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['line-alarms', updatedTime],
|
queryKey: ['line-alarms', updatedTime],
|
||||||
enabled: computed(() => onlineStationList.value.length > 0),
|
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
|
||||||
placeholderData: (prev) => prev,
|
placeholderData: (prev) => prev,
|
||||||
queryFn: async (): Promise<LineAlarms> => {
|
queryFn: async (): Promise<LineAlarms> => {
|
||||||
|
// console.time('useLineAlarmsQuery');
|
||||||
|
|
||||||
const lineAlarms: LineAlarms = {};
|
const lineAlarms: LineAlarms = {};
|
||||||
|
|
||||||
if (!stationList?.value) {
|
if (!stationList?.value) {
|
||||||
@@ -96,6 +101,8 @@ export function useLineAlarmsQuery() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.timeEnd('useLineAlarmsQuery');
|
||||||
|
|
||||||
return lineAlarms;
|
return lineAlarms;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
} from '@/apis/models';
|
} from '@/apis/models';
|
||||||
import { postNdmCameraPage, postNdmDecoderPage, postNdmKeyboardPage, postNdmMediaServerPage, postNdmNvrPage, postNdmSecurityBoxPage, postNdmSwitchPage, postNdmVideoServerPage } from '@/apis/requests';
|
import { postNdmCameraPage, postNdmDecoderPage, postNdmKeyboardPage, postNdmMediaServerPage, postNdmNvrPage, postNdmSecurityBoxPage, postNdmSwitchPage, postNdmVideoServerPage } from '@/apis/requests';
|
||||||
import { DeviceType } from '@/enums/device-type';
|
import { DeviceType } from '@/enums/device-type';
|
||||||
|
import { useQueryControlStore } from '@/stores/query-control';
|
||||||
import { useStationStore } from '@/stores/station';
|
import { useStationStore } from '@/stores/station';
|
||||||
import { useQuery } from '@tanstack/vue-query';
|
import { useQuery } from '@tanstack/vue-query';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
@@ -36,12 +37,16 @@ export interface LineDevices {
|
|||||||
export function useLineDevicesQuery() {
|
export function useLineDevicesQuery() {
|
||||||
const stationStore = useStationStore();
|
const stationStore = useStationStore();
|
||||||
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
||||||
|
const queryControlStore = useQueryControlStore();
|
||||||
|
const { pollingEnabled } = storeToRefs(queryControlStore);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['line-devices', updatedTime],
|
queryKey: ['line-devices', updatedTime],
|
||||||
enabled: computed(() => onlineStationList.value.length > 0),
|
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
|
||||||
placeholderData: (prev) => prev,
|
placeholderData: (prev) => prev,
|
||||||
queryFn: async (): Promise<LineDevices> => {
|
queryFn: async (): Promise<LineDevices> => {
|
||||||
|
// console.time('useLineDevicesQuery');
|
||||||
|
|
||||||
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
||||||
|
|
||||||
const lineDevices: LineDevices = {};
|
const lineDevices: LineDevices = {};
|
||||||
@@ -108,6 +113,8 @@ export function useLineDevicesQuery() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.timeEnd('useLineDevicesQuery');
|
||||||
|
|
||||||
return lineDevices;
|
return lineDevices;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user