chore: 统一代码风格并配置ESLint和Prettier

配置ESLint和Prettier规则
添加前端和后端的忽略文件
统一代码格式和缩进
修复代码风格问题
This commit is contained in:
zhang1106
2026-02-10 11:04:01 +08:00
parent f82d82e57e
commit afc372a432
61 changed files with 14976 additions and 6124 deletions
+73 -68
View File
@@ -1,5 +1,17 @@
import React, { useState, useCallback, useEffect, useMemo } from 'react';
import { Modal, Form, Input, Select, InputNumber, message, Space, Button, Tooltip, Alert, Tag } from 'antd';
import {
Modal,
Form,
Input,
Select,
InputNumber,
message,
Space,
Button,
Tooltip,
Alert,
Tag,
} from 'antd';
import { PlusOutlined, InfoCircleOutlined } from '@ant-design/icons';
import axios from 'axios';
@@ -10,12 +22,12 @@ const designTokens = {
colors: {
primary: {
main: '#667eea',
gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
}
gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
},
},
borderRadius: {
medium: '10px'
}
medium: '10px',
},
};
function parsePortRange(portName) {
@@ -24,34 +36,34 @@ function parsePortRange(portName) {
}
const trimmed = portName.trim();
if (!trimmed.includes('-')) {
return null;
}
const [startPart, endPart] = trimmed.split('-').map(s => s.trim());
if (!startPart || !endPart) {
return null;
}
const startNumMatch = startPart.match(/(\d+)$/);
const endNumMatch = endPart.match(/(\d+)$/);
if (!startNumMatch || !endNumMatch) {
return null;
}
const startNum = parseInt(startNumMatch[1], 10);
const endNum = parseInt(endNumMatch[1], 10);
if (startNum >= endNum || endNum - startNum > 1000) {
return null;
}
const prefix = startPart.replace(startNumMatch[0], '');
const portCount = endNum - startNum + 1;
const ports = [];
for (let i = 0; i < portCount; i++) {
const num = startNum + i;
@@ -64,17 +76,17 @@ function parsePortRange(portName) {
startNum,
endNum,
portCount,
ports
ports,
};
}
function generatePortNames(portName) {
const result = parsePortRange(portName);
if (result && result.isRange) {
return result.ports;
}
return [portName];
}
@@ -92,7 +104,7 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
setPreviewPorts([]);
setShowPreview(false);
form.resetFields();
if (defaultNicId) {
form.setFieldsValue({ nicId: defaultNicId });
}
@@ -116,10 +128,10 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
}
};
const handlePortNameChange = useCallback((e) => {
const handlePortNameChange = useCallback(e => {
const value = e.target.value;
const ports = generatePortNames(value);
if (ports.length > 1) {
setPreviewPorts(ports.slice(0, 20));
setShowPreview(true);
@@ -135,7 +147,7 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
setLoading(true);
const portNames = generatePortNames(values.portName);
if (portNames.length === 1) {
await axios.post('/api/device-ports', {
deviceId: device.deviceId,
@@ -145,7 +157,7 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
portSpeed: values.portSpeed,
vlanId: values.vlanId,
status: values.status,
description: values.description
description: values.description,
});
message.success('端口创建成功');
} else {
@@ -158,7 +170,7 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
portSpeed: values.portSpeed,
vlanId: values.vlanId,
status: values.status,
description: values.description
description: values.description,
}));
await axios.post('/api/device-ports/batch', { ports: portsData });
@@ -196,9 +208,7 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
<Space>
<PlusOutlined style={{ color: designTokens.colors.primary.main }} />
<span>新增端口 - {device?.name || '设备'}</span>
{portCount > 1 && (
<Tag color="blue">{portCount} 个端口</Tag>
)}
{portCount > 1 && <Tag color="blue">{portCount} 个端口</Tag>}
</Space>
}
open={visible}
@@ -217,18 +227,11 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
initialValues={{
portType: 'RJ45',
portSpeed: '1G',
status: 'free'
status: 'free',
}}
>
<Form.Item
name="deviceId"
label="设备"
>
<Input
value={device?.name}
disabled
placeholder={device?.deviceId}
/>
<Form.Item name="deviceId" label="设备">
<Input value={device?.name} disabled placeholder={device?.deviceId} />
</Form.Item>
<Form.Item
@@ -263,16 +266,19 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
label={
<Space>
端口名称
<Tooltip title="支持单个端口(如 eth0/1)或端口范围(如 1/0/1-1/0/48" mouseEnterDelay={0.5}>
<Tooltip
title="支持单个端口(如 eth0/1)或端口范围(如 1/0/1-1/0/48"
mouseEnterDelay={0.5}
>
<InfoCircleOutlined style={{ color: '#999' }} />
</Tooltip>
</Space>
}
rules={[
{ required: true, message: '请输入端口名称' },
{
pattern: /^[\w\/:\-]+$/,
message: '端口名称格式不正确'
{
pattern: /^[\w\/:\-]+$/,
message: '端口名称格式不正确',
},
{
validator: (_, value) => {
@@ -282,13 +288,13 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
return Promise.reject(new Error('单次最多创建1000个端口'));
}
return Promise.resolve();
}
}
},
},
]}
>
<Input
placeholder="例如: eth0/1 或 1/0/1-1/0/48"
onChange={(e) => {
<Input
placeholder="例如: eth0/1 或 1/0/1-1/0/48"
onChange={e => {
// 确保 Form 值更新
form.setFieldValue('portName', e.target.value);
handlePortNameChange(e);
@@ -303,9 +309,12 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
<div style={{ marginTop: 8 }}>
<Space wrap size={4}>
{previewPorts.map((port, index) => (
<Tag key={index} color="blue">{port}</Tag>
<Tag key={index} color="blue">
{port}
</Tag>
))}
{previewPorts.length < parsePortRange(form.getFieldValue('portName'))?.portCount && (
{previewPorts.length <
parsePortRange(form.getFieldValue('portName'))?.portCount && (
<Tag color="default">...</Tag>
)}
</Space>
@@ -352,17 +361,8 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
</Space>
<Space style={{ display: 'flex', width: '100%' }}>
<Form.Item
name="vlanId"
label="VLAN ID"
style={{ flex: 1 }}
>
<InputNumber
placeholder="1-4094"
min={1}
max={4094}
style={{ width: '100%' }}
/>
<Form.Item name="vlanId" label="VLAN ID" style={{ flex: 1 }}>
<InputNumber placeholder="1-4094" min={1} max={4094} style={{ width: '100%' }} />
</Form.Item>
<Form.Item
@@ -379,25 +379,30 @@ function PortCreateModal({ device, visible, onClose, onSuccess, defaultNicId, ne
</Form.Item>
</Space>
<Form.Item
name="description"
label="描述"
>
<Form.Item name="description" label="描述">
<TextArea rows={2} placeholder="请输入描述信息(可选)" />
</Form.Item>
<div style={{
background: '#f5f5f5',
padding: '12px 16px',
borderRadius: '8px',
fontSize: '12px',
color: '#666'
}}>
<div
style={{
background: '#f5f5f5',
padding: '12px 16px',
borderRadius: '8px',
fontSize: '12px',
color: '#666',
}}
>
<strong>格式说明</strong>
<ul style={{ margin: '8px 0 0 0', paddingLeft: '20px' }}>
<li>单个端口<code>eth0/1</code><code>gigabitethernet1/0/1</code></li>
<li>端口范围<code>1/0/1-1/0/48</code>创建 1/0/1 1/0/48 共48个端口</li>
<li>简单范围<code>eth1-eth24</code>创建 eth1 eth24 共24个端口</li>
<li>
单个端口<code>eth0/1</code><code>gigabitethernet1/0/1</code>
</li>
<li>
端口范围<code>1/0/1-1/0/48</code>创建 1/0/1 1/0/48 共48个端口
</li>
<li>
简单范围<code>eth1-eth24</code>创建 eth1 eth24 共24个端口
</li>
</ul>
</div>
</Form>