refactor(设备管理): 提取常量并优化样式管理
将状态标签和设备类型映射提取到常量文件 将表格组件样式和空状态样式提取到样式文件 移除组件内硬编码的映射和样式,使用导入的常量
This commit is contained in:
@@ -276,3 +276,20 @@ export const ACTION_BUTTON_CONFIG = {
|
|||||||
// 单个删除确认消息
|
// 单个删除确认消息
|
||||||
singleDeleteConfirmMessage: name => `确定要删除设备 "${name}" 吗?此操作不可恢复。`,
|
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: '其他设备',
|
||||||
|
};
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ import {
|
|||||||
DEVICE_STATUS_OPTIONS,
|
DEVICE_STATUS_OPTIONS,
|
||||||
COLUMN_WIDTH_CONFIG,
|
COLUMN_WIDTH_CONFIG,
|
||||||
EMPTY_STATE_CONFIG,
|
EMPTY_STATE_CONFIG,
|
||||||
|
STATUS_MAP,
|
||||||
|
TYPE_MAP,
|
||||||
} from '../constants/deviceManagementConstants';
|
} from '../constants/deviceManagementConstants';
|
||||||
import {
|
import {
|
||||||
pageContainerStyle,
|
pageContainerStyle,
|
||||||
@@ -88,6 +90,10 @@ import {
|
|||||||
detailModalStyles,
|
detailModalStyles,
|
||||||
exportModalStyles,
|
exportModalStyles,
|
||||||
generateGlobalStyles,
|
generateGlobalStyles,
|
||||||
|
emptyStateStyle,
|
||||||
|
emptyStateIconStyle,
|
||||||
|
tableContainerStyle,
|
||||||
|
resizableTitleStyles,
|
||||||
} from '../styles/deviceManagementStyles';
|
} from '../styles/deviceManagementStyles';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
@@ -199,36 +205,14 @@ const ResizableTitle = props => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<th {...restProps} style={{ position: 'relative' }}>
|
<th {...restProps} style={{ position: 'relative' }}>
|
||||||
<div
|
<div style={resizableTitleStyles.container}>
|
||||||
style={{
|
<span style={resizableTitleStyles.text}>
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
{onResize && (
|
{onResize && (
|
||||||
<div
|
<div
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
style={{
|
style={resizableTitleStyles.resizeHandle}
|
||||||
width: '8px',
|
|
||||||
height: '20px',
|
|
||||||
backgroundColor: '#e0e0e0',
|
|
||||||
borderRadius: '4px',
|
|
||||||
cursor: 'col-resize',
|
|
||||||
marginLeft: '8px',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -1012,22 +996,7 @@ function DeviceManagement() {
|
|||||||
return false;
|
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 => {
|
const getDeviceTypeIcon = type => {
|
||||||
@@ -1100,7 +1069,7 @@ function DeviceManagement() {
|
|||||||
return (
|
return (
|
||||||
<Space>
|
<Space>
|
||||||
{getDeviceTypeIcon(type)}
|
{getDeviceTypeIcon(type)}
|
||||||
<span>{typeMap[type]}</span>
|
<span>{TYPE_MAP[type]}</span>
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -1119,16 +1088,16 @@ function DeviceManagement() {
|
|||||||
return (
|
return (
|
||||||
<Space>
|
<Space>
|
||||||
{status.map(s => (
|
{status.map(s => (
|
||||||
<span key={s} style={{ color: statusMap[s]?.color || 'black' }}>
|
<span key={s} style={{ color: STATUS_MAP[s]?.color || 'black' }}>
|
||||||
{statusMap[s]?.text || s}
|
{STATUS_MAP[s]?.text || s}
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<span style={{ color: statusMap[status]?.color || 'black' }}>
|
<span style={{ color: STATUS_MAP[status]?.color || 'black' }}>
|
||||||
{statusMap[status]?.text || status}
|
{STATUS_MAP[status]?.text || status}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -1509,16 +1478,13 @@ function DeviceManagement() {
|
|||||||
{!loading && filteredDevicesMemo.length === 0 && !searching && (
|
{!loading && filteredDevicesMemo.length === 0 && !searching && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
textAlign: 'center',
|
...emptyStateStyle,
|
||||||
padding: '60px 20px',
|
|
||||||
color: designTokens.colors.text.secondary,
|
color: designTokens.colors.text.secondary,
|
||||||
fontSize: '15px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SearchOutlined
|
<SearchOutlined
|
||||||
style={{
|
style={{
|
||||||
fontSize: '48px',
|
...emptyStateIconStyle,
|
||||||
marginBottom: '16px',
|
|
||||||
color: designTokens.colors.border.light,
|
color: designTokens.colors.border.light,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -1529,8 +1495,8 @@ function DeviceManagement() {
|
|||||||
<div
|
<div
|
||||||
className="device-table-wrapper"
|
className="device-table-wrapper"
|
||||||
style={{
|
style={{
|
||||||
|
...tableContainerStyle,
|
||||||
borderRadius: designTokens.borderRadius.medium,
|
borderRadius: designTokens.borderRadius.medium,
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Table
|
<Table
|
||||||
|
|||||||
@@ -406,6 +406,50 @@ export const exportModalStyles = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 空状态样式
|
||||||
|
export const emptyStateStyle = {
|
||||||
|
textAlign: 'center',
|
||||||
|
padding: '60px 20px',
|
||||||
|
fontSize: '15px',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 空状态图标样式
|
||||||
|
export const emptyStateIconStyle = {
|
||||||
|
fontSize: '48px',
|
||||||
|
marginBottom: '16px',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格容器样式
|
||||||
|
export const tableContainerStyle = {
|
||||||
|
borderRadius: borderRadius.medium,
|
||||||
|
overflow: 'hidden',
|
||||||
|
};
|
||||||
|
|
||||||
|
// ResizableTitle 组件样式
|
||||||
|
export const resizableTitleStyles = {
|
||||||
|
container: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
width: '100%',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
flex: 1,
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
},
|
||||||
|
resizeHandle: {
|
||||||
|
width: '8px',
|
||||||
|
height: '20px',
|
||||||
|
backgroundColor: '#e0e0e0',
|
||||||
|
borderRadius: '4px',
|
||||||
|
cursor: 'col-resize',
|
||||||
|
marginLeft: '8px',
|
||||||
|
flexShrink: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// CSS-in-JS 样式字符串生成函数
|
// CSS-in-JS 样式字符串生成函数
|
||||||
export const generateGlobalStyles = tokens => `
|
export const generateGlobalStyles = tokens => `
|
||||||
.device-modal .ant-modal-close {
|
.device-modal .ant-modal-close {
|
||||||
|
|||||||
Reference in New Issue
Block a user