2026-03-27 17:52:35 +08:00
|
|
|
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
2026-02-10 11:04:01 +08:00
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
Button,
|
|
|
|
|
Modal,
|
|
|
|
|
Form,
|
|
|
|
|
Input,
|
|
|
|
|
Select,
|
|
|
|
|
message,
|
|
|
|
|
Card,
|
|
|
|
|
Space,
|
|
|
|
|
Tooltip,
|
2026-02-12 14:36:33 +08:00
|
|
|
Tag,
|
|
|
|
|
Row,
|
|
|
|
|
Col,
|
2026-03-27 17:52:35 +08:00
|
|
|
Spin,
|
2026-02-10 11:04:01 +08:00
|
|
|
} from 'antd';
|
|
|
|
|
import {
|
|
|
|
|
PlusOutlined,
|
|
|
|
|
EditOutlined,
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
SearchOutlined,
|
|
|
|
|
UploadOutlined,
|
|
|
|
|
ExportOutlined,
|
2026-03-10 14:34:39 +08:00
|
|
|
SettingOutlined,
|
|
|
|
|
CloudServerOutlined,
|
|
|
|
|
ReloadOutlined,
|
2026-03-24 14:54:39 +08:00
|
|
|
AppstoreOutlined,
|
|
|
|
|
ToolOutlined,
|
|
|
|
|
EnvironmentOutlined,
|
|
|
|
|
FilterOutlined,
|
|
|
|
|
UnorderedListOutlined,
|
2026-02-10 11:04:01 +08:00
|
|
|
} from '@ant-design/icons';
|
2025-12-18 10:45:13 +08:00
|
|
|
import axios from 'axios';
|
2026-03-10 09:20:31 +08:00
|
|
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
2026-02-10 09:32:16 +08:00
|
|
|
import { designTokens } from '../config/theme';
|
|
|
|
|
import {
|
|
|
|
|
PAGINATION_CONFIG,
|
|
|
|
|
DEBOUNCE_DELAY,
|
|
|
|
|
DEFAULT_DEVICE_FIELDS,
|
2026-02-10 14:48:42 +08:00
|
|
|
STATUS_MAP,
|
|
|
|
|
TYPE_MAP,
|
2026-02-10 09:32:16 +08:00
|
|
|
} from '../constants/deviceManagementConstants';
|
|
|
|
|
import {
|
|
|
|
|
pageContainerStyle,
|
|
|
|
|
headerStyle,
|
|
|
|
|
titleRowStyle,
|
|
|
|
|
titleSectionStyle,
|
|
|
|
|
titleIconStyle,
|
|
|
|
|
titleTextStyle,
|
|
|
|
|
pageTitleStyle,
|
|
|
|
|
pageSubtitleStyle,
|
|
|
|
|
secondaryActionStyle,
|
|
|
|
|
cardStyle,
|
|
|
|
|
filterCardStyle,
|
|
|
|
|
modalHeaderStyle,
|
2026-03-10 14:34:39 +08:00
|
|
|
tableContainerStyle,
|
2026-02-10 14:48:42 +08:00
|
|
|
emptyStateStyle,
|
|
|
|
|
emptyStateIconStyle,
|
2026-03-10 14:34:39 +08:00
|
|
|
generateGlobalStyles,
|
2026-02-10 09:32:16 +08:00
|
|
|
} from '../styles/deviceManagementStyles';
|
2026-03-10 14:34:39 +08:00
|
|
|
import {
|
|
|
|
|
ResizableTitle,
|
|
|
|
|
DeviceDetailModal,
|
|
|
|
|
DeviceFormModal,
|
|
|
|
|
ImportModal,
|
|
|
|
|
ExportModal,
|
|
|
|
|
FieldConfigModal,
|
|
|
|
|
BatchStatusModal,
|
|
|
|
|
} from '../components/device';
|
|
|
|
|
import { useDebounce } from '../hooks/useDebounce';
|
2026-03-27 19:12:16 +08:00
|
|
|
import { getDeviceTypeIcon, getStatusConfig, processDeviceData } from '../utils/deviceUtils.jsx';
|
2025-12-18 10:45:13 +08:00
|
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
const DEFAULT_DEVICE_FIELDS_LOCAL = DEFAULT_DEVICE_FIELDS;
|
2025-12-19 15:05:31 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
function DeviceManagement() {
|
2026-02-12 13:27:32 +08:00
|
|
|
const navigate = useNavigate();
|
2026-03-10 09:20:31 +08:00
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
2026-03-10 14:34:39 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
const [devices, setDevices] = useState([]);
|
2025-12-29 13:02:06 +08:00
|
|
|
const [allDevices, setAllDevices] = useState([]);
|
2025-12-18 10:45:13 +08:00
|
|
|
const [racks, setRacks] = useState([]);
|
2026-03-06 13:57:37 +08:00
|
|
|
const [rooms, setRooms] = useState([]);
|
2025-12-18 10:45:13 +08:00
|
|
|
const [loading, setLoading] = useState(true);
|
2025-12-29 13:33:26 +08:00
|
|
|
const [searching, setSearching] = useState(false);
|
2026-03-10 14:34:39 +08:00
|
|
|
|
2025-12-18 13:04:32 +08:00
|
|
|
const [keyword, setKeyword] = useState('');
|
|
|
|
|
const [status, setStatus] = useState('all');
|
|
|
|
|
const [type, setType] = useState('all');
|
2026-03-19 14:38:50 +08:00
|
|
|
const [roomId, setRoomId] = useState('all');
|
|
|
|
|
const [rackId, setRackId] = useState('all');
|
2025-12-18 13:04:32 +08:00
|
|
|
const [searchForm] = Form.useForm();
|
2026-03-10 14:34:39 +08:00
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
const [pagination, setPagination] = useState({
|
|
|
|
|
current: 1,
|
|
|
|
|
pageSize: PAGINATION_CONFIG.defaultPageSize,
|
2025-12-18 19:11:56 +08:00
|
|
|
total: 0,
|
2026-02-10 09:32:16 +08:00
|
|
|
pageSizeOptions: PAGINATION_CONFIG.pageSizeOptions,
|
|
|
|
|
showSizeChanger: PAGINATION_CONFIG.showSizeChanger,
|
2026-02-10 11:04:01 +08:00
|
|
|
showTotal: PAGINATION_CONFIG.showTotal,
|
2025-12-18 19:11:56 +08:00
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
const [deviceFields, setDeviceFields] = useState([]);
|
|
|
|
|
const [loadingFields, setLoadingFields] = useState(true);
|
2026-03-10 14:34:39 +08:00
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
const [importModalVisible, setImportModalVisible] = useState(false);
|
2025-12-19 15:05:31 +08:00
|
|
|
const [detailModalVisible, setDetailModalVisible] = useState(false);
|
|
|
|
|
const [selectedDevice, setSelectedDevice] = useState(null);
|
|
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
const [modalVisible, setModalVisible] = useState(false);
|
|
|
|
|
const [editingDevice, setEditingDevice] = useState(null);
|
2025-12-19 13:21:39 +08:00
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
const [fieldConfigModalVisible, setFieldConfigModalVisible] = useState(false);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 16:10:42 +08:00
|
|
|
const [batchStatusModalVisible, setBatchStatusModalVisible] = useState(false);
|
|
|
|
|
const [batchStatusLoading, setBatchStatusLoading] = useState(false);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 16:10:42 +08:00
|
|
|
const [exportModalVisible, setExportModalVisible] = useState(false);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
const [selectedDevices, setSelectedDevices] = useState([]);
|
2025-12-29 16:10:42 +08:00
|
|
|
const [selectAll, setSelectAll] = useState(false);
|
2025-12-19 15:05:31 +08:00
|
|
|
const [columnWidths, setColumnWidths] = useState({});
|
2026-03-24 14:54:39 +08:00
|
|
|
const [advancedSearchVisible, setAdvancedSearchVisible] = useState(false);
|
2025-12-18 10:45:13 +08:00
|
|
|
|
2026-02-10 09:32:16 +08:00
|
|
|
const debouncedKeyword = useDebounce(keyword, DEBOUNCE_DELAY);
|
2025-12-29 13:33:26 +08:00
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
const fetchDevices = useCallback(
|
2026-04-01 07:44:57 +00:00
|
|
|
async (page = 1, pageSize = 50) => {
|
2026-02-10 11:04:01 +08:00
|
|
|
try {
|
2026-04-01 07:44:57 +00:00
|
|
|
setLoading(true);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
page,
|
|
|
|
|
pageSize,
|
|
|
|
|
keyword: debouncedKeyword || undefined,
|
|
|
|
|
status: status !== 'all' ? status : undefined,
|
|
|
|
|
type: type !== 'all' ? type : undefined,
|
2026-03-19 14:38:50 +08:00
|
|
|
roomId: roomId !== 'all' ? roomId : undefined,
|
|
|
|
|
rackId: rackId !== 'all' ? rackId : undefined,
|
2026-02-10 11:04:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await axios.get('/api/devices', { params });
|
2026-03-10 14:34:39 +08:00
|
|
|
const { devices: deviceList, total } = response.data;
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
const processedDevices = deviceList.map(processDeviceData);
|
2026-04-01 07:44:57 +00:00
|
|
|
setAllDevices(processedDevices);
|
2026-03-27 19:12:16 +08:00
|
|
|
setPagination(prev => ({ ...prev, current: page, pageSize, total }));
|
2026-02-10 11:04:01 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('获取设备列表失败');
|
|
|
|
|
console.error('获取设备列表失败:', error);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-03-19 14:38:50 +08:00
|
|
|
[debouncedKeyword, status, type, roomId, rackId]
|
2026-02-10 11:04:01 +08:00
|
|
|
);
|
2025-12-29 13:02:06 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
const fetchDeviceFields = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setLoadingFields(true);
|
|
|
|
|
const response = await axios.get('/api/deviceFields');
|
2026-03-20 17:15:14 +08:00
|
|
|
let fields = response.data.sort((a, b) => a.order - b.order);
|
2026-03-27 19:12:16 +08:00
|
|
|
|
2026-03-20 17:15:14 +08:00
|
|
|
// 补充缺失的 options(状态和设备类型)
|
|
|
|
|
fields = fields.map(field => {
|
|
|
|
|
if (field.fieldName === 'type' && !field.options) {
|
|
|
|
|
const defaultTypeField = DEFAULT_DEVICE_FIELDS_LOCAL.find(f => f.fieldName === 'type');
|
|
|
|
|
return { ...field, options: defaultTypeField?.options || [] };
|
|
|
|
|
}
|
|
|
|
|
if (field.fieldName === 'status' && !field.options) {
|
2026-03-27 19:12:16 +08:00
|
|
|
const defaultStatusField = DEFAULT_DEVICE_FIELDS_LOCAL.find(
|
|
|
|
|
f => f.fieldName === 'status'
|
|
|
|
|
);
|
2026-03-20 17:15:14 +08:00
|
|
|
return { ...field, options: defaultStatusField?.options || [] };
|
|
|
|
|
}
|
|
|
|
|
return field;
|
|
|
|
|
});
|
2026-03-27 19:12:16 +08:00
|
|
|
|
2026-03-20 17:15:14 +08:00
|
|
|
setDeviceFields(fields);
|
2025-12-18 10:45:13 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('获取字段配置失败');
|
|
|
|
|
console.error('获取字段配置失败:', error);
|
2026-03-10 14:34:39 +08:00
|
|
|
setDeviceFields(DEFAULT_DEVICE_FIELDS_LOCAL);
|
2025-12-18 10:45:13 +08:00
|
|
|
} finally {
|
|
|
|
|
setLoadingFields(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fetchRacks = async () => {
|
|
|
|
|
try {
|
2026-03-24 17:10:38 +08:00
|
|
|
const response = await axios.get('/api/racks/all');
|
2025-12-22 08:59:44 +08:00
|
|
|
setRacks(response.data.racks || []);
|
2025-12-18 10:45:13 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('获取机柜列表失败');
|
|
|
|
|
console.error('获取机柜列表失败:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-06 13:57:37 +08:00
|
|
|
const fetchRooms = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get('/api/rooms');
|
2026-03-20 17:15:14 +08:00
|
|
|
setRooms(response.data.rooms || []);
|
2026-03-06 13:57:37 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('获取机房列表失败');
|
|
|
|
|
console.error('获取机房列表失败:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
useEffect(() => {
|
2026-01-20 14:31:20 +08:00
|
|
|
fetchDevices(1, pagination.pageSize);
|
2025-12-18 10:45:13 +08:00
|
|
|
fetchRacks();
|
2026-03-06 13:57:37 +08:00
|
|
|
fetchRooms();
|
2025-12-18 10:45:13 +08:00
|
|
|
fetchDeviceFields();
|
2026-01-20 14:31:20 +08:00
|
|
|
}, [fetchDevices]);
|
2025-12-18 10:45:13 +08:00
|
|
|
|
2026-03-10 09:20:31 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
const deviceIdFromUrl = searchParams.get('deviceId');
|
|
|
|
|
if (deviceIdFromUrl) {
|
|
|
|
|
const fetchDeviceDetail = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get(`/api/devices/${deviceIdFromUrl}`);
|
|
|
|
|
if (response.data) {
|
|
|
|
|
setSelectedDevice(response.data);
|
|
|
|
|
setDetailModalVisible(true);
|
|
|
|
|
setSearchParams({});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取设备详情失败:', error);
|
|
|
|
|
const errorStatus = error.response?.status;
|
|
|
|
|
const errorMessage = error.response?.data?.error;
|
2026-03-10 14:34:39 +08:00
|
|
|
|
2026-03-10 09:20:31 +08:00
|
|
|
if (errorStatus === 404 || errorMessage === '设备不存在') {
|
|
|
|
|
message.warning('该设备已被删除,无法查看详情');
|
|
|
|
|
} else {
|
|
|
|
|
message.error(errorMessage || '获取设备详情失败');
|
|
|
|
|
}
|
|
|
|
|
setSearchParams({});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
fetchDeviceDetail();
|
|
|
|
|
}
|
|
|
|
|
}, [searchParams, setSearchParams]);
|
|
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
const showModal = (device = null) => {
|
|
|
|
|
setEditingDevice(device);
|
|
|
|
|
setModalVisible(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
setModalVisible(false);
|
|
|
|
|
setEditingDevice(null);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleSubmit = async deviceData => {
|
2025-12-18 10:45:13 +08:00
|
|
|
try {
|
|
|
|
|
if (editingDevice) {
|
|
|
|
|
await axios.put(`/api/devices/${editingDevice.deviceId}`, deviceData);
|
|
|
|
|
message.success('设备更新成功');
|
|
|
|
|
} else {
|
|
|
|
|
await axios.post('/api/devices', deviceData);
|
|
|
|
|
message.success('设备创建成功');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setModalVisible(false);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, pagination.pageSize);
|
2025-12-18 10:45:13 +08:00
|
|
|
setEditingDevice(null);
|
|
|
|
|
} catch (error) {
|
2026-03-06 13:57:37 +08:00
|
|
|
const errorMsg = error.response?.data?.error || error.message || '未知错误';
|
|
|
|
|
message.error(editingDevice ? `设备更新失败: ${errorMsg}` : `设备创建失败: ${errorMsg}`);
|
2025-12-18 10:45:13 +08:00
|
|
|
console.error(editingDevice ? '设备更新失败:' : '设备创建失败:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleSearch = values => {
|
2025-12-29 13:33:26 +08:00
|
|
|
setSearching(true);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 13:02:06 +08:00
|
|
|
setKeyword(values.keyword || '');
|
|
|
|
|
setStatus(values.status || 'all');
|
|
|
|
|
setType(values.type || 'all');
|
2026-03-19 14:38:50 +08:00
|
|
|
setRoomId(values.roomId || 'all');
|
|
|
|
|
setRackId(values.rackId || 'all');
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
setPagination(prev => ({ ...prev, current: 1 }));
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 13:33:26 +08:00
|
|
|
setTimeout(() => setSearching(false), 300);
|
2025-12-18 13:04:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleReset = () => {
|
2025-12-29 13:33:26 +08:00
|
|
|
setSearching(true);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 13:04:32 +08:00
|
|
|
setKeyword('');
|
|
|
|
|
setStatus('all');
|
|
|
|
|
setType('all');
|
2026-03-19 14:38:50 +08:00
|
|
|
setRoomId('all');
|
|
|
|
|
setRackId('all');
|
2025-12-18 13:04:32 +08:00
|
|
|
searchForm.resetFields();
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 13:33:26 +08:00
|
|
|
setTimeout(() => setSearching(false), 300);
|
2025-12-18 13:04:32 +08:00
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleTableChange = newPagination => {
|
2025-12-29 16:10:42 +08:00
|
|
|
setPagination(newPagination);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(newPagination.current, newPagination.pageSize);
|
2025-12-18 13:04:32 +08:00
|
|
|
};
|
|
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
const handleBatchDelete = async () => {
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '批量删除确认',
|
|
|
|
|
content: `确定要删除选中的 ${selectedDevices.length} 个设备吗?此操作不可恢复!`,
|
|
|
|
|
okText: '确认删除',
|
|
|
|
|
okType: 'danger',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
2026-03-13 15:13:58 +08:00
|
|
|
const response = await axios.post('/api/devices/batch-delete', {
|
|
|
|
|
deviceIds: selectedDevices,
|
2025-12-18 19:11:56 +08:00
|
|
|
});
|
|
|
|
|
message.success(response.data.message || '批量删除成功');
|
|
|
|
|
setSelectedDevices([]);
|
|
|
|
|
setSelectAll(false);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, 50);
|
2025-12-18 19:11:56 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('批量删除失败');
|
|
|
|
|
console.error('批量删除设备失败:', error);
|
2026-03-13 15:13:58 +08:00
|
|
|
// 显示更具体的错误信息
|
|
|
|
|
if (error.response?.data?.error) {
|
|
|
|
|
console.error('后端错误详情:', error.response.data.error);
|
|
|
|
|
}
|
2025-12-18 19:11:56 +08:00
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
},
|
2025-12-18 19:11:56 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-09 16:22:00 +08:00
|
|
|
const handleDeleteAll = async () => {
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '危险操作确认',
|
2026-02-10 11:04:01 +08:00
|
|
|
content:
|
|
|
|
|
'确定要删除所有设备吗?此操作将清空所有设备数据,包括相关的接线、网卡、端口等信息,且不可恢复!',
|
2026-02-09 16:22:00 +08:00
|
|
|
okText: '确认删除所有',
|
|
|
|
|
okType: 'danger',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.delete('/api/devices/delete-all');
|
|
|
|
|
message.success(response.data.message || '成功删除所有设备');
|
|
|
|
|
setSelectedDevices([]);
|
|
|
|
|
setSelectAll(false);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, 50);
|
2026-02-09 16:22:00 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('删除所有设备失败');
|
|
|
|
|
console.error('删除所有设备失败:', error);
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
},
|
2026-02-09 16:22:00 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-20 17:15:14 +08:00
|
|
|
const handleBatchToIdle = async () => {
|
|
|
|
|
if (selectedDevices.length === 0) {
|
|
|
|
|
message.warning('请先选择要标记为空闲的设备');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '确认标记为空闲',
|
|
|
|
|
content: `确定要将选中的 ${selectedDevices.length} 个设备标记为空闲设备吗?`,
|
|
|
|
|
okText: '确认',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.post('/api/idle-devices/batch-from-devices', {
|
|
|
|
|
deviceIds: selectedDevices,
|
|
|
|
|
idleReason: '从设备管理批量转入',
|
|
|
|
|
});
|
|
|
|
|
message.success(response.data.message || '设备已标记为空闲');
|
|
|
|
|
setSelectedDevices([]);
|
|
|
|
|
setSelectAll(false);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, 50);
|
2026-03-20 17:15:14 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error(error.response?.data?.error || '标记为空闲失败');
|
|
|
|
|
console.error('标记为空闲失败:', error);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleDelete = async deviceId => {
|
2025-12-18 10:45:13 +08:00
|
|
|
Modal.confirm({
|
|
|
|
|
title: '确认删除',
|
|
|
|
|
content: '确定要删除这个设备吗?',
|
|
|
|
|
okText: '删除',
|
|
|
|
|
okType: 'danger',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
await axios.delete(`/api/devices/${deviceId}`);
|
|
|
|
|
message.success('设备删除成功');
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, pagination.pageSize);
|
2025-12-18 10:45:13 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('设备删除失败');
|
|
|
|
|
console.error('设备删除失败:', error);
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
},
|
2025-12-18 10:45:13 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleShowDetail = device => {
|
2025-12-19 15:05:31 +08:00
|
|
|
setSelectedDevice(device);
|
|
|
|
|
setDetailModalVisible(true);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleViewDeviceTickets = device => {
|
2026-03-10 14:34:39 +08:00
|
|
|
navigate(
|
|
|
|
|
`/tickets?deviceId=${device.deviceId}&deviceName=${encodeURIComponent(device.name)}&serialNumber=${encodeURIComponent(device.serialNumber || '')}&view=true`
|
|
|
|
|
);
|
2026-02-12 13:27:32 +08:00
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleCreateTicketForDevice = device => {
|
2026-03-10 14:34:39 +08:00
|
|
|
navigate(
|
|
|
|
|
`/tickets?deviceId=${device.deviceId}&deviceName=${encodeURIComponent(device.name)}&serialNumber=${encodeURIComponent(device.serialNumber || '')}&create=true`
|
|
|
|
|
);
|
2026-02-12 13:27:32 +08:00
|
|
|
};
|
|
|
|
|
|
2025-12-29 16:10:42 +08:00
|
|
|
const showBatchStatusModal = () => {
|
|
|
|
|
if (selectedDevices.length === 0) {
|
|
|
|
|
message.warning('请先选择要操作的设备');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setBatchStatusModalVisible(true);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleBatchStatusChange = async newStatus => {
|
2026-03-10 14:34:39 +08:00
|
|
|
setBatchStatusLoading(true);
|
2025-12-18 19:11:56 +08:00
|
|
|
try {
|
2025-12-29 16:10:42 +08:00
|
|
|
const response = await axios.put('/api/devices/batch-status', {
|
|
|
|
|
deviceIds: selectedDevices,
|
2026-03-10 14:34:39 +08:00
|
|
|
status: newStatus,
|
2025-12-29 16:10:42 +08:00
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 16:10:42 +08:00
|
|
|
message.success(response.data.message || '批量状态变更成功');
|
|
|
|
|
setBatchStatusModalVisible(false);
|
|
|
|
|
setSelectedDevices([]);
|
|
|
|
|
setSelectAll(false);
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, pagination.pageSize);
|
2025-12-29 16:10:42 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
message.error('批量状态变更失败');
|
|
|
|
|
console.error('批量状态变更失败:', error);
|
|
|
|
|
} finally {
|
|
|
|
|
setBatchStatusLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const showExportModal = () => {
|
|
|
|
|
if (selectedDevices.length === 0) {
|
|
|
|
|
message.warning('请先选择要导出的设备');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setExportModalVisible(true);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-23 14:07:40 +08:00
|
|
|
const handleEnhancedExport = async ({ format, scope }) => {
|
2026-03-10 14:34:39 +08:00
|
|
|
let deviceIds = [];
|
|
|
|
|
if (scope === 'selected') {
|
|
|
|
|
deviceIds = selectedDevices;
|
|
|
|
|
} else if (scope === 'currentPage') {
|
2026-04-01 07:44:57 +00:00
|
|
|
deviceIds = allDevices.map(device => device.deviceId);
|
2026-03-10 14:34:39 +08:00
|
|
|
} else if (scope === 'all') {
|
2026-03-27 19:12:16 +08:00
|
|
|
deviceIds = allDevices.map(device => device.deviceId);
|
2026-03-10 14:34:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceIds.length === 0) {
|
|
|
|
|
message.warning('没有可导出的设备');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const params = new URLSearchParams();
|
2026-03-27 19:12:16 +08:00
|
|
|
deviceIds.forEach(id => params.append('deviceIds', id));
|
2026-03-10 14:34:39 +08:00
|
|
|
params.append('format', format);
|
|
|
|
|
|
|
|
|
|
const response = await axios.get(`/api/devices/enhanced-export?${params.toString()}`, {
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const contentType = format === 'csv' ? 'text/csv; charset=gbk' : 'application/json';
|
|
|
|
|
const blob = new Blob([response.data], { type: contentType });
|
|
|
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = url;
|
|
|
|
|
link.download = `devices_export_${new Date().toISOString().split('T')[0]}.${format}`;
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
link.click();
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
|
|
|
|
|
|
message.success(`成功导出 ${deviceIds.length} 个设备`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleImport = async (file, callbacks) => {
|
2025-12-29 16:10:42 +08:00
|
|
|
try {
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onProgress(0, '正在上传文件...');
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('csvFile', file);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
const response = await axios.post('/api/devices/import', formData, {
|
|
|
|
|
headers: {
|
2026-02-10 11:04:01 +08:00
|
|
|
'Content-Type': 'multipart/form-data',
|
2025-12-29 12:08:05 +08:00
|
|
|
},
|
2026-03-27 19:12:16 +08:00
|
|
|
onUploadProgress: progressEvent => {
|
2025-12-29 12:08:05 +08:00
|
|
|
const progress = Math.round((progressEvent.loaded * 50) / progressEvent.total);
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onProgress(Math.min(progress, 50), '正在上传文件...');
|
2026-02-10 11:04:01 +08:00
|
|
|
},
|
2025-12-18 19:11:56 +08:00
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onProgress(60, '正在处理数据...');
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 12:08:05 +08:00
|
|
|
setTimeout(() => {
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onProgress(80, '正在验证数据...');
|
2025-12-29 12:08:05 +08:00
|
|
|
}, 200);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 12:08:05 +08:00
|
|
|
setTimeout(() => {
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onProgress(90, '正在保存数据...');
|
2025-12-29 12:08:05 +08:00
|
|
|
}, 400);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onSuccess(response.data);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 13:21:39 +08:00
|
|
|
const { success, failed } = response.data.statistics;
|
|
|
|
|
if (failed > 0) {
|
|
|
|
|
message.warning(`导入完成,但有 ${failed} 条记录导入失败`);
|
|
|
|
|
} else {
|
|
|
|
|
message.success('所有记录导入成功');
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 19:11:56 +08:00
|
|
|
setTimeout(() => {
|
2026-04-01 07:44:57 +00:00
|
|
|
fetchDevices(1, pagination.pageSize);
|
2025-12-18 19:11:56 +08:00
|
|
|
}, 1000);
|
|
|
|
|
} catch (error) {
|
2025-12-29 12:08:05 +08:00
|
|
|
let errorMessage = '导入失败';
|
|
|
|
|
let errorDetails = [];
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 12:08:05 +08:00
|
|
|
if (error.response) {
|
2025-12-30 14:01:16 +08:00
|
|
|
const { data, status } = error.response;
|
2026-02-10 11:04:01 +08:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
status === 500 &&
|
|
|
|
|
data &&
|
|
|
|
|
data.errors &&
|
|
|
|
|
Array.isArray(data.errors) &&
|
|
|
|
|
data.errors.length > 0
|
|
|
|
|
) {
|
2026-03-27 19:12:16 +08:00
|
|
|
errorDetails = data.errors.map(err => ({
|
2025-12-30 14:01:16 +08:00
|
|
|
row: err.row || 0,
|
2026-02-10 11:04:01 +08:00
|
|
|
error: err.error || err.message || '服务器内部错误',
|
2025-12-30 14:01:16 +08:00
|
|
|
}));
|
|
|
|
|
errorMessage = `导入失败:${errorDetails[0].error}`;
|
|
|
|
|
} else if (data && data.errors && Array.isArray(data.errors)) {
|
2025-12-29 12:08:05 +08:00
|
|
|
errorDetails = data.errors.map((err, index) => ({
|
|
|
|
|
row: err.row || index + 1,
|
2026-02-10 11:04:01 +08:00
|
|
|
error: err.error || err.message || '未知错误',
|
2025-12-29 12:08:05 +08:00
|
|
|
}));
|
|
|
|
|
errorMessage = `导入失败,共发现 ${errorDetails.length} 处数据错误`;
|
2025-12-30 14:01:16 +08:00
|
|
|
} else if (data && (data.message || data.error)) {
|
|
|
|
|
errorMessage = data.message || data.error;
|
2025-12-29 12:08:05 +08:00
|
|
|
}
|
|
|
|
|
} else if (error.message) {
|
|
|
|
|
errorMessage = error.message;
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
callbacks.onError({
|
|
|
|
|
message: errorMessage,
|
|
|
|
|
errors: errorDetails,
|
2025-12-29 12:08:05 +08:00
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-29 12:08:05 +08:00
|
|
|
message.error(errorMessage);
|
2025-12-18 19:11:56 +08:00
|
|
|
console.error('导入设备失败:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleSaveFieldConfig = async updatedFields => {
|
2026-03-10 14:34:39 +08:00
|
|
|
try {
|
|
|
|
|
const response = await axios.post('/api/deviceFields/config', updatedFields);
|
|
|
|
|
setDeviceFields(response.data);
|
|
|
|
|
message.success('字段配置保存成功');
|
|
|
|
|
setFieldConfigModalVisible(false);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
message.error('字段配置保存失败');
|
|
|
|
|
console.error('保存字段配置失败:', error);
|
|
|
|
|
}
|
2025-12-19 15:05:31 +08:00
|
|
|
};
|
|
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleResetFieldConfig = defaultFields => {
|
2026-03-10 14:34:39 +08:00
|
|
|
setDeviceFields(defaultFields);
|
2025-12-19 15:05:31 +08:00
|
|
|
};
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleSelectionChange = selectedRowKeys => {
|
2026-03-10 14:34:39 +08:00
|
|
|
setSelectedDevices(selectedRowKeys);
|
|
|
|
|
setSelectAll(selectedRowKeys.length === allDevices.length && allDevices.length > 0);
|
2025-12-19 15:05:31 +08:00
|
|
|
};
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
const handleHeaderCellResize = key => column => ({
|
2025-12-19 15:05:31 +08:00
|
|
|
width: column.width,
|
2026-03-27 19:12:16 +08:00
|
|
|
onResize: width => {
|
|
|
|
|
setColumnWidths(prev => ({ ...prev, [key]: width }));
|
2025-12-29 16:10:42 +08:00
|
|
|
},
|
2025-12-19 15:05:31 +08:00
|
|
|
});
|
2025-12-29 16:10:42 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
const columns = useMemo(() => {
|
2025-12-18 10:45:13 +08:00
|
|
|
const generatedColumns = [];
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-27 19:12:16 +08:00
|
|
|
deviceFields.forEach(field => {
|
2025-12-18 19:11:56 +08:00
|
|
|
if (!field.visible) return;
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
if (field.fieldName === 'rackId') {
|
2025-12-18 19:11:56 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: '所在机房',
|
|
|
|
|
dataIndex: ['Rack', 'Room', 'name'],
|
|
|
|
|
key: 'roomName',
|
2025-12-19 15:05:31 +08:00
|
|
|
width: columnWidths.roomName || 120,
|
|
|
|
|
onHeaderCell: handleHeaderCellResize('roomName'),
|
2025-12-18 19:11:56 +08:00
|
|
|
});
|
2025-12-18 10:45:13 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: field.displayName,
|
|
|
|
|
dataIndex: ['Rack', 'name'],
|
|
|
|
|
key: field.fieldName,
|
2025-12-19 15:05:31 +08:00
|
|
|
width: columnWidths[field.fieldName] || 120,
|
|
|
|
|
onHeaderCell: handleHeaderCellResize(field.fieldName),
|
2025-12-18 10:45:13 +08:00
|
|
|
});
|
2026-03-10 14:34:39 +08:00
|
|
|
} else if (field.fieldName === 'type') {
|
2025-12-18 10:45:13 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: field.displayName,
|
|
|
|
|
dataIndex: field.fieldName,
|
|
|
|
|
key: field.fieldName,
|
2025-12-19 15:05:31 +08:00
|
|
|
width: columnWidths[field.fieldName] || 100,
|
|
|
|
|
onHeaderCell: handleHeaderCellResize(field.fieldName),
|
2026-03-27 19:12:16 +08:00
|
|
|
render: type => (
|
2026-03-10 14:34:39 +08:00
|
|
|
<Space>
|
|
|
|
|
{getDeviceTypeIcon(type)}
|
|
|
|
|
<span>{TYPE_MAP[type]}</span>
|
|
|
|
|
</Space>
|
|
|
|
|
),
|
2025-12-18 10:45:13 +08:00
|
|
|
});
|
2026-03-10 14:34:39 +08:00
|
|
|
} else if (field.fieldName === 'status') {
|
2025-12-18 10:45:13 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: field.displayName,
|
|
|
|
|
dataIndex: field.fieldName,
|
|
|
|
|
key: field.fieldName,
|
2026-03-24 14:54:39 +08:00
|
|
|
width: columnWidths[field.fieldName] || 90,
|
2025-12-19 15:05:31 +08:00
|
|
|
onHeaderCell: handleHeaderCellResize(field.fieldName),
|
2026-03-27 19:12:16 +08:00
|
|
|
render: status => {
|
2026-03-20 17:15:14 +08:00
|
|
|
const config = STATUS_MAP[status] || { text: status, color: 'default' };
|
|
|
|
|
const statusStyles = {
|
|
|
|
|
running: { bg: '#f6ffed', border: '#52c41a', text: '#389e0d' },
|
|
|
|
|
maintenance: { bg: '#fffbE6', border: '#faad14', text: '#d48806' },
|
|
|
|
|
offline: { bg: '#f5f5f5', border: '#8c8c8c', text: '#595959' },
|
|
|
|
|
fault: { bg: '#fff2f0', border: '#ff4d4f', text: '#cf1322' },
|
2026-03-24 14:54:39 +08:00
|
|
|
idle: { bg: '#E6FFFA', border: '#36cfc9', text: '#08979d' },
|
2026-03-20 17:15:14 +08:00
|
|
|
};
|
2026-03-27 19:12:16 +08:00
|
|
|
const style = statusStyles[status] || {
|
|
|
|
|
bg: '#fafafa',
|
|
|
|
|
border: '#d9d9d9',
|
|
|
|
|
text: '#595959',
|
|
|
|
|
};
|
2025-12-19 13:21:39 +08:00
|
|
|
return (
|
2026-03-20 17:15:14 +08:00
|
|
|
<Tag
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: style.bg,
|
|
|
|
|
borderColor: style.border,
|
|
|
|
|
color: style.text,
|
|
|
|
|
borderRadius: '4px',
|
|
|
|
|
fontWeight: 500,
|
|
|
|
|
boxShadow: `0 1px 2px ${style.border}30`,
|
2026-03-24 14:54:39 +08:00
|
|
|
minWidth: '80px',
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
padding: '2px 8px',
|
|
|
|
|
display: 'block',
|
2026-03-20 17:15:14 +08:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{config.text}
|
|
|
|
|
</Tag>
|
2025-12-19 13:21:39 +08:00
|
|
|
);
|
|
|
|
|
},
|
2025-12-18 10:45:13 +08:00
|
|
|
});
|
2026-03-10 14:34:39 +08:00
|
|
|
} else if (field.fieldType === 'date') {
|
2025-12-18 10:45:13 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: field.displayName,
|
|
|
|
|
dataIndex: field.fieldName,
|
|
|
|
|
key: field.fieldName,
|
2025-12-19 15:05:31 +08:00
|
|
|
width: columnWidths[field.fieldName] || 120,
|
|
|
|
|
onHeaderCell: handleHeaderCellResize(field.fieldName),
|
2026-03-27 19:12:16 +08:00
|
|
|
render: date => {
|
2025-12-19 13:21:39 +08:00
|
|
|
if (!date) return '';
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 13:21:39 +08:00
|
|
|
const dateObj = new Date(date);
|
|
|
|
|
const formattedDate = dateObj.toLocaleDateString('zh-CN');
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 13:21:39 +08:00
|
|
|
if (field.fieldName === 'warrantyExpiry') {
|
|
|
|
|
const today = new Date();
|
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
dateObj.setHours(0, 0, 0, 0);
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 13:21:39 +08:00
|
|
|
if (dateObj < today) {
|
2026-02-10 11:04:01 +08:00
|
|
|
return (
|
|
|
|
|
<span style={{ color: '#d93025', fontWeight: 'bold' }}>{formattedDate}</span>
|
|
|
|
|
);
|
2025-12-19 13:21:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 13:21:39 +08:00
|
|
|
return formattedDate;
|
|
|
|
|
},
|
2025-12-18 10:45:13 +08:00
|
|
|
});
|
2026-03-10 14:34:39 +08:00
|
|
|
} else {
|
2025-12-19 15:05:31 +08:00
|
|
|
let defaultWidth = 120;
|
|
|
|
|
if (field.fieldName === 'deviceId' || field.fieldName === 'name') {
|
|
|
|
|
defaultWidth = 150;
|
|
|
|
|
} else if (field.fieldName === 'description') {
|
|
|
|
|
defaultWidth = 200;
|
|
|
|
|
} else if (field.fieldType === 'number') {
|
|
|
|
|
defaultWidth = 80;
|
|
|
|
|
} else if (field.fieldType === 'textarea') {
|
|
|
|
|
defaultWidth = 180;
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 15:05:31 +08:00
|
|
|
const columnConfig = {
|
2025-12-18 10:45:13 +08:00
|
|
|
title: field.displayName,
|
|
|
|
|
dataIndex: field.fieldName,
|
|
|
|
|
key: field.fieldName,
|
2025-12-19 15:05:31 +08:00
|
|
|
width: columnWidths[field.fieldName] || defaultWidth,
|
2025-12-29 16:10:42 +08:00
|
|
|
minWidth: 80,
|
|
|
|
|
maxWidth: field.fieldType === 'textarea' ? 300 : 200,
|
2025-12-19 15:05:31 +08:00
|
|
|
onHeaderCell: handleHeaderCellResize(field.fieldName),
|
2025-12-29 16:10:42 +08:00
|
|
|
ellipsis: field.fieldType !== 'textarea',
|
2025-12-19 15:05:31 +08:00
|
|
|
};
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 15:05:31 +08:00
|
|
|
if (field.fieldName === 'deviceId' || field.fieldName === 'name') {
|
|
|
|
|
columnConfig.render = (value, record) => (
|
2026-02-10 11:04:01 +08:00
|
|
|
<a
|
2025-12-19 15:05:31 +08:00
|
|
|
onClick={() => handleShowDetail(record)}
|
2026-02-10 11:04:01 +08:00
|
|
|
style={{
|
|
|
|
|
color: '#1890ff',
|
2025-12-19 15:05:31 +08:00
|
|
|
textDecoration: 'none',
|
2025-12-29 16:10:42 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
|
display: 'block',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
whiteSpace: 'nowrap',
|
2025-12-19 15:05:31 +08:00
|
|
|
}}
|
2026-03-27 19:12:16 +08:00
|
|
|
onMouseEnter={e => (e.target.style.textDecoration = 'underline')}
|
|
|
|
|
onMouseLeave={e => (e.target.style.textDecoration = 'none')}
|
2025-12-19 15:05:31 +08:00
|
|
|
>
|
|
|
|
|
{value || '-'}
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-19 15:05:31 +08:00
|
|
|
generatedColumns.push(columnConfig);
|
2025-12-18 10:45:13 +08:00
|
|
|
}
|
|
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
generatedColumns.push({
|
|
|
|
|
title: '操作',
|
|
|
|
|
key: 'action',
|
2025-12-29 16:10:42 +08:00
|
|
|
width: columnWidths.action || 80,
|
|
|
|
|
minWidth: 60,
|
|
|
|
|
maxWidth: 100,
|
2025-12-19 15:05:31 +08:00
|
|
|
onHeaderCell: handleHeaderCellResize('action'),
|
2025-12-18 10:45:13 +08:00
|
|
|
render: (_, record) => (
|
2025-12-29 16:10:42 +08:00
|
|
|
<div style={{ display: 'flex', gap: '4px' }}>
|
|
|
|
|
<Tooltip title="编辑">
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
icon={<EditOutlined />}
|
|
|
|
|
onClick={() => showModal(record)}
|
|
|
|
|
size="small"
|
|
|
|
|
style={{ color: '#1890ff', padding: '4px 8px' }}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title="删除">
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
danger
|
|
|
|
|
icon={<DeleteOutlined />}
|
|
|
|
|
onClick={() => handleDelete(record.deviceId)}
|
|
|
|
|
size="small"
|
|
|
|
|
style={{ padding: '4px 8px' }}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2025-12-18 10:45:13 +08:00
|
|
|
),
|
|
|
|
|
});
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2025-12-18 10:45:13 +08:00
|
|
|
return generatedColumns;
|
2025-12-19 15:05:31 +08:00
|
|
|
}, [deviceFields, columnWidths]);
|
2025-12-18 10:45:13 +08:00
|
|
|
|
|
|
|
|
return (
|
2026-01-20 11:28:53 +08:00
|
|
|
<div style={pageContainerStyle}>
|
2026-02-10 09:32:16 +08:00
|
|
|
<style>{generateGlobalStyles(designTokens)}</style>
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-01-20 11:28:53 +08:00
|
|
|
<div style={headerStyle}>
|
|
|
|
|
<div style={titleRowStyle}>
|
|
|
|
|
<div style={titleSectionStyle}>
|
|
|
|
|
<div style={titleIconStyle}>
|
|
|
|
|
<CloudServerOutlined style={{ fontSize: '20px', color: '#ffffff' }} />
|
|
|
|
|
</div>
|
|
|
|
|
<div style={titleTextStyle}>
|
|
|
|
|
<h1 style={pageTitleStyle}>设备管理</h1>
|
|
|
|
|
<p style={pageSubtitleStyle}>管理您的IT设备资产</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-01-20 11:28:53 +08:00
|
|
|
<div style={{ display: 'flex', gap: designTokens.spacing.sm, flexWrap: 'wrap' }}>
|
|
|
|
|
<Button
|
2026-02-06 09:53:59 +08:00
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
|
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-02-06 09:53:59 +08:00
|
|
|
}}
|
2026-01-20 11:28:53 +08:00
|
|
|
icon={<PlusOutlined />}
|
|
|
|
|
onClick={() => showModal()}
|
|
|
|
|
>
|
|
|
|
|
添加设备
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-06 09:53:59 +08:00
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
|
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-02-06 09:53:59 +08:00
|
|
|
}}
|
2026-01-20 11:28:53 +08:00
|
|
|
icon={<UploadOutlined />}
|
|
|
|
|
onClick={() => setImportModalVisible(true)}
|
|
|
|
|
>
|
|
|
|
|
导入
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-06 09:53:59 +08:00
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
|
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-02-06 09:53:59 +08:00
|
|
|
}}
|
2026-01-20 11:28:53 +08:00
|
|
|
icon={<ExportOutlined />}
|
|
|
|
|
onClick={showExportModal}
|
|
|
|
|
>
|
|
|
|
|
导出
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-06 09:53:59 +08:00
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
|
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-02-06 09:53:59 +08:00
|
|
|
}}
|
2026-01-20 11:28:53 +08:00
|
|
|
icon={<SettingOutlined />}
|
|
|
|
|
onClick={() => setFieldConfigModalVisible(true)}
|
|
|
|
|
>
|
|
|
|
|
字段配置
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
2026-02-06 09:53:59 +08:00
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-01-20 11:28:53 +08:00
|
|
|
}}
|
|
|
|
|
icon={<ReloadOutlined />}
|
|
|
|
|
disabled={selectedDevices.length === 0}
|
|
|
|
|
onClick={showBatchStatusModal}
|
|
|
|
|
>
|
|
|
|
|
状态变更 ({selectedDevices.length})
|
|
|
|
|
</Button>
|
2026-03-20 17:15:14 +08:00
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
|
|
|
|
color: '#f59e0b',
|
|
|
|
|
borderColor: '#f59e0b',
|
|
|
|
|
}}
|
|
|
|
|
icon={<CloudServerOutlined />}
|
|
|
|
|
disabled={selectedDevices.length === 0}
|
|
|
|
|
onClick={handleBatchToIdle}
|
|
|
|
|
>
|
|
|
|
|
标记为空闲 ({selectedDevices.length})
|
|
|
|
|
</Button>
|
2026-01-20 11:28:53 +08:00
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
...secondaryActionStyle,
|
2026-02-06 09:53:59 +08:00
|
|
|
color: designTokens.colors.primary.main,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderColor: designTokens.colors.primary.main,
|
2026-01-20 11:28:53 +08:00
|
|
|
}}
|
|
|
|
|
icon={<DeleteOutlined />}
|
|
|
|
|
disabled={selectedDevices.length === 0}
|
|
|
|
|
onClick={handleBatchDelete}
|
|
|
|
|
>
|
|
|
|
|
批量删除 ({selectedDevices.length})
|
|
|
|
|
</Button>
|
2026-02-09 16:22:00 +08:00
|
|
|
<Button
|
2026-02-12 15:13:38 +08:00
|
|
|
type="primary"
|
|
|
|
|
danger
|
2026-02-10 09:32:16 +08:00
|
|
|
style={{
|
|
|
|
|
height: '36px',
|
|
|
|
|
borderRadius: designTokens.borderRadius.small,
|
|
|
|
|
fontSize: '13px',
|
|
|
|
|
fontWeight: '500',
|
|
|
|
|
display: 'inline-flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: '6px',
|
|
|
|
|
}}
|
2026-02-09 16:22:00 +08:00
|
|
|
icon={<DeleteOutlined />}
|
|
|
|
|
onClick={handleDeleteAll}
|
|
|
|
|
>
|
|
|
|
|
删除所有
|
|
|
|
|
</Button>
|
2026-01-20 11:28:53 +08:00
|
|
|
</div>
|
2025-12-29 16:10:42 +08:00
|
|
|
</div>
|
2025-12-29 11:15:55 +08:00
|
|
|
</div>
|
2025-12-18 19:11:56 +08:00
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
<Card
|
|
|
|
|
size="small"
|
|
|
|
|
style={filterCardStyle}
|
|
|
|
|
styles={{
|
|
|
|
|
body: {
|
|
|
|
|
padding: `${designTokens.spacing.md}px ${designTokens.spacing.lg}px`,
|
|
|
|
|
display: 'flex',
|
2026-03-24 14:54:39 +08:00
|
|
|
flexDirection: 'column',
|
2026-02-10 11:04:01 +08:00
|
|
|
gap: designTokens.spacing.md,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-12-29 11:15:55 +08:00
|
|
|
<Form
|
|
|
|
|
form={searchForm}
|
|
|
|
|
layout="inline"
|
|
|
|
|
onFinish={handleSearch}
|
2026-03-24 14:54:39 +08:00
|
|
|
style={{ width: '100%' }}
|
2026-01-20 11:28:53 +08:00
|
|
|
className="filter-form"
|
2025-12-29 11:15:55 +08:00
|
|
|
>
|
2026-03-27 19:12:16 +08:00
|
|
|
<div
|
|
|
|
|
style={{
|
2026-03-24 14:54:39 +08:00
|
|
|
display: 'flex',
|
2026-03-27 19:12:16 +08:00
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
gap: designTokens.spacing.md,
|
2026-03-24 14:54:39 +08:00
|
|
|
alignItems: 'center',
|
2026-03-27 19:12:16 +08:00
|
|
|
width: '100%',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: designTokens.spacing.sm,
|
|
|
|
|
padding: '0 12px',
|
|
|
|
|
borderRight: `1px solid ${designTokens.colors.border.light}`,
|
|
|
|
|
marginRight: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FilterOutlined
|
|
|
|
|
style={{ color: designTokens.colors.primary.main, fontSize: '16px' }}
|
|
|
|
|
/>
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: '13px',
|
|
|
|
|
fontWeight: 500,
|
|
|
|
|
color: designTokens.colors.text.secondary,
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
筛选
|
|
|
|
|
</span>
|
2026-03-24 14:54:39 +08:00
|
|
|
</div>
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-24 14:54:39 +08:00
|
|
|
<Form.Item name="keyword" style={{ margin: 0 }}>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="搜索设备名称、型号、序列号..."
|
|
|
|
|
prefix={<SearchOutlined style={{ color: designTokens.colors.primary.main }} />}
|
2026-01-20 11:28:53 +08:00
|
|
|
style={{
|
2026-03-24 14:54:39 +08:00
|
|
|
width: '280px',
|
2026-01-20 11:28:53 +08:00
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
2026-02-10 11:04:01 +08:00
|
|
|
border: `1px solid ${designTokens.colors.border.light}`,
|
2026-03-24 14:54:39 +08:00
|
|
|
transition: `all ${designTokens.transitions.fast}`,
|
2026-01-20 11:28:53 +08:00
|
|
|
}}
|
2026-03-24 14:54:39 +08:00
|
|
|
value={keyword}
|
2026-03-27 19:12:16 +08:00
|
|
|
onChange={e => setKeyword(e.target.value)}
|
2026-03-24 14:54:39 +08:00
|
|
|
allowClear
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
2026-02-10 11:04:01 +08:00
|
|
|
|
2026-03-24 14:54:39 +08:00
|
|
|
<Form.Item name="status" style={{ margin: 0 }}>
|
|
|
|
|
<Select
|
|
|
|
|
value={status}
|
|
|
|
|
onChange={setStatus}
|
|
|
|
|
style={{ width: '140px', borderRadius: designTokens.borderRadius.medium }}
|
|
|
|
|
suffixIcon={<ToolOutlined style={{ color: '#10b981' }} />}
|
|
|
|
|
>
|
|
|
|
|
<Option value="all">所有状态</Option>
|
|
|
|
|
<Option value="running">运行中</Option>
|
|
|
|
|
<Option value="maintenance">维护中</Option>
|
|
|
|
|
<Option value="offline">离线</Option>
|
|
|
|
|
<Option value="fault">故障</Option>
|
|
|
|
|
<Option value="idle">空闲</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item name="type" style={{ margin: 0 }}>
|
|
|
|
|
<Select
|
|
|
|
|
value={type}
|
|
|
|
|
onChange={setType}
|
|
|
|
|
style={{ width: '140px', borderRadius: designTokens.borderRadius.medium }}
|
|
|
|
|
suffixIcon={<AppstoreOutlined style={{ color: '#8b5cf6' }} />}
|
|
|
|
|
>
|
|
|
|
|
<Option value="all">所有类型</Option>
|
|
|
|
|
<Option value="server">服务器</Option>
|
|
|
|
|
<Option value="switch">交换机</Option>
|
|
|
|
|
<Option value="router">路由器</Option>
|
|
|
|
|
<Option value="storage">存储设备</Option>
|
|
|
|
|
<Option value="other">其他设备</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
icon={advancedSearchVisible ? <UnorderedListOutlined /> : <UnorderedListOutlined />}
|
|
|
|
|
onClick={() => setAdvancedSearchVisible(!advancedSearchVisible)}
|
|
|
|
|
style={{
|
|
|
|
|
height: '36px',
|
|
|
|
|
padding: '0 12px',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: '6px',
|
2026-03-27 19:12:16 +08:00
|
|
|
color: advancedSearchVisible
|
|
|
|
|
? designTokens.colors.primary.main
|
|
|
|
|
: designTokens.colors.text.secondary,
|
2026-03-24 14:54:39 +08:00
|
|
|
fontWeight: 500,
|
|
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
2026-03-27 19:12:16 +08:00
|
|
|
background: advancedSearchVisible
|
|
|
|
|
? `${designTokens.colors.primary.main}10`
|
|
|
|
|
: 'transparent',
|
2026-03-24 14:54:39 +08:00
|
|
|
transition: `all ${designTokens.transitions.fast}`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
高级筛选 {advancedSearchVisible ? '▲' : '▼'}
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<div style={{ marginLeft: 'auto', display: 'flex', gap: designTokens.spacing.sm }}>
|
|
|
|
|
<Space>
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
style={{
|
|
|
|
|
height: '36px',
|
|
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
|
|
|
|
background: designTokens.colors.primary.gradient,
|
|
|
|
|
border: 'none',
|
|
|
|
|
boxShadow: designTokens.shadows.small,
|
|
|
|
|
}}
|
|
|
|
|
icon={<SearchOutlined />}
|
|
|
|
|
htmlType="submit"
|
|
|
|
|
loading={searching}
|
|
|
|
|
>
|
|
|
|
|
搜索
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
height: '36px',
|
|
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
|
|
|
|
border: `1px solid ${designTokens.colors.border.light}`,
|
|
|
|
|
}}
|
|
|
|
|
onClick={handleReset}
|
|
|
|
|
>
|
|
|
|
|
重置
|
|
|
|
|
</Button>
|
|
|
|
|
</Space>
|
|
|
|
|
<Button
|
|
|
|
|
icon={<ReloadOutlined />}
|
2026-04-01 07:44:57 +00:00
|
|
|
onClick={() => fetchDevices(1, pagination.pageSize)}
|
2026-03-24 14:54:39 +08:00
|
|
|
style={{
|
|
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
|
|
|
|
border: `1px solid ${designTokens.colors.border.light}`,
|
|
|
|
|
height: '36px',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
刷新
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{advancedSearchVisible && (
|
2026-03-27 19:12:16 +08:00
|
|
|
<div
|
|
|
|
|
style={{
|
2026-03-24 14:54:39 +08:00
|
|
|
display: 'flex',
|
2026-03-27 19:12:16 +08:00
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
gap: designTokens.spacing.md,
|
|
|
|
|
padding: `${designTokens.spacing.md}px 0`,
|
|
|
|
|
borderTop: `1px dashed ${designTokens.colors.border.light}`,
|
|
|
|
|
marginTop: designTokens.spacing.sm,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
gap: designTokens.spacing.sm,
|
|
|
|
|
padding: '0 12px',
|
|
|
|
|
borderRight: `1px solid ${designTokens.colors.border.light}`,
|
|
|
|
|
marginRight: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-03-24 14:54:39 +08:00
|
|
|
<EnvironmentOutlined style={{ color: '#3b82f6', fontSize: '16px' }} />
|
2026-03-27 19:12:16 +08:00
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: '13px',
|
|
|
|
|
fontWeight: 500,
|
|
|
|
|
color: designTokens.colors.text.secondary,
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
位置筛选
|
|
|
|
|
</span>
|
2026-03-24 14:54:39 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Form.Item name="roomId" style={{ margin: 0 }}>
|
|
|
|
|
<Select
|
|
|
|
|
value={roomId}
|
2026-03-27 19:12:16 +08:00
|
|
|
onChange={value => {
|
2026-03-24 14:54:39 +08:00
|
|
|
setRoomId(value);
|
|
|
|
|
setRackId('all');
|
|
|
|
|
}}
|
|
|
|
|
style={{ width: '160px', borderRadius: designTokens.borderRadius.medium }}
|
|
|
|
|
placeholder="选择机房"
|
|
|
|
|
suffixIcon={<EnvironmentOutlined style={{ color: '#3b82f6' }} />}
|
|
|
|
|
>
|
|
|
|
|
<Option value="all">所有机房</Option>
|
2026-03-27 19:12:16 +08:00
|
|
|
{rooms.map(room => (
|
2026-03-24 14:54:39 +08:00
|
|
|
<Option key={room.roomId} value={room.roomId}>
|
|
|
|
|
{room.name}
|
|
|
|
|
</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item name="rackId" style={{ margin: 0 }}>
|
|
|
|
|
<Select
|
|
|
|
|
value={rackId}
|
|
|
|
|
onChange={setRackId}
|
|
|
|
|
style={{ width: '160px', borderRadius: designTokens.borderRadius.medium }}
|
|
|
|
|
placeholder="选择机柜"
|
|
|
|
|
showSearch
|
|
|
|
|
optionFilterProp="children"
|
|
|
|
|
suffixIcon={<EnvironmentOutlined style={{ color: '#f59e0b' }} />}
|
|
|
|
|
>
|
|
|
|
|
<Option value="all">所有机柜</Option>
|
|
|
|
|
{racks
|
2026-03-27 19:12:16 +08:00
|
|
|
.filter(rack => roomId === 'all' || rack.roomId === roomId)
|
|
|
|
|
.map(rack => (
|
2026-03-24 14:54:39 +08:00
|
|
|
<Option key={rack.rackId} value={rack.rackId}>
|
|
|
|
|
{rack.name}
|
|
|
|
|
</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Form>
|
2025-12-29 11:15:55 +08:00
|
|
|
</Card>
|
2025-12-18 19:11:56 +08:00
|
|
|
|
2025-12-29 11:15:55 +08:00
|
|
|
<Card style={cardStyle}>
|
2026-03-10 14:34:39 +08:00
|
|
|
{!loading && allDevices.length === 0 && !searching && (
|
2026-02-10 11:04:01 +08:00
|
|
|
<div
|
|
|
|
|
style={{
|
2026-02-10 14:48:42 +08:00
|
|
|
...emptyStateStyle,
|
2026-02-10 11:04:01 +08:00
|
|
|
color: designTokens.colors.text.secondary,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SearchOutlined
|
|
|
|
|
style={{
|
2026-02-10 14:48:42 +08:00
|
|
|
...emptyStateIconStyle,
|
2026-02-10 11:04:01 +08:00
|
|
|
color: designTokens.colors.border.light,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-12-29 13:33:26 +08:00
|
|
|
<p>暂无设备数据</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-10 14:34:39 +08:00
|
|
|
{allDevices.length > 0 && (
|
2026-02-10 11:04:01 +08:00
|
|
|
<div
|
|
|
|
|
className="device-table-wrapper"
|
|
|
|
|
style={{
|
2026-02-10 14:48:42 +08:00
|
|
|
...tableContainerStyle,
|
2026-02-10 11:04:01 +08:00
|
|
|
borderRadius: designTokens.borderRadius.medium,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-12-29 16:29:10 +08:00
|
|
|
<Table
|
2026-02-10 11:04:01 +08:00
|
|
|
columns={columns}
|
2026-03-10 14:34:39 +08:00
|
|
|
dataSource={allDevices}
|
2026-02-10 11:04:01 +08:00
|
|
|
rowKey="deviceId"
|
|
|
|
|
loading={loading || searching}
|
|
|
|
|
pagination={{
|
|
|
|
|
...pagination,
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
showQuickJumper: true,
|
|
|
|
|
pageSizeOptions: ['10', '20', '30', '50', '100'],
|
2026-03-27 19:12:16 +08:00
|
|
|
showTotal: total => `共 ${total} 条记录`,
|
2026-02-10 11:04:01 +08:00
|
|
|
style: { marginTop: '16px' },
|
|
|
|
|
}}
|
|
|
|
|
onChange={handleTableChange}
|
2026-02-10 14:17:26 +08:00
|
|
|
scroll={{ y: 500, scrollToFirstRowOnChange: true }}
|
2026-02-10 11:04:01 +08:00
|
|
|
virtual
|
|
|
|
|
components={{
|
|
|
|
|
header: {
|
|
|
|
|
cell: ResizableTitle,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
style={{ width: '100%', maxWidth: '100%' }}
|
|
|
|
|
size="middle"
|
2026-03-10 14:34:39 +08:00
|
|
|
showHeader={allDevices.length > 0}
|
2026-02-10 11:04:01 +08:00
|
|
|
rowSelection={{
|
|
|
|
|
selectedRowKeys: selectedDevices,
|
|
|
|
|
onChange: handleSelectionChange,
|
|
|
|
|
columnWidth: 48,
|
|
|
|
|
fixed: 'left',
|
|
|
|
|
type: 'checkbox',
|
|
|
|
|
crossPageSelect: true,
|
|
|
|
|
selections: [
|
|
|
|
|
{
|
|
|
|
|
key: 'all',
|
|
|
|
|
text: '全选',
|
|
|
|
|
onSelect: () => {
|
2026-03-27 19:12:16 +08:00
|
|
|
const allIds = allDevices.map(device => device.deviceId);
|
2026-02-10 11:04:01 +08:00
|
|
|
setSelectedDevices(allIds);
|
|
|
|
|
setSelectAll(true);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'invert',
|
|
|
|
|
text: '反选',
|
|
|
|
|
onSelect: () => {
|
2026-03-27 19:12:16 +08:00
|
|
|
const visibleIds = allDevices.map(device => device.deviceId);
|
|
|
|
|
const newSelected = visibleIds.filter(id => !selectedDevices.includes(id));
|
2026-02-10 11:04:01 +08:00
|
|
|
setSelectedDevices(newSelected);
|
2026-03-10 14:34:39 +08:00
|
|
|
setSelectAll(newSelected.length === allDevices.length);
|
2026-02-10 11:04:01 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'none',
|
|
|
|
|
text: '清除选择',
|
|
|
|
|
onSelect: () => {
|
|
|
|
|
setSelectedDevices([]);
|
|
|
|
|
setSelectAll(false);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}}
|
2026-03-27 19:12:16 +08:00
|
|
|
onRow={record => ({
|
2026-02-10 11:04:01 +08:00
|
|
|
onClick: () =>
|
|
|
|
|
handleSelectionChange(
|
|
|
|
|
selectedDevices.includes(record.deviceId)
|
2026-03-27 19:12:16 +08:00
|
|
|
? selectedDevices.filter(id => id !== record.deviceId)
|
2026-02-10 11:04:01 +08:00
|
|
|
: [...selectedDevices, record.deviceId]
|
|
|
|
|
),
|
|
|
|
|
})}
|
|
|
|
|
rowClassName={(record, index) => {
|
|
|
|
|
if (selectedDevices.includes(record.deviceId)) {
|
|
|
|
|
return 'ant-table-row-selected';
|
|
|
|
|
}
|
|
|
|
|
return index % 2 === 0 ? 'ant-table-row-even' : 'ant-table-row-odd';
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-12-29 16:29:10 +08:00
|
|
|
)}
|
2025-12-18 10:45:13 +08:00
|
|
|
</Card>
|
|
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
<DeviceFormModal
|
|
|
|
|
visible={modalVisible}
|
|
|
|
|
editingDevice={editingDevice}
|
|
|
|
|
deviceFields={deviceFields}
|
|
|
|
|
racks={racks}
|
|
|
|
|
rooms={rooms}
|
2025-12-18 10:45:13 +08:00
|
|
|
onCancel={handleCancel}
|
2026-03-10 14:34:39 +08:00
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
/>
|
2026-03-06 13:57:37 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
<DeviceDetailModal
|
|
|
|
|
visible={detailModalVisible}
|
|
|
|
|
device={selectedDevice}
|
|
|
|
|
deviceFields={deviceFields}
|
|
|
|
|
onClose={() => {
|
2025-12-19 15:05:31 +08:00
|
|
|
setDetailModalVisible(false);
|
|
|
|
|
setSelectedDevice(null);
|
|
|
|
|
}}
|
2026-03-10 14:34:39 +08:00
|
|
|
onEdit={showModal}
|
|
|
|
|
onViewTickets={handleViewDeviceTickets}
|
|
|
|
|
onCreateTicket={handleCreateTicketForDevice}
|
|
|
|
|
/>
|
2026-02-12 14:36:33 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
<ImportModal
|
|
|
|
|
visible={importModalVisible}
|
|
|
|
|
deviceFields={deviceFields}
|
|
|
|
|
onImport={handleImport}
|
|
|
|
|
onCancel={() => setImportModalVisible(false)}
|
|
|
|
|
/>
|
2026-02-12 14:36:33 +08:00
|
|
|
|
2026-03-10 14:34:39 +08:00
|
|
|
<ExportModal
|
|
|
|
|
visible={exportModalVisible}
|
|
|
|
|
selectedDevices={selectedDevices}
|
2026-04-01 07:44:57 +00:00
|
|
|
currentPageDevices={allDevices}
|
2026-03-10 14:34:39 +08:00
|
|
|
allDevices={allDevices}
|
|
|
|
|
onExport={handleEnhancedExport}
|
2025-12-29 16:10:42 +08:00
|
|
|
onCancel={() => setExportModalVisible(false)}
|
2026-03-10 14:34:39 +08:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<FieldConfigModal
|
|
|
|
|
visible={fieldConfigModalVisible}
|
|
|
|
|
deviceFields={deviceFields}
|
|
|
|
|
defaultDeviceFields={DEFAULT_DEVICE_FIELDS_LOCAL}
|
|
|
|
|
onSave={handleSaveFieldConfig}
|
|
|
|
|
onReset={handleResetFieldConfig}
|
|
|
|
|
onCancel={() => setFieldConfigModalVisible(false)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<BatchStatusModal
|
|
|
|
|
visible={batchStatusModalVisible}
|
|
|
|
|
selectedCount={selectedDevices.length}
|
|
|
|
|
loading={batchStatusLoading}
|
|
|
|
|
onSubmit={handleBatchStatusChange}
|
|
|
|
|
onCancel={() => setBatchStatusModalVisible(false)}
|
|
|
|
|
/>
|
2025-12-18 10:45:13 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
export default DeviceManagement;
|