refactor(services): 重构服务文件结构,将服务按功能分类到不同目录
- 将服务文件按功能分类到core、ai、analytics、security等目录 - 修复logger导入路径问题,统一使用相对路径 - 更新相关文件的导入路径引用 - 添加新的批量操作组件导出文件 - 修复dashboard页面中的类型错误 - 添加dotenv依赖到package.json
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Table, Button, Input, Select, message, Card } from 'antd';
|
||||
import { Table, Button, Input, Select, message, Card, Modal, Form, InputNumber, Row, Col, Tag, Rate } from 'antd';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, UserOutlined, PhoneOutlined, MailOutlined, HomeOutlined } from '@ant-design/icons';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { suppliersDataSource, Supplier } from '@/services/suppliersDataSource';
|
||||
|
||||
const { Option } = Select;
|
||||
const { Search } = Input;
|
||||
const { TextArea } = Input;
|
||||
|
||||
const Suppliers: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [suppliers, setSuppliers] = useState<Supplier[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [editingSupplier, setEditingSupplier] = useState<Supplier | null>(null);
|
||||
const [form] = Form.useForm();
|
||||
const [filters, setFilters] = useState({
|
||||
category: '',
|
||||
status: '',
|
||||
@@ -34,16 +38,55 @@ const Suppliers: React.FC = () => {
|
||||
};
|
||||
|
||||
const handleAddSupplier = () => {
|
||||
message.info('添加供应商功能开发中');
|
||||
setEditingSupplier(null);
|
||||
form.resetFields();
|
||||
form.setFieldsValue({
|
||||
status: 'active',
|
||||
rating: 3,
|
||||
leadTime: 7,
|
||||
minOrder: 100,
|
||||
paymentTerms: 'Net 30',
|
||||
});
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleEditSupplier = (id: string) => {
|
||||
navigate(`/suppliers/${id}`);
|
||||
const supplier = suppliers.find(s => s.id === id);
|
||||
if (supplier) {
|
||||
setEditingSupplier(supplier);
|
||||
form.setFieldsValue(supplier);
|
||||
setModalVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveSupplier = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
if (editingSupplier) {
|
||||
const updatedSuppliers = suppliers.map(s =>
|
||||
s.id === editingSupplier.id ? { ...s, ...values } : s
|
||||
);
|
||||
setSuppliers(updatedSuppliers);
|
||||
message.success('供应商已更新');
|
||||
} else {
|
||||
const newSupplier: Supplier = {
|
||||
id: `supplier-${Date.now()}`,
|
||||
...values,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
setSuppliers([...suppliers, newSupplier]);
|
||||
message.success('供应商已添加');
|
||||
}
|
||||
setModalVisible(false);
|
||||
} catch (error) {
|
||||
message.error('保存失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteSupplier = (id: string) => {
|
||||
const updatedSuppliers = suppliers.filter(s => s.id !== id);
|
||||
setSuppliers(updatedSuppliers);
|
||||
message.success('供应商已删除');
|
||||
fetchSuppliers();
|
||||
};
|
||||
|
||||
const columns = [
|
||||
@@ -71,24 +114,34 @@ const Suppliers: React.FC = () => {
|
||||
title: '类别',
|
||||
dataIndex: 'category',
|
||||
key: 'category',
|
||||
render: (category: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
Electronics: 'blue',
|
||||
Clothing: 'purple',
|
||||
'Home Goods': 'green',
|
||||
};
|
||||
return <Tag color={colorMap[category] || 'default'}>{category}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
render: (status: string) => {
|
||||
const statusMap: Record<string, string> = {
|
||||
active: '活跃',
|
||||
inactive: '非活跃',
|
||||
pending: '待审核',
|
||||
const statusMap: Record<string, { label: string; color: string }> = {
|
||||
active: { label: '活跃', color: 'success' },
|
||||
inactive: { label: '非活跃', color: 'default' },
|
||||
pending: { label: '待审核', color: 'warning' },
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
const config = statusMap[status] || { label: status, color: 'default' };
|
||||
return <Tag color={config.color}>{config.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '评分',
|
||||
dataIndex: 'rating',
|
||||
key: 'rating',
|
||||
render: (rating: number) => <Rate disabled defaultValue={rating || 3} />,
|
||||
},
|
||||
{
|
||||
title: '交货期(天)',
|
||||
@@ -127,7 +180,7 @@ const Suppliers: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="suppliers">
|
||||
<div className="page-header">
|
||||
<div className="page-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
|
||||
<h1>供应商管理</h1>
|
||||
<Button
|
||||
type="primary"
|
||||
@@ -184,8 +237,162 @@ const Suppliers: React.FC = () => {
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
title={editingSupplier ? '编辑供应商' : '添加供应商'}
|
||||
open={modalVisible}
|
||||
onCancel={() => setModalVisible(false)}
|
||||
onOk={handleSaveSupplier}
|
||||
width={800}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="name"
|
||||
label="供应商名称"
|
||||
rules={[{ required: true, message: '请输入供应商名称' }]}
|
||||
>
|
||||
<Input placeholder="输入供应商名称" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="category"
|
||||
label="类别"
|
||||
rules={[{ required: true, message: '请选择类别' }]}
|
||||
>
|
||||
<Select placeholder="选择类别">
|
||||
<Option value="Electronics">Electronics</Option>
|
||||
<Option value="Clothing">Clothing</Option>
|
||||
<Option value="Home Goods">Home Goods</Option>
|
||||
<Option value="Other">Other</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="contactName"
|
||||
label="联系人"
|
||||
rules={[{ required: true, message: '请输入联系人' }]}
|
||||
>
|
||||
<Input placeholder="输入联系人姓名" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="status"
|
||||
label="状态"
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
>
|
||||
<Select placeholder="选择状态">
|
||||
<Option value="active">活跃</Option>
|
||||
<Option value="inactive">非活跃</Option>
|
||||
<Option value="pending">待审核</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="email"
|
||||
label="邮箱"
|
||||
rules={[
|
||||
{ required: true, message: '请输入邮箱' },
|
||||
{ type: 'email', message: '请输入有效的邮箱地址' },
|
||||
]}
|
||||
>
|
||||
<Input placeholder="输入邮箱地址" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="phone"
|
||||
label="电话"
|
||||
rules={[{ required: true, message: '请输入电话' }]}
|
||||
>
|
||||
<Input placeholder="输入电话号码" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="rating"
|
||||
label="评分"
|
||||
>
|
||||
<Rate />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="paymentTerms"
|
||||
label="付款条款"
|
||||
>
|
||||
<Select placeholder="选择付款条款">
|
||||
<Option value="Net 30">Net 30</Option>
|
||||
<Option value="Net 60">Net 60</Option>
|
||||
<Option value="Net 90">Net 90</Option>
|
||||
<Option value="Prepaid">预付款</Option>
|
||||
<Option value="COD">货到付款</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="leadTime"
|
||||
label="交货期 (天)"
|
||||
>
|
||||
<InputNumber
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
placeholder="输入交货期"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
name="minOrder"
|
||||
label="最小订单量"
|
||||
>
|
||||
<InputNumber
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
placeholder="输入最小订单量"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item
|
||||
name="address"
|
||||
label="地址"
|
||||
>
|
||||
<Input placeholder="输入供应商地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="description"
|
||||
label="备注"
|
||||
>
|
||||
<TextArea rows={3} placeholder="输入备注信息" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Suppliers;
|
||||
export default Suppliers;
|
||||
|
||||
Reference in New Issue
Block a user