import React, { useState, useCallback, useEffect } from 'react'; import { Modal, Form, Input, Select, message, Space, Tooltip, Card, Alert, AutoComplete, } from 'antd'; import { CloudServerOutlined, InfoCircleOutlined, QuestionCircleOutlined, ThunderboltOutlined, } from '@ant-design/icons'; import axios from 'axios'; import { designTokens } from '../config/theme'; import CloseButton from './CloseButton'; const { TextArea } = Input; const SLOT_TYPES = [ { value: 'LOM', label: '板载网卡 (LOM)', description: '主板集成网卡,编号0' }, { value: 'OCP', label: 'OCP 网卡', description: '开放式计算项目网卡槽位' }, { value: '1', label: '插槽 1', description: 'PCIe x16/x8 插槽' }, { value: '2', label: '插槽 2', description: 'PCIe x8 插槽' }, { value: '3', label: '插槽 3', description: 'PCIe x4 插槽(需 Riser 卡)' }, { value: '4', label: '插槽 4', description: 'PCIe x4 插槽(需 Riser 卡)' }, ]; const MANUFACTURER_OPTIONS = [ { value: 'Intel', label: 'Intel' }, { value: 'Broadcom', label: 'Broadcom' }, { value: 'Mellanox', label: 'Mellanox (NVIDIA)' }, { value: 'Realtek', label: 'Realtek' }, { value: 'Cisco', label: 'Cisco' }, { value: 'HP', label: 'HP/HPE' }, { value: 'Dell', label: 'Dell' }, { value: 'Qlogic', label: 'Qlogic' }, { value: 'Marvell', label: 'Marvell' }, { value: 'Other', label: '其他' }, ]; function NetworkCardCreateModal({ device, visible, onClose, onSuccess }) { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); useEffect(() => { if (visible) { form.resetFields(); } }, [visible, form]); const handleSubmit = useCallback(async () => { try { const values = await form.validateFields(); setLoading(true); await axios.post('/api/network-cards', { deviceId: device.deviceId, name: values.name, slotNumber: values.slotNumber, description: values.description, model: values.model, manufacturer: values.manufacturer, }); message.success('网卡创建成功'); form.resetFields(); onSuccess?.(); onClose(); } catch (error) { if (error.errorFields) { return; } message.error(error.response?.data?.error || '网卡创建失败'); console.error('创建网卡失败:', error); } finally { setLoading(false); } }, [device, form, onClose, onSuccess]); const handleCancel = useCallback(() => { form.resetFields(); onClose(); }, [form, onClose]); return ( 新增网卡 - {device?.name || '设备'} } open={visible} closeIcon={} onOk={handleSubmit} onCancel={handleCancel} confirmLoading={loading} okText="创建" cancelText="取消" width={800} styles={{ body: { padding: '0 24px 24px' } }} >
为服务器添加新的网卡,网卡创建后可关联端口
插槽编号参考
  • LOM (LAN on Motherboard):主板集成网卡,编号通常为 0
  • OCP (Open Compute Project):服务器前端维护网卡专用槽位
  • PCIe 插槽:从 1 开始编号,对应服务器物理插槽位置
} type="info" style={{ marginBottom: 20, borderRadius: 10, background: designTokens.colors.info.bg, border: `1px solid ${designTokens.colors.info.light}40`, }} />
基础信息 } style={{ flex: 1, borderRadius: 12, border: `1px solid ${designTokens.colors.neutral[200]}`, }} styles={{ body: { padding: '16px 20px' } }} > 网卡名称 * } rules={[ { required: true, message: '请输入网卡名称' }, { max: 50, message: '名称不能超过50个字符' }, ]} > 插槽位置 } > ({ value: slot.value, label: (
{slot.label}
{slot.description}
), }))} filterOption={(input, option) => option.value.toLowerCase().includes(input.toLowerCase()) || option.label.props.children[0].props.children .toLowerCase() .includes(input.toLowerCase()) } />
规格信息 } style={{ flex: 1, borderRadius: 12, border: `1px solid ${designTokens.colors.neutral[200]}`, }} styles={{ body: { padding: '16px 20px' } }} >
制造商} > ({ value: m.value, label: m.label }))} filterOption={(input, option) => option.label.toLowerCase().includes(input.toLowerCase()) } size="large" /> 型号}>
附加信息 } style={{ borderRadius: 12, border: `1px solid ${designTokens.colors.neutral[200]}`, }} styles={{ body: { padding: '16px 20px' } }} > 描述}>