refactor: extend device-type.ts
This commit is contained in:
@@ -4,7 +4,7 @@ import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
|||||||
import { ndmDeviceAlarmLogDefaultExportByTemplate } from '@/apis/requests';
|
import { ndmDeviceAlarmLogDefaultExportByTemplate } from '@/apis/requests';
|
||||||
import type { StationAlarms } from '@/composables/query';
|
import type { StationAlarms } from '@/composables/query';
|
||||||
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
|
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 { useQueryControlStore } from '@/stores/query-control';
|
||||||
import { downloadByData } from '@/utils/download';
|
import { downloadByData } from '@/utils/download';
|
||||||
import { useMutation } from '@tanstack/vue-query';
|
import { useMutation } from '@tanstack/vue-query';
|
||||||
@@ -60,12 +60,12 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
|||||||
title: '设备类型',
|
title: '设备类型',
|
||||||
key: 'deviceType',
|
key: 'deviceType',
|
||||||
render: (rowData) => {
|
render: (rowData) => {
|
||||||
return DeviceTypeName[(rowData.deviceType ?? DeviceType.Camera) as DeviceTypeVal];
|
return DeviceTypeName[getDeviceTypeVal(rowData.deviceType)];
|
||||||
},
|
},
|
||||||
filterMultiple: true,
|
filterMultiple: true,
|
||||||
filterOptions: Object.values(DeviceType).map((deviceType) => ({ label: DeviceTypeName[deviceType], value: deviceType })),
|
filterOptions: Object.values(DeviceType).map((deviceType) => ({ label: DeviceTypeName[deviceType], value: deviceType })),
|
||||||
filter: (filterOptionValue, row) => {
|
filter: (filterOptionValue, row) => {
|
||||||
return row.deviceType === filterOptionValue;
|
return getDeviceTypeVal(row.deviceType) === filterOptionValue;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ title: '设备名称', key: 'deviceName' },
|
{ title: '设备名称', key: 'deviceName' },
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import type { Station } from '@/apis/domains';
|
import type { Station } from '@/apis/domains';
|
||||||
import type { NdmDeviceResultVO, NdmNvrResultVO } from '@/apis/models';
|
import type { NdmDeviceResultVO, NdmNvrResultVO } from '@/apis/models';
|
||||||
import type { LineDevices } from '@/composables/query/device/use-line-devices-query';
|
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 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 { 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';
|
import { computed, h, ref, toRefs, useTemplateRef } from 'vue';
|
||||||
@@ -165,7 +165,8 @@ const selectedStationCode = defineModel<string>('selected-station-code');
|
|||||||
const expandedKeys = ref<string[]>();
|
const expandedKeys = ref<string[]>();
|
||||||
const deviceTreeInst = useTemplateRef<TreeInst>('deviceTreeInst');
|
const deviceTreeInst = useTemplateRef<TreeInst>('deviceTreeInst');
|
||||||
const onClickLocateDeviceTree = () => {
|
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;
|
selectedKeys.value = selectedDevice.value?.id ? [selectedDevice.value.id] : undefined;
|
||||||
|
|
||||||
let expanded: string[] | undefined = selectedStationCode.value ? [selectedStationCode.value] : undefined;
|
let expanded: string[] | undefined = selectedStationCode.value ? [selectedStationCode.value] : undefined;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import type { Station } from '@/apis/domains';
|
import type { Station } from '@/apis/domains';
|
||||||
import type { NdmDeviceVO } from '@/apis/models';
|
import type { NdmDeviceVO } from '@/apis/models';
|
||||||
import type { StationDevices } from '@/composables/query';
|
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 { useQueryControlStore } from '@/stores/query-control';
|
||||||
import { NButton, NCol, NInput, NModal, NRow, NStatistic, NTree } from 'naive-ui';
|
import { NButton, NCol, NInput, NModal, NRow, NStatistic, NTree } from 'naive-ui';
|
||||||
import type { TreeOption, TreeOverrideNodeClickBehavior } from 'naive-ui';
|
import type { TreeOption, TreeOverrideNodeClickBehavior } from 'naive-ui';
|
||||||
@@ -83,7 +83,7 @@ const treeData = computed<TreeOption[]>(() => {
|
|||||||
path: '/device',
|
path: '/device',
|
||||||
query: {
|
query: {
|
||||||
stationCode: station.value.code,
|
stationCode: station.value.code,
|
||||||
deviceType: dev.deviceType,
|
deviceType: getDeviceTypeVal(dev.deviceType),
|
||||||
deviceDBId: dev.id,
|
deviceDBId: dev.id,
|
||||||
from: route.path,
|
from: route.path,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Station } from '@/apis/domains';
|
import type { Station } from '@/apis/domains';
|
||||||
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
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 { useQueryControlStore } from '@/stores/query-control';
|
||||||
import { useStationStore } from '@/stores/station';
|
import { useStationStore } from '@/stores/station';
|
||||||
import { useQuery } from '@tanstack/vue-query';
|
import { useQuery } from '@tanstack/vue-query';
|
||||||
@@ -84,21 +84,21 @@ export function useLineAlarmsQuery() {
|
|||||||
},
|
},
|
||||||
signal,
|
signal,
|
||||||
);
|
);
|
||||||
const cameraAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Camera);
|
const cameraAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Camera);
|
||||||
stationAlarms[DeviceType.Camera] = cameraAlarms;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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[DeviceType.VideoServer] = videoServerAlarms;
|
||||||
stationAlarms.unclassified = alarmList;
|
stationAlarms.unclassified = alarmList;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,28 @@
|
|||||||
export const DeviceType = {
|
export const DeviceType = {
|
||||||
Camera: '132',
|
Camera: 'ndmCamera',
|
||||||
Nvr: '118',
|
Nvr: 'ndmNvr',
|
||||||
Switch: '220',
|
Switch: 'ndmSwitch',
|
||||||
Decoder: '114',
|
Decoder: 'ndmDecoder',
|
||||||
SecurityBox: '222',
|
SecurityBox: 'ndmSecurityBox',
|
||||||
MediaServer: '403',
|
MediaServer: 'ndmMediaServer',
|
||||||
VideoServer: '401',
|
VideoServer: 'ndmVideoServer',
|
||||||
Keyboard: '141',
|
Keyboard: 'ndmKeyboard',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type DeviceTypeKey = keyof typeof DeviceType;
|
export type DeviceTypeKey = keyof typeof DeviceType;
|
||||||
export type DeviceTypeVal = (typeof DeviceType)[DeviceTypeKey];
|
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> = {
|
export const DeviceTypeName: Record<DeviceTypeVal, string> = {
|
||||||
[DeviceType.Camera]: '摄像机',
|
[DeviceType.Camera]: '摄像机',
|
||||||
[DeviceType.Nvr]: '网络录像机',
|
[DeviceType.Nvr]: '网络录像机',
|
||||||
@@ -22,3 +33,16 @@ export const DeviceTypeName: Record<DeviceTypeVal, string> = {
|
|||||||
[DeviceType.VideoServer]: '视频服务器',
|
[DeviceType.VideoServer]: '视频服务器',
|
||||||
[DeviceType.Keyboard]: '网络键盘',
|
[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;
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
||||||
import { ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
import { ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||||
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
|
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 { useStationStore } from '@/stores/station';
|
||||||
import { downloadByData } from '@/utils/download';
|
import { downloadByData } from '@/utils/download';
|
||||||
import { useMutation } from '@tanstack/vue-query';
|
import { useMutation } from '@tanstack/vue-query';
|
||||||
@@ -109,7 +109,9 @@ const { mutate: getAlarmList, isPending: isTableLoading } = useMutation({
|
|||||||
extra: {
|
extra: {
|
||||||
stationCode_in: [...searchFields.stationCode_in],
|
stationCode_in: [...searchFields.stationCode_in],
|
||||||
deviceName_like: searchFields.deviceName_like,
|
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_ge: searchFields.alarmDate[0],
|
||||||
alarmDate_le: searchFields.alarmDate[1],
|
alarmDate_le: searchFields.alarmDate[1],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user