refactor(components): extract component helpers
This commit is contained in:
@@ -2,15 +2,16 @@
|
||||
import type { Station } from '@/apis/domains';
|
||||
import type { NdmDeviceAlarmLogPageQuery, NdmDeviceAlarmLogResultVO, NdmDeviceAlarmLogVO, PageQueryExtra } from '@/apis/models';
|
||||
import { ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||
import { renderAlarmDateCell, renderAlarmTypeCell, renderDeviceTypeCell, renderFaultLevelCell } from '@/components/helper';
|
||||
import type { StationAlarmCounts } from '@/composables/query';
|
||||
import { FaultLevel } from '@/enums/fault-level';
|
||||
import { AlarmType } from '@/enums/alarm-type';
|
||||
import { DeviceType, DeviceTypeCode, DeviceTypeName, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
|
||||
import { DeviceType, DeviceTypeCode, DeviceTypeName, type DeviceTypeVal } from '@/enums/device-type';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { downloadByData } from '@/utils/download';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
import { NButton, NCol, NDataTable, NModal, NRow, NSpace, NStatistic, NTag, type DataTableColumns, type DataTableProps, type DataTableRowData, type PaginationProps, type TagProps } from 'naive-ui';
|
||||
import { NButton, NCol, NDataTable, NModal, NRow, NSpace, NStatistic, NTag, type DataTableColumns, type DataTableProps, type DataTableRowData, type PaginationProps } from 'naive-ui';
|
||||
import { computed, h, reactive, ref, toRefs, watch } from 'vue';
|
||||
|
||||
interface Props {
|
||||
@@ -49,18 +50,12 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
{
|
||||
title: '告警时间',
|
||||
key: 'alarmDate',
|
||||
render: (rowData /* , rowIndex */) => {
|
||||
return dayjs(Number(rowData.alarmDate ?? 0)).format('YYYY-MM-DD HH:mm:ss');
|
||||
},
|
||||
render: renderAlarmDateCell,
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
key: 'deviceType',
|
||||
render: (rowData) => {
|
||||
const deviceTypeVal = tryGetDeviceTypeVal(rowData.deviceType);
|
||||
if (!deviceTypeVal) return '-';
|
||||
return DeviceTypeName[deviceTypeVal];
|
||||
},
|
||||
render: renderDeviceTypeCell,
|
||||
filter: true,
|
||||
filterMultiple: true,
|
||||
filterOptions: Object.values(DeviceType).map((deviceType) => ({ label: DeviceTypeName[deviceType], value: deviceType })),
|
||||
@@ -70,13 +65,7 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
title: '告警类型',
|
||||
key: 'alarmType',
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
const { alarmType } = rowData;
|
||||
if (!alarmType) {
|
||||
return '';
|
||||
}
|
||||
return h(NTag, { type: 'default' }, { default: () => AlarmType[alarmType] });
|
||||
},
|
||||
render: renderAlarmTypeCell,
|
||||
filter: true,
|
||||
filterMultiple: true,
|
||||
filterOptions: Object.keys(AlarmType).map((alarmType) => ({ label: AlarmType[alarmType], value: alarmType })),
|
||||
@@ -85,21 +74,7 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
title: '故障级别',
|
||||
key: 'faultLevel',
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
const { faultLevel } = rowData;
|
||||
if (!faultLevel) {
|
||||
return '';
|
||||
}
|
||||
let type: TagProps['type'] = 'default';
|
||||
if (faultLevel === '1') {
|
||||
type = 'error';
|
||||
} else if (faultLevel === '2') {
|
||||
type = 'warning';
|
||||
} else if (faultLevel === '3') {
|
||||
type = 'info';
|
||||
}
|
||||
return h(NTag, { type }, { default: () => FaultLevel[faultLevel] });
|
||||
},
|
||||
render: renderFaultLevelCell,
|
||||
filter: true,
|
||||
filterMultiple: true,
|
||||
filterOptions: Object.keys(FaultLevel).map((faultLevel) => ({ label: FaultLevel[faultLevel], value: faultLevel })),
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* - 响应式数据处理和布局
|
||||
*/
|
||||
|
||||
import { getPortStatusVal, transformPortSpeed } from '../../helper';
|
||||
import type { NdmSwitchPortInfo } from '@/apis/domains';
|
||||
import { getPortStatusVal, transformPortSpeed } from '@/components/helper';
|
||||
import { NCard, NGrid, NGridItem, NPopover } from 'naive-ui';
|
||||
import { computed, toRefs } from 'vue';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import type { NdmDeviceAlarmLogResultVO, NdmDeviceResultVO, NdmNvrResultVO, PageParams } from '@/apis/models';
|
||||
import type { NdmDeviceAlarmLogResultVO, NdmDeviceResultVO, PageParams } from '@/apis/models';
|
||||
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||
import { DeviceType, tryGetDeviceTypeVal } from '@/enums/device-type';
|
||||
import { renderAlarmDateCell, renderAlarmTypeCell, renderFaultDescriptionCell, renderFaultLevelCell } from '@/components/helper';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
import { NButton, NCard, NDataTable, NPopover, NScrollbar, type DataTableColumns, type DataTableRowData, type DatePickerProps, type PaginationProps } from 'naive-ui';
|
||||
import { NCard, NDataTable, type DataTableColumns, type DataTableRowData, type DatePickerProps, type PaginationProps } from 'naive-ui';
|
||||
import { h } from 'vue';
|
||||
import { reactive, ref, toRefs } from 'vue';
|
||||
|
||||
@@ -21,66 +20,25 @@ const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
{
|
||||
title: '告警时间',
|
||||
key: 'alarmDate',
|
||||
render: (rowData /* , rowIndex */) => {
|
||||
return dayjs(Number(rowData.alarmDate ?? 0)).format('YYYY-MM-DD HH:mm:ss');
|
||||
},
|
||||
render: renderAlarmDateCell,
|
||||
},
|
||||
{ title: '告警类型', key: 'alarmType', align: 'center' },
|
||||
{ title: '故障级别', key: 'faultLevel', align: 'center' },
|
||||
{ title: '故障编码', key: 'faultCode', align: 'center' },
|
||||
{
|
||||
title: '告警类型',
|
||||
key: 'alarmType',
|
||||
align: 'center',
|
||||
render: renderAlarmTypeCell,
|
||||
},
|
||||
{
|
||||
title: '故障级别',
|
||||
key: 'faultLevel',
|
||||
align: 'center',
|
||||
render: renderFaultLevelCell,
|
||||
},
|
||||
// { title: '故障编码', key: 'faultCode', align: 'center' },
|
||||
{
|
||||
title: '故障描述',
|
||||
key: 'faultDescription',
|
||||
render: (rowData) => {
|
||||
const isNvrCluster = (ndmDevice: NdmDeviceResultVO) => {
|
||||
const deviceTypeVal = tryGetDeviceTypeVal(ndmDevice.deviceType);
|
||||
if (!deviceTypeVal) return false;
|
||||
const isNvr = deviceTypeVal === DeviceType.Nvr;
|
||||
if (!isNvr) return false;
|
||||
const maybeNvrCluster = ndmDevice as NdmNvrResultVO;
|
||||
return !!maybeNvrCluster.clusterList?.trim() && maybeNvrCluster.clusterList !== maybeNvrCluster.ipAddress;
|
||||
};
|
||||
if (!isNvrCluster(ndmDevice.value)) {
|
||||
return rowData.faultDescription;
|
||||
}
|
||||
return h(
|
||||
NPopover,
|
||||
{
|
||||
trigger: 'click',
|
||||
},
|
||||
{
|
||||
trigger: () => {
|
||||
return h(
|
||||
NButton,
|
||||
{
|
||||
text: true,
|
||||
type: 'info',
|
||||
},
|
||||
{
|
||||
default: () => '查看',
|
||||
},
|
||||
);
|
||||
},
|
||||
default: () => {
|
||||
return h(
|
||||
// 'pre',
|
||||
NScrollbar,
|
||||
{
|
||||
style: {
|
||||
width: '800px',
|
||||
'max-height': '400px',
|
||||
},
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
return h('pre', {}, { default: () => rowData.faultDescription?.split('; ').join('\n') ?? '' });
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
render: (rowData) => renderFaultDescriptionCell(rowData, ndmDevice.value),
|
||||
},
|
||||
{
|
||||
title: '是否恢复',
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
import type { NdmSwitchDiagInfo, NdmSwitchPortInfo } from '@/apis/domains';
|
||||
import type { NdmSwitchResultVO, PageParams } from '@/apis/models';
|
||||
import { postSnmpLogPage } from '@/apis/requests';
|
||||
import { getPortStatusVal, transformPortSpeed } from '@/components/helper';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
import destr from 'destr';
|
||||
import { NButton, NCard, NDataTable, NModal, type DataTableColumns, type DataTableRowData, type DatePickerProps, type PaginationProps } from 'naive-ui';
|
||||
import { h, reactive, ref, toRefs } from 'vue';
|
||||
import { getPortStatusVal, transformPortSpeed } from '../../helper';
|
||||
|
||||
const props = defineProps<{
|
||||
stationCode: string;
|
||||
|
||||
91
src/components/helper/device-alarm.ts
Normal file
91
src/components/helper/device-alarm.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import type { NdmDeviceAlarmLogVO, NdmDeviceResultVO, NdmNvrResultVO } from '@/apis/models';
|
||||
import { AlarmType } from '@/enums/alarm-type';
|
||||
import { DeviceType, DeviceTypeName, tryGetDeviceTypeVal } from '@/enums/device-type';
|
||||
import { FaultLevel } from '@/enums/fault-level';
|
||||
import dayjs from 'dayjs';
|
||||
import { NButton, NPopover, NScrollbar, NTag, type TagProps } from 'naive-ui';
|
||||
import { h } from 'vue';
|
||||
|
||||
export const renderAlarmDateCell = (rowData: Partial<NdmDeviceAlarmLogVO>) => {
|
||||
return dayjs(Number(rowData.alarmDate ?? 0)).format('YYYY-MM-DD HH:mm:ss');
|
||||
};
|
||||
|
||||
export const renderDeviceTypeCell = (rowData: Partial<NdmDeviceAlarmLogVO>) => {
|
||||
const deviceTypeVal = tryGetDeviceTypeVal(rowData.deviceType);
|
||||
if (!deviceTypeVal) return '-';
|
||||
return DeviceTypeName[deviceTypeVal];
|
||||
};
|
||||
|
||||
export const renderAlarmTypeCell = (rowData: Partial<NdmDeviceAlarmLogVO>) => {
|
||||
const { alarmType } = rowData;
|
||||
if (!alarmType) {
|
||||
return '';
|
||||
}
|
||||
return h(NTag, { type: 'default' }, { default: () => AlarmType[alarmType] });
|
||||
};
|
||||
|
||||
export const renderFaultLevelCell = (rowData: Partial<NdmDeviceAlarmLogVO>) => {
|
||||
const { faultLevel } = rowData;
|
||||
if (!faultLevel) {
|
||||
return '';
|
||||
}
|
||||
let type: TagProps['type'] = 'default';
|
||||
if (faultLevel === '1') {
|
||||
type = 'error';
|
||||
} else if (faultLevel === '2') {
|
||||
type = 'warning';
|
||||
} else if (faultLevel === '3') {
|
||||
type = 'info';
|
||||
}
|
||||
return h(NTag, { type }, { default: () => FaultLevel[faultLevel] });
|
||||
};
|
||||
|
||||
export const renderFaultDescriptionCell = (rowData: Partial<NdmDeviceAlarmLogVO>, ndmDevice: NdmDeviceResultVO) => {
|
||||
const isNvrCluster = (ndmDevice: NdmDeviceResultVO) => {
|
||||
const deviceTypeVal = tryGetDeviceTypeVal(ndmDevice.deviceType);
|
||||
if (!deviceTypeVal) return false;
|
||||
const isNvr = deviceTypeVal === DeviceType.Nvr;
|
||||
if (!isNvr) return false;
|
||||
const maybeNvrCluster = ndmDevice as NdmNvrResultVO;
|
||||
return !!maybeNvrCluster.clusterList?.trim() && maybeNvrCluster.clusterList !== maybeNvrCluster.ipAddress;
|
||||
};
|
||||
if (!isNvrCluster(ndmDevice)) {
|
||||
return rowData.faultDescription;
|
||||
}
|
||||
return h(
|
||||
NPopover,
|
||||
{
|
||||
trigger: 'click',
|
||||
},
|
||||
{
|
||||
trigger: () => {
|
||||
return h(
|
||||
NButton,
|
||||
{
|
||||
text: true,
|
||||
type: 'info',
|
||||
},
|
||||
{
|
||||
default: () => '查看',
|
||||
},
|
||||
);
|
||||
},
|
||||
default: () => {
|
||||
return h(
|
||||
NScrollbar,
|
||||
{
|
||||
style: {
|
||||
width: '800px',
|
||||
'max-height': '400px',
|
||||
},
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
return h('pre', {}, { default: () => rowData.faultDescription?.split('; ').join('\n') ?? '' });
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
2
src/components/helper/index.ts
Normal file
2
src/components/helper/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './device-alarm';
|
||||
export * from './switch-port';
|
||||
Reference in New Issue
Block a user