2026-01-23 08:55:16 +08:00
|
|
|
import React, { useState, useCallback } from 'react';
|
|
|
|
|
import { Modal, Form, Input, InputNumber, Select, message, Space, Tooltip } from 'antd';
|
|
|
|
|
import { PlusOutlined, InfoCircleOutlined, CloudServerOutlined } from '@ant-design/icons';
|
|
|
|
|
import axios from 'axios';
|
2026-03-10 15:49:02 +08:00
|
|
|
import { designTokens } from '../config/theme';
|
2026-03-12 12:40:12 +08:00
|
|
|
import CloseButton from './CloseButton';
|
2026-01-23 08:55:16 +08:00
|
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
const { TextArea } = Input;
|
|
|
|
|
|
|
|
|
|
function NetworkCardCreateModal({ device, visible, onClose, onSuccess }) {
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
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,
|
2026-02-10 11:04:01 +08:00
|
|
|
status: values.status,
|
2026-01-23 08:55:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
<Modal
|
|
|
|
|
title={
|
|
|
|
|
<Space>
|
|
|
|
|
<CloudServerOutlined style={{ color: designTokens.colors.primary.main }} />
|
|
|
|
|
<span>新增网卡 - {device?.name || '设备'}</span>
|
|
|
|
|
</Space>
|
|
|
|
|
}
|
|
|
|
|
open={visible}
|
2026-03-12 12:40:12 +08:00
|
|
|
closeIcon={<CloseButton />}
|
2026-01-23 08:55:16 +08:00
|
|
|
onOk={handleSubmit}
|
|
|
|
|
onCancel={handleCancel}
|
|
|
|
|
confirmLoading={loading}
|
|
|
|
|
okText="创建"
|
|
|
|
|
cancelText="取消"
|
|
|
|
|
width={480}
|
|
|
|
|
styles={{ body: { padding: '20px 24px' } }}
|
|
|
|
|
>
|
|
|
|
|
<Form
|
|
|
|
|
form={form}
|
|
|
|
|
layout="vertical"
|
|
|
|
|
initialValues={{
|
2026-02-10 11:04:01 +08:00
|
|
|
status: 'normal',
|
2026-01-23 08:55:16 +08:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Form.Item
|
|
|
|
|
name="name"
|
|
|
|
|
label={
|
|
|
|
|
<Space>
|
|
|
|
|
网卡名称
|
|
|
|
|
<Tooltip title="如: 网卡1、eth0、Primary NIC、LAN1">
|
|
|
|
|
<InfoCircleOutlined style={{ color: '#999' }} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Space>
|
|
|
|
|
}
|
|
|
|
|
rules={[
|
|
|
|
|
{ required: true, message: '请输入网卡名称' },
|
2026-02-10 11:04:01 +08:00
|
|
|
{ max: 50, message: '名称不能超过50个字符' },
|
2026-01-23 08:55:16 +08:00
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
<Input placeholder="例如: 网卡1、eth0、LAN1" />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Space style={{ display: 'flex', width: '100%' }}>
|
2026-02-10 11:04:01 +08:00
|
|
|
<Form.Item name="slotNumber" label="插槽编号" style={{ flex: 1 }}>
|
|
|
|
|
<InputNumber placeholder="可选" min={1} max={100} style={{ width: '100%' }} />
|
2026-01-23 08:55:16 +08:00
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
name="status"
|
|
|
|
|
label="状态"
|
|
|
|
|
rules={[{ required: true, message: '请选择状态' }]}
|
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
|
>
|
|
|
|
|
<Select placeholder="请选择">
|
|
|
|
|
<Option value="normal">正常</Option>
|
|
|
|
|
<Option value="warning">警告</Option>
|
|
|
|
|
<Option value="fault">故障</Option>
|
|
|
|
|
<Option value="offline">离线</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Space>
|
|
|
|
|
|
|
|
|
|
<Space style={{ display: 'flex', width: '100%' }}>
|
2026-02-10 11:04:01 +08:00
|
|
|
<Form.Item name="manufacturer" label="制造商" style={{ flex: 1 }}>
|
2026-01-23 08:55:16 +08:00
|
|
|
<Input placeholder="如: Intel、Realtek、Broadcom" />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
<Form.Item name="model" label="型号" style={{ flex: 1 }}>
|
2026-01-23 08:55:16 +08:00
|
|
|
<Input placeholder="如: X520-DA2" />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Space>
|
|
|
|
|
|
2026-02-10 11:04:01 +08:00
|
|
|
<Form.Item name="description" label="描述">
|
2026-01-23 08:55:16 +08:00
|
|
|
<TextArea rows={2} placeholder="请输入描述信息(可选)" />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default React.memo(NetworkCardCreateModal);
|