diff --git a/src/components/device-alarm-detail-modal.vue b/src/components/device-alarm-detail-modal.vue index 1b90fdc..97b528f 100644 --- a/src/components/device-alarm-detail-modal.vue +++ b/src/components/device-alarm-detail-modal.vue @@ -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 = [ 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' }, diff --git a/src/components/device-tree.vue b/src/components/device-tree.vue index c37dd9b..563eaf0 100644 --- a/src/components/device-tree.vue +++ b/src/components/device-tree.vue @@ -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('selected-station-code'); const expandedKeys = ref(); const deviceTreeInst = useTemplateRef('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; diff --git a/src/components/offline-device-detail-modal.vue b/src/components/offline-device-detail-modal.vue index 51cead1..d62b1ed 100644 --- a/src/components/offline-device-detail-modal.vue +++ b/src/components/offline-device-detail-modal.vue @@ -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(() => { path: '/device', query: { stationCode: station.value.code, - deviceType: dev.deviceType, + deviceType: getDeviceTypeVal(dev.deviceType), deviceDBId: dev.id, from: route.path, }, diff --git a/src/composables/query/alarm/use-line-alarms-query.ts b/src/composables/query/alarm/use-line-alarms-query.ts index 69fb727..5beedd5 100644 --- a/src/composables/query/alarm/use-line-alarms-query.ts +++ b/src/composables/query/alarm/use-line-alarms-query.ts @@ -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; diff --git a/src/enums/device-type.ts b/src/enums/device-type.ts index 7f0e08a..7175d75 100644 --- a/src/enums/device-type.ts +++ b/src/enums/device-type.ts @@ -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 = { + [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 = { [DeviceType.Camera]: '摄像机', [DeviceType.Nvr]: '网络录像机', @@ -22,3 +33,16 @@ export const DeviceTypeName: Record = { [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; +}; diff --git a/src/pages/alarm-page.vue b/src/pages/alarm-page.vue index ceb301a..9ec1df9 100644 --- a/src/pages/alarm-page.vue +++ b/src/pages/alarm-page.vue @@ -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], },