refactor: tryGetDeviceTypeVal

This commit is contained in:
yangsy
2025-09-30 15:09:12 +08:00
parent 97bf9855c7
commit d0adb869da
11 changed files with 68 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
import type { NdmDeviceResultVO } from '@/apis/models';
import { DeviceType, getDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
import { DeviceType, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
import { ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import type { LineDevices } from '../query';
@@ -39,7 +39,10 @@ export function useDeviceSelection() {
const selectDevice = (device: NdmDeviceResultVO, stationCode: string) => {
selectedDevice.value = device;
selectedStationCode.value = stationCode;
selectedDeviceType.value = getDeviceTypeVal(device.deviceType);
const deviceTypeVal = tryGetDeviceTypeVal(device.deviceType);
if (!!deviceTypeVal) {
selectedDeviceType.value = deviceTypeVal;
}
};
const syncToRoute = () => {

View File

@@ -8,7 +8,7 @@ import { computed } from 'vue';
import dayjs from 'dayjs';
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
import type { Station } from '@/apis/domains';
import { DeviceType, getDeviceTypeVal } from '@/enums/device-type';
import { DeviceType, tryGetDeviceTypeVal } from '@/enums/device-type';
import type { StationAlarmCounts } from './domains';
import { runTask } from '@/utils/run-task';
@@ -88,7 +88,10 @@ function useStationAlarmCountsMutation() {
signal,
);
for (const alarm of alarmList) {
stationAlarmCounts[getDeviceTypeVal(alarm.deviceType)]++;
const deviceTypeVal = tryGetDeviceTypeVal(alarm.deviceType);
if (deviceTypeVal) {
stationAlarmCounts[deviceTypeVal]++;
}
}
stationAlarmCounts.unclassified = parseInt(total);
return stationAlarmCounts;