refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码 style(frontend): 调整组件代码格式 chore: 删除旧 ESLint 配置并添加新配置 refactor(backend): 重构模型定义语法 style: 统一箭头函数和对象属性简写
This commit is contained in:
@@ -48,7 +48,7 @@ const api = axios.create({
|
||||
baseURL: '/api',
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
api.interceptors.request.use(config => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
@@ -92,7 +92,7 @@ const InventoryManagement = () => {
|
||||
};
|
||||
const res = await api.get('/inventory/plans', { params });
|
||||
setPlans(res.data.plans || []);
|
||||
setPagination((prev) => ({
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
total: res.data.total || 0,
|
||||
}));
|
||||
@@ -119,7 +119,7 @@ const InventoryManagement = () => {
|
||||
const fetchRooms = async () => {
|
||||
try {
|
||||
const res = await api.get('/rooms', { params: { pageSize: 1000 } });
|
||||
setRooms(Array.isArray(res.data) ? res.data : (res.data.rooms || []));
|
||||
setRooms(Array.isArray(res.data) ? res.data : res.data.rooms || []);
|
||||
} catch (error) {
|
||||
console.error('获取机房失败', error);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ const InventoryManagement = () => {
|
||||
const fetchRacks = async () => {
|
||||
try {
|
||||
const res = await api.get('/racks', { params: { pageSize: 1000 } });
|
||||
const allRacks = Array.isArray(res.data) ? res.data : (res.data.racks || []);
|
||||
const allRacks = Array.isArray(res.data) ? res.data : res.data.racks || [];
|
||||
setRacks(allRacks);
|
||||
setFilteredRacks(allRacks);
|
||||
} catch (error) {
|
||||
@@ -157,20 +157,21 @@ const InventoryManagement = () => {
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleEdit = (record) => {
|
||||
const handleEdit = record => {
|
||||
setEditingPlan(record);
|
||||
const targetRooms = record.targetRooms || [];
|
||||
setSelectedRooms(targetRooms);
|
||||
|
||||
|
||||
if (targetRooms.length > 0) {
|
||||
const filtered = racks.filter(rack =>
|
||||
targetRooms.includes(rack.roomId) || (rack.Room && targetRooms.includes(rack.Room.roomId))
|
||||
const filtered = racks.filter(
|
||||
rack =>
|
||||
targetRooms.includes(rack.roomId) || (rack.Room && targetRooms.includes(rack.Room.roomId))
|
||||
);
|
||||
setFilteredRacks(filtered);
|
||||
} else {
|
||||
setFilteredRacks(racks);
|
||||
}
|
||||
|
||||
|
||||
form.setFieldsValue({
|
||||
name: record.name,
|
||||
type: record.type,
|
||||
@@ -182,7 +183,7 @@ const InventoryManagement = () => {
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleDelete = async (planId) => {
|
||||
const handleDelete = async planId => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这个盘点计划吗?此操作不可恢复!',
|
||||
@@ -202,7 +203,7 @@ const InventoryManagement = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (values) => {
|
||||
const handleSubmit = async values => {
|
||||
try {
|
||||
const data = {
|
||||
...values,
|
||||
@@ -226,7 +227,7 @@ const InventoryManagement = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleStart = async (plan) => {
|
||||
const handleStart = async plan => {
|
||||
try {
|
||||
await api.post(`/inventory/plans/${plan.planId}/start`);
|
||||
message.success('盘点任务已启动');
|
||||
@@ -237,7 +238,7 @@ const InventoryManagement = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleComplete = async (plan) => {
|
||||
const handleComplete = async plan => {
|
||||
try {
|
||||
await api.post(`/inventory/plans/${plan.planId}/complete`);
|
||||
message.success('盘点已完成');
|
||||
@@ -248,23 +249,23 @@ const InventoryManagement = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewTasks = (plan) => {
|
||||
const handleViewTasks = plan => {
|
||||
navigate(`/inventory/execution?planId=${plan.planId}`);
|
||||
};
|
||||
|
||||
const handleRoomsChange = (roomIds) => {
|
||||
const handleRoomsChange = roomIds => {
|
||||
setSelectedRooms(roomIds || []);
|
||||
if (!roomIds || roomIds.length === 0) {
|
||||
setFilteredRacks(racks);
|
||||
} else {
|
||||
const filtered = racks.filter(rack =>
|
||||
roomIds.includes(rack.roomId) || (rack.Room && roomIds.includes(rack.Room.roomId))
|
||||
const filtered = racks.filter(
|
||||
rack => roomIds.includes(rack.roomId) || (rack.Room && roomIds.includes(rack.Room.roomId))
|
||||
);
|
||||
setFilteredRacks(filtered);
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusTag = (status) => {
|
||||
const getStatusTag = status => {
|
||||
const statusMap = {
|
||||
draft: { color: 'default', text: '草稿', icon: <FileSearchOutlined /> },
|
||||
pending: { color: 'orange', text: '待执行', icon: <ClockCircleOutlined /> },
|
||||
@@ -274,17 +275,13 @@ const InventoryManagement = () => {
|
||||
};
|
||||
const config = statusMap[status] || statusMap.draft;
|
||||
return (
|
||||
<Tag
|
||||
color={config.color}
|
||||
icon={config.icon}
|
||||
style={{ borderRadius: 6, padding: '2px 8px' }}
|
||||
>
|
||||
<Tag color={config.color} icon={config.icon} style={{ borderRadius: 6, padding: '2px 8px' }}>
|
||||
{config.text}
|
||||
</Tag>
|
||||
);
|
||||
};
|
||||
|
||||
const getTypeTag = (type) => {
|
||||
const getTypeTag = type => {
|
||||
const typeMap = {
|
||||
full: { color: 'blue', text: '全面盘点' },
|
||||
partial: { color: 'cyan', text: '局部盘点' },
|
||||
@@ -294,7 +291,7 @@ const InventoryManagement = () => {
|
||||
return <Tag color={config.color}>{config.text}</Tag>;
|
||||
};
|
||||
|
||||
const getProgressPercent = (plan) => {
|
||||
const getProgressPercent = plan => {
|
||||
if (!plan.totalDevices || plan.totalDevices === 0) return 0;
|
||||
return Math.round((plan.checkedDevices / plan.totalDevices) * 100);
|
||||
};
|
||||
@@ -334,14 +331,14 @@ const InventoryManagement = () => {
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
width: 100,
|
||||
render: (type) => getTypeTag(type),
|
||||
render: type => getTypeTag(type),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 120,
|
||||
render: (status) => getStatusTag(status),
|
||||
render: status => getStatusTag(status),
|
||||
},
|
||||
{
|
||||
title: '盘点进度',
|
||||
@@ -357,8 +354,8 @@ const InventoryManagement = () => {
|
||||
{getProgressPercent(record)}%
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
percent={getProgressPercent(record)}
|
||||
<Progress
|
||||
percent={getProgressPercent(record)}
|
||||
size="small"
|
||||
strokeColor={{
|
||||
'0%': '#108ee9',
|
||||
@@ -372,25 +369,26 @@ const InventoryManagement = () => {
|
||||
title: '异常设备',
|
||||
key: 'abnormal',
|
||||
width: 100,
|
||||
render: (_, record) => (
|
||||
record.abnormalDevices > 0 ?
|
||||
<Tag color="error">{record.abnormalDevices} 异常</Tag> :
|
||||
render: (_, record) =>
|
||||
record.abnormalDevices > 0 ? (
|
||||
<Tag color="error">{record.abnormalDevices} 异常</Tag>
|
||||
) : (
|
||||
<span style={{ color: '#8c8c8c' }}>-</span>
|
||||
),
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建人',
|
||||
dataIndex: ['Creator', 'realName'],
|
||||
key: 'creator',
|
||||
width: 100,
|
||||
render: (name) => name || '-',
|
||||
render: name => name || '-',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createdAt',
|
||||
key: 'createdAt',
|
||||
width: 160,
|
||||
render: (date) => (date ? dayjs(date).format('YYYY-MM-DD HH:mm') : '-'),
|
||||
render: date => (date ? dayjs(date).format('YYYY-MM-DD HH:mm') : '-'),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
@@ -482,21 +480,29 @@ const InventoryManagement = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24, background: designTokens.colors.background.secondary, minHeight: '100vh' }}>
|
||||
<div
|
||||
style={{
|
||||
padding: 24,
|
||||
background: designTokens.colors.background.secondary,
|
||||
minHeight: '100vh',
|
||||
}}
|
||||
>
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<Row gutter={[16, 16]}>
|
||||
{statCards.map((stat, index) => (
|
||||
<Col xs={24} sm={8} key={index}>
|
||||
<Card
|
||||
bordered={false}
|
||||
style={{
|
||||
<Card
|
||||
bordered={false}
|
||||
style={{
|
||||
borderRadius: 16,
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.06)',
|
||||
background: stat.gradient,
|
||||
}}
|
||||
bodyStyle={{ padding: 20 }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<div
|
||||
style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<div style={{ color: 'rgba(255,255,255,0.9)', fontSize: 14, marginBottom: 8 }}>
|
||||
{stat.title}
|
||||
@@ -505,17 +511,19 @@ const InventoryManagement = () => {
|
||||
{stat.value || 0}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{
|
||||
width: 56,
|
||||
height: 56,
|
||||
borderRadius: 12,
|
||||
background: 'rgba(255,255,255,0.2)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
fontSize: 24,
|
||||
color: '#fff'
|
||||
}}>
|
||||
<div
|
||||
style={{
|
||||
width: 56,
|
||||
height: 56,
|
||||
borderRadius: 12,
|
||||
background: 'rgba(255,255,255,0.2)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
fontSize: 24,
|
||||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{stat.icon}
|
||||
</div>
|
||||
</div>
|
||||
@@ -525,25 +533,27 @@ const InventoryManagement = () => {
|
||||
</Row>
|
||||
</div>
|
||||
|
||||
<Card
|
||||
bordered={false}
|
||||
style={{ borderRadius: 16, boxShadow: '0 2px 8px rgba(0,0,0,0.06)' }}
|
||||
>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<Card bordered={false} style={{ borderRadius: 16, boxShadow: '0 2px 8px rgba(0,0,0,0.06)' }}>
|
||||
<Tabs activeKey={activeTab} onChange={setActiveTab} style={{ marginBottom: 16 }}>
|
||||
<TabPane tab="盘点计划列表" key="list">
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 12 }}>
|
||||
<div
|
||||
style={{
|
||||
marginBottom: 16,
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
flexWrap: 'wrap',
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<Input
|
||||
placeholder="搜索计划名称"
|
||||
prefix={<SearchOutlined />}
|
||||
style={{ width: 240, borderRadius: 8 }}
|
||||
onChange={(e) => setSearchParamsObj({ keyword: e.target.value })}
|
||||
onChange={e => setSearchParamsObj({ keyword: e.target.value })}
|
||||
onPressEnter={() => {
|
||||
setPagination((prev) => ({ ...prev, current: 1 }));
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
fetchPlans();
|
||||
}}
|
||||
/>
|
||||
@@ -551,9 +561,9 @@ const InventoryManagement = () => {
|
||||
placeholder="选择状态"
|
||||
style={{ width: 140, borderRadius: 8 }}
|
||||
allowClear
|
||||
onChange={(value) => {
|
||||
setSearchParamsObj((prev) => ({ ...prev, status: value }));
|
||||
setPagination((prev) => ({ ...prev, current: 1 }));
|
||||
onChange={value => {
|
||||
setSearchParamsObj(prev => ({ ...prev, status: value }));
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
}}
|
||||
>
|
||||
<Select.Option value="draft">草稿</Select.Option>
|
||||
@@ -561,17 +571,21 @@ const InventoryManagement = () => {
|
||||
<Select.Option value="in_progress">进行中</Select.Option>
|
||||
<Select.Option value="completed">已完成</Select.Option>
|
||||
</Select>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => { setSearchParamsObj({}); fetchPlans(); fetchStats(); }}
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => {
|
||||
setSearchParamsObj({});
|
||||
fetchPlans();
|
||||
fetchStats();
|
||||
}}
|
||||
style={{ borderRadius: 8 }}
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={handleAdd}
|
||||
style={{ borderRadius: 8, height: 40 }}
|
||||
>
|
||||
@@ -588,14 +602,16 @@ const InventoryManagement = () => {
|
||||
...pagination,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total) => `共 ${total} 条记录`,
|
||||
showTotal: total => `共 ${total} 条记录`,
|
||||
onChange: (page, pageSize) => {
|
||||
setPagination((prev) => ({ ...prev, current: page, pageSize }));
|
||||
setPagination(prev => ({ ...prev, current: page, pageSize }));
|
||||
},
|
||||
}}
|
||||
scroll={{ x: 1200 }}
|
||||
locale={{
|
||||
emptyText: <Empty description="暂无盘点计划" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
|
||||
emptyText: (
|
||||
<Empty description="暂无盘点计划" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</TabPane>
|
||||
@@ -615,17 +631,13 @@ const InventoryManagement = () => {
|
||||
footer={null}
|
||||
width={640}
|
||||
centered
|
||||
styles={{
|
||||
styles={{
|
||||
header: { borderBottom: '1px solid #f0f0f0', padding: '16px 24px' },
|
||||
body: { padding: 24 },
|
||||
footer: { borderTop: '1px solid #f0f0f0', padding: '12px 24px' }
|
||||
footer: { borderTop: '1px solid #f0f0f0', padding: '12px 24px' },
|
||||
}}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleSubmit}
|
||||
>
|
||||
<Form form={form} layout="vertical" onFinish={handleSubmit}>
|
||||
<Row gutter={16}>
|
||||
<Col span={16}>
|
||||
<Form.Item
|
||||
@@ -652,35 +664,26 @@ const InventoryManagement = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item
|
||||
name="description"
|
||||
label="描述"
|
||||
>
|
||||
<Form.Item name="description" label="描述">
|
||||
<Input.TextArea rows={2} placeholder="请输入描述" style={{ borderRadius: 8 }} />
|
||||
</Form.Item>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="scheduledDate"
|
||||
label="计划日期"
|
||||
>
|
||||
<Form.Item name="scheduledDate" label="计划日期">
|
||||
<DatePicker style={{ width: '100%', borderRadius: 8 }} placeholder="选择计划日期" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="targetRooms"
|
||||
label="目标机房"
|
||||
>
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="选择目标机房(不选则为全部)"
|
||||
<Form.Item name="targetRooms" label="目标机房">
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="选择目标机房(不选则为全部)"
|
||||
allowClear
|
||||
onChange={handleRoomsChange}
|
||||
style={{ borderRadius: 8 }}
|
||||
>
|
||||
{rooms.map((room) => (
|
||||
{rooms.map(room => (
|
||||
<Select.Option key={room.roomId} value={room.roomId}>
|
||||
{room.name}
|
||||
</Select.Option>
|
||||
@@ -690,17 +693,14 @@ const InventoryManagement = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item
|
||||
name="targetRacks"
|
||||
label="目标机柜"
|
||||
>
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="选择目标机柜(不选则为全部)"
|
||||
<Form.Item name="targetRacks" label="目标机柜">
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="选择目标机柜(不选则为全部)"
|
||||
allowClear
|
||||
style={{ borderRadius: 8 }}
|
||||
>
|
||||
{filteredRacks.map((rack) => (
|
||||
{filteredRacks.map(rack => (
|
||||
<Select.Option key={rack.rackId} value={rack.rackId}>
|
||||
{rack.name} ({rack.Room?.name || ''})
|
||||
</Select.Option>
|
||||
|
||||
Reference in New Issue
Block a user