diff --git a/frontend/src/constants/deviceManagementConstants.js b/frontend/src/constants/deviceManagementConstants.js index 632a6c8..81b88c6 100644 --- a/frontend/src/constants/deviceManagementConstants.js +++ b/frontend/src/constants/deviceManagementConstants.js @@ -276,3 +276,20 @@ export const ACTION_BUTTON_CONFIG = { // 单个删除确认消息 singleDeleteConfirmMessage: name => `确定要删除设备 "${name}" 吗?此操作不可恢复。`, }; + +// 状态标签映射 +export const STATUS_MAP = { + running: { text: '运行中', color: 'green' }, + maintenance: { text: '维护中', color: 'orange' }, + offline: { text: '离线', color: 'gray' }, + fault: { text: '故障', color: 'red' }, +}; + +// 设备类型映射 +export const TYPE_MAP = { + server: '服务器', + switch: '交换机', + router: '路由器', + storage: '存储设备', + other: '其他设备', +}; diff --git a/frontend/src/pages/DeviceManagement.jsx b/frontend/src/pages/DeviceManagement.jsx index 2f7e778..18e11e6 100644 --- a/frontend/src/pages/DeviceManagement.jsx +++ b/frontend/src/pages/DeviceManagement.jsx @@ -56,6 +56,8 @@ import { DEVICE_STATUS_OPTIONS, COLUMN_WIDTH_CONFIG, EMPTY_STATE_CONFIG, + STATUS_MAP, + TYPE_MAP, } from '../constants/deviceManagementConstants'; import { pageContainerStyle, @@ -88,6 +90,10 @@ import { detailModalStyles, exportModalStyles, generateGlobalStyles, + emptyStateStyle, + emptyStateIconStyle, + tableContainerStyle, + resizableTitleStyles, } from '../styles/deviceManagementStyles'; const { Option } = Select; @@ -199,36 +205,14 @@ const ResizableTitle = props => { return ( -
- +
+ {children} {onResize && (
)}
@@ -1012,22 +996,7 @@ function DeviceManagement() { return false; }; - // 状态标签映射 - const statusMap = { - running: { text: '运行中', color: 'green' }, - maintenance: { text: '维护中', color: 'orange' }, - offline: { text: '离线', color: 'gray' }, - fault: { text: '故障', color: 'red' }, - }; - - // 设备类型映射 - const typeMap = { - server: '服务器', - switch: '交换机', - router: '路由器', - storage: '存储设备', - other: '其他设备', - }; + // 使用从常量导入的映射,避免每次渲染重新创建 // 获取设备类型图标 const getDeviceTypeIcon = type => { @@ -1100,7 +1069,7 @@ function DeviceManagement() { return ( {getDeviceTypeIcon(type)} - {typeMap[type]} + {TYPE_MAP[type]} ); }, @@ -1119,16 +1088,16 @@ function DeviceManagement() { return ( {status.map(s => ( - - {statusMap[s]?.text || s} + + {STATUS_MAP[s]?.text || s} ))} ); } return ( - - {statusMap[status]?.text || status} + + {STATUS_MAP[status]?.text || status} ); }, @@ -1509,16 +1478,13 @@ function DeviceManagement() { {!loading && filteredDevicesMemo.length === 0 && !searching && (
@@ -1529,8 +1495,8 @@ function DeviceManagement() {
` .device-modal .ant-modal-close {