fix: queries continue running after page unmounted
This commit is contained in:
@@ -35,8 +35,7 @@ export function useLineDevicesQuery() {
|
||||
return useQuery({
|
||||
queryKey: ['line-devices', updatedTime],
|
||||
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
|
||||
placeholderData: (prev) => prev,
|
||||
queryFn: async (): Promise<LineDevices> => {
|
||||
queryFn: async ({ signal }): Promise<LineDevices> => {
|
||||
// console.time('useLineDevicesQuery');
|
||||
|
||||
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
||||
@@ -59,14 +58,14 @@ export function useLineDevicesQuery() {
|
||||
try {
|
||||
// 并行获取该车站的所有设备类型数据
|
||||
const [cameraData, decoderData, keyboardData, mediaServerData, nvrData, securityBoxData, switchData, videoServerData] = await Promise.all([
|
||||
postNdmCameraPage(station.code, pageQuery),
|
||||
postNdmDecoderPage(station.code, pageQuery),
|
||||
postNdmKeyboardPage(station.code, pageQuery),
|
||||
postNdmMediaServerPage(station.code, pageQuery),
|
||||
postNdmNvrPage(station.code, pageQuery),
|
||||
postNdmSecurityBoxPage(station.code, pageQuery),
|
||||
postNdmSwitchPage(station.code, pageQuery),
|
||||
postNdmVideoServerPage(station.code, pageQuery),
|
||||
postNdmCameraPage(station.code, pageQuery, signal),
|
||||
postNdmDecoderPage(station.code, pageQuery, signal),
|
||||
postNdmKeyboardPage(station.code, pageQuery, signal),
|
||||
postNdmMediaServerPage(station.code, pageQuery, signal),
|
||||
postNdmNvrPage(station.code, pageQuery, signal),
|
||||
postNdmSecurityBoxPage(station.code, pageQuery, signal),
|
||||
postNdmSwitchPage(station.code, pageQuery, signal),
|
||||
postNdmVideoServerPage(station.code, pageQuery, signal),
|
||||
]);
|
||||
|
||||
// 存储该车站的设备数据
|
||||
@@ -91,5 +90,6 @@ export function useLineDevicesQuery() {
|
||||
|
||||
return lineDevices;
|
||||
},
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useStationStore } from '@/stores/station';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import type { StationDevices } from './domains/station-devices';
|
||||
import type { StationDevices } from './domains';
|
||||
|
||||
const createEmptyStationDevices = (): StationDevices => {
|
||||
return {
|
||||
@@ -34,8 +34,7 @@ export function useStationDevicesQuery(stationCode: Station['code']) {
|
||||
return useQuery({
|
||||
queryKey: ['station-devices', stationCode, updatedTime],
|
||||
enabled: computed(() => isOnline.value && pollingEnabled.value),
|
||||
placeholderData: (prev) => prev ?? createEmptyStationDevices(),
|
||||
queryFn: async (): Promise<StationDevices> => {
|
||||
queryFn: async ({ signal }): Promise<StationDevices> => {
|
||||
const pageQuery: PageParams<{}> = { model: {}, extra: {}, size: 5000, current: 1, sort: 'id', order: 'ascending' };
|
||||
|
||||
// 如果车站离线,返回空数据
|
||||
@@ -45,14 +44,14 @@ export function useStationDevicesQuery(stationCode: Station['code']) {
|
||||
|
||||
try {
|
||||
const [cameraData, decoderData, keyboardData, mediaServerData, nvrData, securityBoxData, switchData, videoServerData] = await Promise.all([
|
||||
postNdmCameraPage(stationCode, pageQuery),
|
||||
postNdmDecoderPage(stationCode, pageQuery),
|
||||
postNdmKeyboardPage(stationCode, pageQuery),
|
||||
postNdmMediaServerPage(stationCode, pageQuery),
|
||||
postNdmNvrPage(stationCode, pageQuery),
|
||||
postNdmSecurityBoxPage(stationCode, pageQuery),
|
||||
postNdmSwitchPage(stationCode, pageQuery),
|
||||
postNdmVideoServerPage(stationCode, pageQuery),
|
||||
postNdmCameraPage(stationCode, pageQuery, signal),
|
||||
postNdmDecoderPage(stationCode, pageQuery, signal),
|
||||
postNdmKeyboardPage(stationCode, pageQuery, signal),
|
||||
postNdmMediaServerPage(stationCode, pageQuery, signal),
|
||||
postNdmNvrPage(stationCode, pageQuery, signal),
|
||||
postNdmSecurityBoxPage(stationCode, pageQuery, signal),
|
||||
postNdmSwitchPage(stationCode, pageQuery, signal),
|
||||
postNdmVideoServerPage(stationCode, pageQuery, signal),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -71,5 +70,6 @@ export function useStationDevicesQuery(stationCode: Station['code']) {
|
||||
return createEmptyStationDevices();
|
||||
}
|
||||
},
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user