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,6 +1,6 @@
<script setup lang="ts">
import type { NdmDeviceResultVO } from '@/apis/models';
import { DeviceType, DeviceTypeName, getDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
import { NButton, NCard, NFlex, NTag } from 'naive-ui';
import { computed, toRefs } from 'vue';
@@ -12,7 +12,11 @@ const props = defineProps<{
const { device } = toRefs(props);
const type = computed(() => DeviceTypeName[getDeviceTypeVal(device.value.deviceType)]);
const type = computed(() => {
const deviceTypeVal = tryGetDeviceTypeVal(device.value.deviceType);
if (!deviceTypeVal) return '-';
return DeviceTypeName[deviceTypeVal];
});
const name = computed(() => device.value.name ?? '-');
const ipAddr = computed(() => device.value.ipAddress ?? '-');
const gbCode = computed(() => Reflect.get(device.value, 'gbCode') as string | undefined);
@@ -20,7 +24,8 @@ const status = computed(() => device.value.deviceStatus);
const canOpenMgmtPage = computed(() => {
const mgmtableDeviceTypes: DeviceTypeVal[] = [DeviceType['Camera'], DeviceType['Decoder'], DeviceType['Switch']];
return mgmtableDeviceTypes.includes(getDeviceTypeVal(device.value.deviceType));
const deviceTypeVal = tryGetDeviceTypeVal(device.value.deviceType);
return deviceTypeVal && mgmtableDeviceTypes.includes(deviceTypeVal);
});
const onClickOpenMgmtPage = () => {