feat: 添加MSW模拟服务和数据源集成
refactor: 重构页面组件移除冗余Layout组件 feat: 实现WebSocket和事件总线系统 feat: 添加队列和调度系统 docs: 更新架构文档和服务映射 style: 清理重复接口定义使用数据源 chore: 更新依赖项配置 feat: 添加运行时系统和领域引导 ci: 配置ESLint边界检查规则 build: 添加Redis和WebSocket依赖 test: 添加MSW浏览器环境入口 perf: 优化数据获取逻辑使用统一数据源 fix: 修复类型定义和状态管理问题
This commit is contained in:
98
dashboard/src/services/suppliersDataSource.ts
Normal file
98
dashboard/src/services/suppliersDataSource.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* [MOCK-SUPPLIERS] Suppliers模块DataSource
|
||||
*/
|
||||
|
||||
export interface Supplier {
|
||||
id: string;
|
||||
name: string;
|
||||
contact: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
address: string;
|
||||
category: string;
|
||||
rating: number;
|
||||
status: 'active' | 'inactive' | 'pending';
|
||||
paymentTerms: string;
|
||||
leadTime: number;
|
||||
minOrderQty: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface SupplierProduct {
|
||||
id: string;
|
||||
supplierId: string;
|
||||
sku: string;
|
||||
productName: string;
|
||||
costPrice: number;
|
||||
moq: number;
|
||||
leadTime: number;
|
||||
quality: 'A' | 'B' | 'C';
|
||||
}
|
||||
|
||||
export interface ISuppliersDataSource {
|
||||
fetchSuppliers(): Promise<Supplier[]>;
|
||||
fetchSupplierDetail(id: string): Promise<Supplier>;
|
||||
saveSupplier(data: Partial<Supplier>): Promise<Supplier>;
|
||||
deleteSupplier(id: string): Promise<void>;
|
||||
fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]>;
|
||||
}
|
||||
|
||||
class MockSuppliersDataSource implements ISuppliersDataSource {
|
||||
async fetchSuppliers(): Promise<Supplier[]> {
|
||||
return [
|
||||
{ id: 'sup_001', name: 'Shenzhen Tech Co.', contact: 'Li Wei', email: 'liwei@szttech.com', phone: '+86-138-0000-0001', address: 'Shenzhen, China', category: 'Electronics', rating: 4.8, status: 'active', paymentTerms: '30% deposit, 70% before shipping', leadTime: 15, minOrderQty: 100, createdAt: '2025-01-15' },
|
||||
{ id: 'sup_002', name: 'Guangzhou Accessories Ltd.', contact: 'Wang Ming', email: 'wangming@gzacc.com', phone: '+86-138-0000-0002', address: 'Guangzhou, China', category: 'Accessories', rating: 4.5, status: 'active', paymentTerms: 'Net 30', leadTime: 10, minOrderQty: 50, createdAt: '2025-02-20' },
|
||||
{ id: 'sup_003', name: 'Dongguan Manufacturing', contact: 'Zhang Hua', email: 'zhanghua@dgmfg.com', phone: '+86-138-0000-0003', address: 'Dongguan, China', category: 'Electronics', rating: 4.2, status: 'active', paymentTerms: '50% deposit, 50% on delivery', leadTime: 20, minOrderQty: 200, createdAt: '2025-03-10' },
|
||||
];
|
||||
}
|
||||
|
||||
async fetchSupplierDetail(id: string): Promise<Supplier> {
|
||||
const suppliers = await this.fetchSuppliers();
|
||||
return suppliers.find(s => s.id === id) || suppliers[0];
|
||||
}
|
||||
|
||||
async saveSupplier(data: Partial<Supplier>): Promise<Supplier> {
|
||||
return { ...data, id: data.id || `sup_${Date.now()}`, createdAt: new Date().toISOString() } as Supplier;
|
||||
}
|
||||
|
||||
async deleteSupplier(id: string): Promise<void> {}
|
||||
|
||||
async fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]> {
|
||||
return [
|
||||
{ id: 'sp_001', supplierId, sku: 'SKU-001', productName: 'Wireless Headphones', costPrice: 12.50, moq: 100, leadTime: 15, quality: 'A' },
|
||||
{ id: 'sp_002', supplierId, sku: 'SKU-002', productName: 'USB-C Cable', costPrice: 1.80, moq: 500, leadTime: 10, quality: 'A' },
|
||||
{ id: 'sp_003', supplierId, sku: 'SKU-003', productName: 'Phone Case', costPrice: 2.50, moq: 200, leadTime: 12, quality: 'B' },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class ApiSuppliersDataSource implements ISuppliersDataSource {
|
||||
private baseUrl = '/api/suppliers';
|
||||
|
||||
async fetchSuppliers(): Promise<Supplier[]> {
|
||||
const res = await fetch(this.baseUrl);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async fetchSupplierDetail(id: string): Promise<Supplier> {
|
||||
const res = await fetch(`${this.baseUrl}/${id}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async saveSupplier(data: Partial<Supplier>): Promise<Supplier> {
|
||||
const res = await fetch(this.baseUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async deleteSupplier(id: string): Promise<void> {
|
||||
await fetch(`${this.baseUrl}/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
async fetchSupplierProducts(supplierId: string): Promise<SupplierProduct[]> {
|
||||
const res = await fetch(`${this.baseUrl}/${supplierId}/products`);
|
||||
return res.json();
|
||||
}
|
||||
}
|
||||
|
||||
const useMock = process.env.REACT_APP_USE_MOCK === 'true';
|
||||
export const suppliersDataSource: ISuppliersDataSource = useMock ? new MockSuppliersDataSource() : new ApiSuppliersDataSource();
|
||||
Reference in New Issue
Block a user