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
+127 -127
View File
@@ -20,7 +20,7 @@ const CableCreateModal = ({ visible, onClose, onSuccess, sourceDevice }) => {
form.resetFields();
if (sourceDevice) {
form.setFieldsValue({
sourceDeviceId: sourceDevice.deviceId || sourceDevice.id,
sourceDeviceId: sourceDevice.deviceId || sourceDevice.id,
});
fetchDevicePorts(sourceDevice.deviceId || sourceDevice.id, 'source');
}
@@ -63,12 +63,12 @@ const CableCreateModal = ({ visible, onClose, onSuccess, sourceDevice }) => {
}
};
const handleSourceDeviceChange = (deviceId) => {
const handleSourceDeviceChange = deviceId => {
form.setFieldsValue({ sourcePort: undefined });
fetchDevicePorts(deviceId, 'source');
};
const handleTargetDeviceChange = (deviceId) => {
const handleTargetDeviceChange = deviceId => {
form.setFieldsValue({ targetPort: undefined });
fetchDevicePorts(deviceId, 'target');
};
@@ -85,22 +85,19 @@ const CableCreateModal = ({ visible, onClose, onSuccess, sourceDevice }) => {
let payload = { ...values };
// If Source is NOT Switch AND Target IS Switch, swap them
if (sourceDev && targetDev &&
sourceDev.type !== 'switch' &&
targetDev.type === 'switch') {
payload = {
...values,
sourceDeviceId: values.targetDeviceId,
sourcePort: values.targetPort,
targetDeviceId: values.sourceDeviceId,
targetPort: values.sourcePort
};
console.log('Swapped source/target to ensure Switch is Source');
if (sourceDev && targetDev && sourceDev.type !== 'switch' && targetDev.type === 'switch') {
payload = {
...values,
sourceDeviceId: values.targetDeviceId,
sourcePort: values.targetPort,
targetDeviceId: values.sourceDeviceId,
targetPort: values.sourcePort,
};
console.log('Swapped source/target to ensure Switch is Source');
}
await axios.post('/api/cables', payload);
message.success('接线创建成功');
onSuccess?.();
onClose();
@@ -130,122 +127,125 @@ const CableCreateModal = ({ visible, onClose, onSuccess, sourceDevice }) => {
>
<Form form={form} layout="vertical">
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
{/* Source Side */}
<div style={{ padding: '12px', background: '#f9f9f9', borderRadius: '8px' }}>
<div style={{ marginBottom: 12, fontWeight: 500, color: '#666' }}>源设备 (起点)</div>
<Form.Item
name="sourceDeviceId"
label="设备"
rules={[{ required: true, message: '请选择源设备' }]}
>
<Select
placeholder="选择源设备"
showSearch
filterOption={(input, option) =>
(option?.children ?? '').toLowerCase().includes(input.toLowerCase())
}
onChange={handleSourceDeviceChange}
loading={fetchingDevices}
disabled={!!sourceDevice} // Lock source device if provided
>
{devices.map(d => (
<Option key={d.deviceId} value={d.deviceId}>{d.name}</Option>
))}
</Select>
</Form.Item>
<Form.Item
name="sourcePort"
label="端口"
rules={[{ required: true, message: '请选择源端口' }]}
>
<Select placeholder="选择源端口" showSearch>
{sourcePorts.map(p => (
<Option key={p.portId} value={p.portName}>
{p.portName} ({p.portType})
</Option>
))}
</Select>
</Form.Item>
</div>
{/* Source Side */}
<div style={{ padding: '12px', background: '#f9f9f9', borderRadius: '8px' }}>
<div style={{ marginBottom: 12, fontWeight: 500, color: '#666' }}>源设备 (起点)</div>
<Form.Item
name="sourceDeviceId"
label="设备"
rules={[{ required: true, message: '请选择源设备' }]}
>
<Select
placeholder="选择源设备"
showSearch
filterOption={(input, option) =>
(option?.children ?? '').toLowerCase().includes(input.toLowerCase())
}
onChange={handleSourceDeviceChange}
loading={fetchingDevices}
disabled={!!sourceDevice} // Lock source device if provided
>
{devices.map(d => (
<Option key={d.deviceId} value={d.deviceId}>
{d.name}
</Option>
))}
</Select>
</Form.Item>
<Form.Item
name="sourcePort"
label="端口"
rules={[{ required: true, message: '请选择源端口' }]}
>
<Select placeholder="选择源端口" showSearch>
{sourcePorts.map(p => (
<Option key={p.portId} value={p.portName}>
{p.portName} ({p.portType})
</Option>
))}
</Select>
</Form.Item>
</div>
{/* Target Side */}
<div style={{ padding: '12px', background: '#f9f9f9', borderRadius: '8px' }}>
<div style={{ marginBottom: 12, fontWeight: 500, color: '#666' }}>目标设备 (终点)</div>
<Form.Item
name="targetDeviceId"
label="设备"
rules={[{ required: true, message: '请选择目标设备' }]}
>
<Select
placeholder="选择目标设备"
showSearch
filterOption={(input, option) =>
(option?.children ?? '').toLowerCase().includes(input.toLowerCase())
}
onChange={handleTargetDeviceChange}
loading={fetchingDevices}
>
{devices.filter(d => d.deviceId !== form.getFieldValue('sourceDeviceId')).map(d => (
<Option key={d.deviceId} value={d.deviceId}>{d.name}</Option>
))}
</Select>
</Form.Item>
<Form.Item
name="targetPort"
label="端口"
rules={[{ required: true, message: '请选择目标端口' }]}
>
<Select
placeholder="选择目标端口"
showSearch
disabled={!form.getFieldValue('targetDeviceId')}
>
{targetPorts.map(p => (
<Option key={p.portId} value={p.portName}>
{p.portName} ({p.portType})
</Option>
))}
</Select>
</Form.Item>
</div>
{/* Target Side */}
<div style={{ padding: '12px', background: '#f9f9f9', borderRadius: '8px' }}>
<div style={{ marginBottom: 12, fontWeight: 500, color: '#666' }}>目标设备 (终点)</div>
<Form.Item
name="targetDeviceId"
label="设备"
rules={[{ required: true, message: '请选择目标设备' }]}
>
<Select
placeholder="选择目标设备"
showSearch
filterOption={(input, option) =>
(option?.children ?? '').toLowerCase().includes(input.toLowerCase())
}
onChange={handleTargetDeviceChange}
loading={fetchingDevices}
>
{devices
.filter(d => d.deviceId !== form.getFieldValue('sourceDeviceId'))
.map(d => (
<Option key={d.deviceId} value={d.deviceId}>
{d.name}
</Option>
))}
</Select>
</Form.Item>
<Form.Item
name="targetPort"
label="端口"
rules={[{ required: true, message: '请选择目标端口' }]}
>
<Select
placeholder="选择目标端口"
showSearch
disabled={!form.getFieldValue('targetDeviceId')}
>
{targetPorts.map(p => (
<Option key={p.portId} value={p.portName}>
{p.portName} ({p.portType})
</Option>
))}
</Select>
</Form.Item>
</div>
</div>
<div style={{ marginTop: 16 }}>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 16 }}>
<Form.Item
name="cableType"
label="线缆类型"
initialValue="ethernet"
rules={[{ required: true }]}
>
<Select>
<Option value="ethernet">网线</Option>
<Option value="fiber">光纤</Option>
<Option value="copper">铜缆</Option>
</Select>
</Form.Item>
<Form.Item
name="status"
label="状态"
initialValue="normal"
rules={[{ required: true }]}
>
<Select>
<Option value="normal">正常</Option>
<Option value="fault">故障</Option>
<Option value="disconnected">未连接</Option>
</Select>
</Form.Item>
<Form.Item
name="cableLength"
label="长度 (米)"
>
<Input type="number" min={0} />
</Form.Item>
</div>
<Form.Item name="description" label="描述">
<Input.TextArea rows={2} />
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 16 }}>
<Form.Item
name="cableType"
label="线缆类型"
initialValue="ethernet"
rules={[{ required: true }]}
>
<Select>
<Option value="ethernet">网线</Option>
<Option value="fiber">光纤</Option>
<Option value="copper">铜缆</Option>
</Select>
</Form.Item>
<Form.Item
name="status"
label="状态"
initialValue="normal"
rules={[{ required: true }]}
>
<Select>
<Option value="normal">正常</Option>
<Option value="fault">故障</Option>
<Option value="disconnected">未连接</Option>
</Select>
</Form.Item>
<Form.Item name="cableLength" label="长度 (米)">
<Input type="number" min={0} />
</Form.Item>
</div>
<Form.Item name="description" label="描述">
<Input.TextArea rows={2} />
</Form.Item>
</div>
</Form>
</Modal>