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

@@ -2,7 +2,7 @@
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
import { ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage } from '@/apis/requests';
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
import { DeviceType, DeviceTypeName, type DeviceTypeCode } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, type DeviceTypeVal } from '@/enums/device-type';
import { useStationStore } from '@/stores/station';
import { downloadByData } from '@/utils/download';
import { useMutation } from '@tanstack/vue-query';
@@ -49,7 +49,7 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
title: '设备类型',
key: 'deviceType',
render: (rowData) => {
return DeviceTypeName[(rowData.deviceType ?? DeviceType.Camera) as DeviceTypeCode];
return DeviceTypeName[(rowData.deviceType ?? DeviceType.Camera) as DeviceTypeVal];
},
},
{ title: '设备名称', key: 'deviceName' },

View File

@@ -2,7 +2,7 @@
import type { Station } from '@/apis/domains';
import type { NdmDeviceResultVO, NdmNvrResultVO } from '@/apis/models';
import { useLineDevicesQuery } from '@/composables/query';
import { DeviceType, DeviceTypeName, type DeviceTypeCode, type DeviceTypeKey } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, type DeviceTypeVal, type DeviceTypeKey } from '@/enums/device-type';
import { useStationStore } from '@/stores/station';
import { ChevronBack } from '@vicons/ionicons5';
import { destr } from 'destr';
@@ -57,7 +57,7 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
deviceTabPanes.forEach(({ name: paneName /* , tab: paneTab */ }) => {
treeData[paneName] = stationList.value.map<TreeOption>((station) => {
const { name: stationName, code: stationCode } = station;
const devices = lineDevices.value?.[stationCode][paneName];
const devices = lineDevices.value?.[stationCode][paneName] as NdmDeviceResultVO[] | undefined;
const onlineDevices = devices?.filter((device) => device.deviceStatus === '10');
const offlineDevices = devices?.filter((device) => device.deviceStatus === '20');
// 对于录像机需要根据clusterList字段以分号分隔设备IP进一步形成子树结构
@@ -159,7 +159,7 @@ const renderDeviceNodePrefix = (device: NdmDeviceResultVO, stationCode: string)
};
// ========== 选中设备 ==========
const selectedTab = ref<DeviceTypeCode>(DeviceType.Camera);
const selectedTab = ref<DeviceTypeVal>(DeviceType.Camera);
const selectedKeys = ref<string[]>();
const expandedKeys = ref<string[]>();
const selectedDevice = ref<NdmDeviceResultVO>();
@@ -167,10 +167,10 @@ const selectedDevice = ref<NdmDeviceResultVO>();
const setDeviceTreePropsFromRouteQuery = (query: LocationQuery) => {
const { stationCode, deviceType, deviceDBId } = query;
let stnCode = '';
let devType: DeviceTypeCode = DeviceType.Camera;
let devType: DeviceTypeVal = DeviceType.Camera;
let devDBId = '';
if (stationCode) stnCode = stationCode as string;
if (deviceType) devType = deviceType as DeviceTypeCode;
if (deviceType) devType = deviceType as DeviceTypeVal;
if (deviceDBId) devDBId = deviceDBId as string;
selectedTab.value = devType;
@@ -219,7 +219,7 @@ const searchFilter = (pattern: string, node: TreeOption): boolean => {
// ========== 设备树交互 ==========
const deviceTreeInst = useTemplateRef<TreeInst>('deviceTreeInst');
const onClickLocateDeviceTree = () => {
selectedTab.value = (selectedDevice.value?.deviceType ?? selectedTab.value) as DeviceTypeCode;
selectedTab.value = (selectedDevice.value?.deviceType ?? selectedTab.value) as DeviceTypeVal;
selectedKeys.value = selectedDevice.value?.id ? [selectedDevice.value.id] : undefined;
const stationCode = route.query['stationCode'] as string | undefined;