refactor: extend device-type.ts

This commit is contained in:
yangsy
2025-08-27 14:43:04 +08:00
parent 620dfd8a74
commit d948c96047
6 changed files with 53 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
import { ndmDeviceAlarmLogDefaultExportByTemplate } from '@/apis/requests';
import type { StationAlarms } from '@/composables/query';
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
import { DeviceType, DeviceTypeName, type DeviceTypeVal } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, getDeviceTypeVal } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
import { downloadByData } from '@/utils/download';
import { useMutation } from '@tanstack/vue-query';
@@ -60,12 +60,12 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
title: '设备类型',
key: 'deviceType',
render: (rowData) => {
return DeviceTypeName[(rowData.deviceType ?? DeviceType.Camera) as DeviceTypeVal];
return DeviceTypeName[getDeviceTypeVal(rowData.deviceType)];
},
filterMultiple: true,
filterOptions: Object.values(DeviceType).map((deviceType) => ({ label: DeviceTypeName[deviceType], value: deviceType })),
filter: (filterOptionValue, row) => {
return row.deviceType === filterOptionValue;
return getDeviceTypeVal(row.deviceType) === filterOptionValue;
},
},
{ title: '设备名称', key: 'deviceName' },

View File

@@ -2,7 +2,7 @@
import type { Station } from '@/apis/domains';
import type { NdmDeviceResultVO, NdmNvrResultVO } from '@/apis/models';
import type { LineDevices } from '@/composables/query/device/use-line-devices-query';
import { DeviceType, DeviceTypeName, type DeviceTypeKey, type DeviceTypeVal } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, getDeviceTypeVal, type DeviceTypeKey, type DeviceTypeVal } from '@/enums/device-type';
import destr from 'destr';
import { NButton, NButtonGroup, NFlex, NInput, NRadio, NRadioGroup, NTab, NTabs, NTag, NTree, type TagProps, type TreeInst, type TreeOption, type TreeOverrideNodeClickBehavior } from 'naive-ui';
import { computed, h, ref, toRefs, useTemplateRef } from 'vue';
@@ -165,7 +165,8 @@ const selectedStationCode = defineModel<string>('selected-station-code');
const expandedKeys = ref<string[]>();
const deviceTreeInst = useTemplateRef<TreeInst>('deviceTreeInst');
const onClickLocateDeviceTree = () => {
selectedTab.value = (selectedDevice.value?.deviceType ?? selectedTab.value) as DeviceTypeVal;
// FIXME
selectedTab.value = getDeviceTypeVal(selectedDevice.value?.deviceType ?? selectedTab.value);
selectedKeys.value = selectedDevice.value?.id ? [selectedDevice.value.id] : undefined;
let expanded: string[] | undefined = selectedStationCode.value ? [selectedStationCode.value] : undefined;

View File

@@ -2,7 +2,7 @@
import type { Station } from '@/apis/domains';
import type { NdmDeviceVO } from '@/apis/models';
import type { StationDevices } from '@/composables/query';
import { DeviceType, DeviceTypeName } from '@/enums/device-type';
import { DeviceType, DeviceTypeName, getDeviceTypeVal } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
import { NButton, NCol, NInput, NModal, NRow, NStatistic, NTree } from 'naive-ui';
import type { TreeOption, TreeOverrideNodeClickBehavior } from 'naive-ui';
@@ -83,7 +83,7 @@ const treeData = computed<TreeOption[]>(() => {
path: '/device',
query: {
stationCode: station.value.code,
deviceType: dev.deviceType,
deviceType: getDeviceTypeVal(dev.deviceType),
deviceDBId: dev.id,
from: route.path,
},

View File

@@ -1,6 +1,6 @@
import type { Station } from '@/apis/domains';
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
import { DeviceType } from '@/enums/device-type';
import { DeviceType, getDeviceTypeVal } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
import { useStationStore } from '@/stores/station';
import { useQuery } from '@tanstack/vue-query';
@@ -84,21 +84,21 @@ export function useLineAlarmsQuery() {
},
signal,
);
const cameraAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Camera);
const cameraAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Camera);
stationAlarms[DeviceType.Camera] = cameraAlarms;
const decoderAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Decoder);
const decoderAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Decoder);
stationAlarms[DeviceType.Decoder] = decoderAlarms;
const keyboardAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Keyboard);
const keyboardAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Keyboard);
stationAlarms[DeviceType.Keyboard] = keyboardAlarms;
const mediaServerAlarms = alarmList.filter((device) => device.deviceType === DeviceType.MediaServer);
const mediaServerAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.MediaServer);
stationAlarms[DeviceType.MediaServer] = mediaServerAlarms;
const nvrAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Nvr);
const nvrAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Nvr);
stationAlarms[DeviceType.Nvr] = nvrAlarms;
const securityBoxAlarms = alarmList.filter((device) => device.deviceType === DeviceType.SecurityBox);
const securityBoxAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.SecurityBox);
stationAlarms[DeviceType.SecurityBox] = securityBoxAlarms;
const switchAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Switch);
const switchAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Switch);
stationAlarms[DeviceType.Switch] = switchAlarms;
const videoServerAlarms = alarmList.filter((device) => device.deviceType === DeviceType.VideoServer);
const videoServerAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.VideoServer);
stationAlarms[DeviceType.VideoServer] = videoServerAlarms;
stationAlarms.unclassified = alarmList;

View File

@@ -1,17 +1,28 @@
export const DeviceType = {
Camera: '132',
Nvr: '118',
Switch: '220',
Decoder: '114',
SecurityBox: '222',
MediaServer: '403',
VideoServer: '401',
Keyboard: '141',
Camera: 'ndmCamera',
Nvr: 'ndmNvr',
Switch: 'ndmSwitch',
Decoder: 'ndmDecoder',
SecurityBox: 'ndmSecurityBox',
MediaServer: 'ndmMediaServer',
VideoServer: 'ndmVideoServer',
Keyboard: 'ndmKeyboard',
} as const;
export type DeviceTypeKey = keyof typeof DeviceType;
export type DeviceTypeVal = (typeof DeviceType)[DeviceTypeKey];
export const DeviceTypeCode: Record<DeviceTypeVal, string[]> = {
[DeviceType.Camera]: ['131', '132'],
[DeviceType.Nvr]: ['111', '118'],
[DeviceType.Switch]: ['220'],
[DeviceType.Decoder]: ['114'],
[DeviceType.SecurityBox]: ['222'],
[DeviceType.MediaServer]: ['403'],
[DeviceType.VideoServer]: ['401'],
[DeviceType.Keyboard]: ['141'],
};
export const DeviceTypeName: Record<DeviceTypeVal, string> = {
[DeviceType.Camera]: '摄像机',
[DeviceType.Nvr]: '网络录像机',
@@ -22,3 +33,16 @@ export const DeviceTypeName: Record<DeviceTypeVal, string> = {
[DeviceType.VideoServer]: '视频服务器',
[DeviceType.Keyboard]: '网络键盘',
};
export const getDeviceTypeVal = (devcieTypeCode?: string): DeviceTypeVal => {
let result: DeviceTypeVal = DeviceType.Camera;
if (devcieTypeCode) {
for (const key in DeviceTypeCode) {
if (DeviceTypeCode[key as DeviceTypeVal].includes(devcieTypeCode)) {
result = key as DeviceTypeVal;
break;
}
}
}
return result;
};

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 DeviceTypeVal } from '@/enums/device-type';
import { DeviceType, DeviceTypeCode, DeviceTypeName, type DeviceTypeVal } from '@/enums/device-type';
import { useStationStore } from '@/stores/station';
import { downloadByData } from '@/utils/download';
import { useMutation } from '@tanstack/vue-query';
@@ -109,7 +109,9 @@ const { mutate: getAlarmList, isPending: isTableLoading } = useMutation({
extra: {
stationCode_in: [...searchFields.stationCode_in],
deviceName_like: searchFields.deviceName_like,
deviceType_in: searchFields.deviceType_in,
deviceType_in: searchFields.deviceType_in.flatMap((deviceType) => {
return DeviceTypeCode[deviceType as DeviceTypeVal];
}),
alarmDate_ge: searchFields.alarmDate[0],
alarmDate_le: searchFields.alarmDate[1],
},