fix: queries continue running after page unmounted
This commit is contained in:
@@ -33,8 +33,7 @@ export function useStationAlarmsQuery(stationCode: Station['code']) {
|
||||
return useQuery({
|
||||
queryKey: ['station-alarms', stationCode, updatedTime],
|
||||
enabled: computed(() => isOnline.value && pollingEnabled.value),
|
||||
placeholderData: (prev) => prev ?? createEmptyStationAlarms(),
|
||||
queryFn: async (): Promise<StationAlarms> => {
|
||||
queryFn: async ({ signal }): Promise<StationAlarms> => {
|
||||
// 如果车站离线,返回空数据
|
||||
if (!isOnline.value) {
|
||||
return createEmptyStationAlarms();
|
||||
@@ -45,17 +44,21 @@ export function useStationAlarmsQuery(stationCode: Station['code']) {
|
||||
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,
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(
|
||||
stationCode,
|
||||
{
|
||||
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((alarm) => alarm.deviceType === DeviceType.Camera);
|
||||
const decoderAlarms = alarmList.filter((alarm) => alarm.deviceType === DeviceType.Decoder);
|
||||
@@ -83,5 +86,6 @@ export function useStationAlarmsQuery(stationCode: Station['code']) {
|
||||
return createEmptyStationAlarms();
|
||||
}
|
||||
},
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user