fix: queries continue running after page unmounted

This commit is contained in:
yangsy
2025-08-25 23:32:25 +08:00
parent 59a14cb9e1
commit 3cfb829608
20 changed files with 98 additions and 112 deletions

View File

@@ -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,
});
}