import React, { useState, useCallback, useMemo } from 'react'; import { Drawer, Tabs, Tag, Space, Typography, Empty, Card, Tooltip } from 'antd'; import { ApiOutlined, CloudServerOutlined, EnvironmentOutlined } from '@ant-design/icons'; import NetworkCardPanel from './NetworkCardPanel'; const { Text, Title } = Typography; const designTokens = { colors: { primary: '#667eea', success: '#10b981', error: '#ef4444', warning: '#f59e0b' }, spacing: { sm: 8, md: 16 } }; function DeviceDetailDrawer({ device, visible, onClose, cables, onRefreshCables }) { const [activeTab, setActiveTab] = useState('ports'); const deviceCables = useMemo(() => { if (!device || !cables) return []; return cables.filter(c => c.sourceDeviceId === device.deviceId || c.targetDeviceId === device.deviceId ); }, [device, cables]); const getStatusTag = useCallback((status) => { const config = { running: { color: 'success', text: '运行中' }, normal: { color: 'success', text: '正常' }, warning: { color: 'warning', text: '警告' }, error: { color: 'error', text: '故障' }, fault: { color: 'error', text: '故障' }, offline: { color: 'default', text: '离线' }, maintenance: { color: 'processing', text: '维护中' } }; const { color, text } = config[status] || { color: 'default', text: status }; return {text}; }, []); const getDeviceTypeName = useCallback((type) => { const typeMap = { server: '服务器', switch: '交换机', router: '路由器', storage: '存储设备', firewall: '防火墙', ups: 'UPS', pdu: 'PDU' }; return typeMap[type?.toLowerCase()] || type || '未知设备'; }, []); const tabItems = [ { key: 'ports', label: ( 端口与网卡 ), children: ( ) }, { key: 'cables', label: ( 接线 ({deviceCables.length}) ), children: (
{deviceCables.length === 0 ? ( ) : ( {deviceCables.map(cable => (
源设备:
{cable.sourceDevice?.name || '-'} {cable.sourcePort}
目标设备:
{cable.targetDevice?.name || '-'} {cable.targetPort}
{cable.status === 'normal' ? '正常' : cable.status === 'fault' ? '故障' : '未连接'} {cable.cableType === 'ethernet' ? '网线' : cable.cableType === 'fiber' ? '光纤' : '铜缆'} {cable.cableLength && ( {cable.cableLength}m )} {cable.description && (
{cable.description}
)}
))}
)}
) } ]; if (!device) return null; return ( 设备详情 - {device.name} } placement="right" width={520} open={visible} onClose={onClose} styles={{ body: { padding: '16px 20px', overflow: 'auto' } }} >
基本信息
设备ID {device.deviceId}
设备类型 {getDeviceTypeName(device.type)}
设备状态 {getStatusTag(device.status)}
位置 U{device.position} {device.height && `(${device.height}U)`}
{device.ipAddress && (
IP地址 {device.ipAddress}
)} {device.brand && (
品牌 {device.brand}
)}
); } export default React.memo(DeviceDetailDrawer);