fix: queries continue running after page unmounted
This commit is contained in:
@@ -39,8 +39,7 @@ export function useLineAlarmsQuery() {
|
||||
return useQuery({
|
||||
queryKey: ['line-alarms', updatedTime],
|
||||
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
|
||||
placeholderData: (prev) => prev,
|
||||
queryFn: async (): Promise<LineAlarms> => {
|
||||
queryFn: async ({ signal }): Promise<LineAlarms> => {
|
||||
// console.time('useLineAlarmsQuery');
|
||||
|
||||
const lineAlarms: LineAlarms = {};
|
||||
@@ -66,17 +65,21 @@ export function useLineAlarmsQuery() {
|
||||
const now = dayjs();
|
||||
const todayStart = now.startOf('date').valueOf();
|
||||
const todayEnd = now.endOf('date').valueOf();
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(station.code, {
|
||||
model: {},
|
||||
extra: {
|
||||
alarmDate_ge: todayStart,
|
||||
alarmDate_le: todayEnd,
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(
|
||||
station.code,
|
||||
{
|
||||
model: {},
|
||||
extra: {
|
||||
alarmDate_ge: todayStart,
|
||||
alarmDate_le: todayEnd,
|
||||
},
|
||||
size: 50000,
|
||||
current: 1,
|
||||
sort: 'id',
|
||||
order: 'descending',
|
||||
},
|
||||
size: 50000,
|
||||
current: 1,
|
||||
sort: 'id',
|
||||
order: 'descending',
|
||||
});
|
||||
signal,
|
||||
);
|
||||
const cameraAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Camera);
|
||||
const decoderAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Decoder);
|
||||
const keyboardAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Keyboard);
|
||||
@@ -105,5 +108,6 @@ export function useLineAlarmsQuery() {
|
||||
|
||||
return lineAlarms;
|
||||
},
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user