refactor: 重构代码结构和类型定义,优化类型安全性和代码可维护性

- 添加类型定义文件和类型引用
- 删除废弃的页面模块和导出文件
- 新增聚合管理模块和插件系统
- 修复类型错误和潜在运行时问题
- 更新API基础URL和配置
- 优化组件类型定义和事件处理
- 重构数据源接口和实现
- 完善文档和开发进度记录
This commit is contained in:
2026-03-22 11:25:28 +08:00
parent 15ee1758f5
commit a037843851
88 changed files with 42703 additions and 6395 deletions

View File

@@ -4,32 +4,55 @@
* 仅在USE_MOCK=true时启用
*/
import { Inventory } from '../types/inventory';
import { Inventory, InventoryStatus } from '../types/inventory';
export interface Warehouse {
id: string;
name: string;
code: string;
address: string;
city: string;
country: string;
capacity: number;
currentUsage: number;
status: 'active' | 'inactive' | 'maintenance';
manager: string;
phone: string;
email: string;
createdAt: string;
updatedAt: string;
}
export interface InventoryForecast {
id: string;
productId: string;
productName: string;
sku: string;
currentStock: number;
forecastedDemand: number;
recommendedOrder: number;
leadTime: number;
riskLevel: 'low' | 'medium' | 'high';
date: string;
}
export interface InventoryQueryParams {
productId?: string;
status?: InventoryStatus;
warehouseId?: string;
page?: number;
pageSize?: number;
}
// 库存数据接口
export interface InventoryDataSource {
list(params?: {
page?: number;
pageSize?: number;
productId?: string;
status?: string;
warehouseId?: string;
}): Promise<{ data: Inventory[]; total: number }>;
list(params?: InventoryQueryParams): Promise<{ data: Inventory[]; total: number }>;
get(id: string): Promise<Inventory | null>;
create(inventory: Omit<Inventory, 'id' | 'createdAt' | 'updatedAt'>): Promise<Inventory>;
update(id: string, inventory: Partial<Inventory>): Promise<Inventory | null>;
updateStock(id: string, quantity: number): Promise<Inventory | null>;
getByProductId(productId: string): Promise<Inventory[]>;
getByWarehouseId(warehouseId: string): Promise<Inventory[]>;
getLowStockAlerts(threshold: number): Promise<Inventory[]>;
getInventoryStatistics(): Promise<{
totalItems: number;
totalStock: number;
@@ -37,19 +60,12 @@ export interface InventoryDataSource {
outOfStockItems: number;
warehouseDistribution: Record<string, number>;
}>;
fetchWarehouses(): Promise<Warehouse[]>;
getInventoryForecasts(): Promise<InventoryForecast[]>;
}
// 库存DataSource实现
export class InventoryDataSourceImpl implements InventoryDataSource {
async list(params?: {
page?: number;
pageSize?: number;
productId?: string;
status?: string;
warehouseId?: string;
}): Promise<{ data: Inventory[]; total: number }> {
// 这里应该调用实际的API
// 暂时返回Mock数据
async list(params?: InventoryQueryParams): Promise<{ data: Inventory[]; total: number }> {
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -57,7 +73,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -70,7 +86,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '无线耳机',
quantity: 200,
threshold: 30,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-11'),
@@ -83,7 +99,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '运动鞋',
quantity: 150,
threshold: 25,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-12'),
@@ -96,7 +112,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手机',
quantity: 5,
threshold: 10,
status: 'low_stock',
status: InventoryStatus.LOW_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-09'),
@@ -109,7 +125,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '平板电脑',
quantity: 0,
threshold: 15,
status: 'out_of_stock',
status: InventoryStatus.OUT_OF_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-08'),
@@ -145,8 +161,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async get(id: string): Promise<Inventory | null> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -154,7 +168,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -167,7 +181,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '无线耳机',
quantity: 200,
threshold: 30,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-11'),
@@ -181,8 +195,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async create(inventory: Omit<Inventory, 'id' | 'createdAt' | 'updatedAt'>): Promise<Inventory> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const newInventory: Inventory = {
...inventory,
id: `inv_${Date.now()}`,
@@ -194,8 +206,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async update(id: string, inventory: Partial<Inventory>): Promise<Inventory | null> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const existingInventory = await this.get(id);
if (!existingInventory) {
return null;
@@ -211,22 +221,20 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async updateStock(id: string, quantity: number): Promise<Inventory | null> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const existingInventory = await this.get(id);
if (!existingInventory) {
return null;
}
const newQuantity = existingInventory.quantity + quantity;
let status: 'in_stock' | 'low_stock' | 'out_of_stock';
let status: InventoryStatus;
if (newQuantity <= 0) {
status = 'out_of_stock';
status = InventoryStatus.OUT_OF_STOCK;
} else if (newQuantity < existingInventory.threshold) {
status = 'low_stock';
status = InventoryStatus.LOW_STOCK;
} else {
status = 'in_stock';
status = InventoryStatus.IN_STOCK;
}
const updatedInventory: Inventory = {
@@ -241,8 +249,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async getByProductId(productId: string): Promise<Inventory[]> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -250,7 +256,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -263,7 +269,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '无线耳机',
quantity: 200,
threshold: 30,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-11'),
@@ -276,8 +282,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async getByWarehouseId(warehouseId: string): Promise<Inventory[]> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -285,7 +289,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -298,7 +302,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '无线耳机',
quantity: 200,
threshold: 30,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-11'),
@@ -311,7 +315,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '运动鞋',
quantity: 150,
threshold: 25,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-12'),
@@ -324,8 +328,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
}
async getLowStockAlerts(threshold: number): Promise<Inventory[]> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -333,7 +335,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -346,7 +348,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手机',
quantity: 5,
threshold: 10,
status: 'low_stock',
status: InventoryStatus.LOW_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-09'),
@@ -359,7 +361,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '平板电脑',
quantity: 0,
threshold: 15,
status: 'out_of_stock',
status: InventoryStatus.OUT_OF_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-08'),
@@ -378,8 +380,6 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
outOfStockItems: number;
warehouseDistribution: Record<string, number>;
}> {
// 这里应该调用实际的API
// 暂时返回Mock数据
const mockInventory: Inventory[] = [
{
id: 'inv_1',
@@ -387,7 +387,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手表',
quantity: 100,
threshold: 20,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-10'),
@@ -400,7 +400,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '无线耳机',
quantity: 200,
threshold: 30,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-11'),
@@ -413,7 +413,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '运动鞋',
quantity: 150,
threshold: 25,
status: 'in_stock',
status: InventoryStatus.IN_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-12'),
@@ -426,7 +426,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '智能手机',
quantity: 5,
threshold: 10,
status: 'low_stock',
status: InventoryStatus.LOW_STOCK,
warehouseId: 'warehouse_1',
warehouseName: '北京仓库',
lastStockUpdate: new Date('2026-03-09'),
@@ -439,7 +439,7 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
productName: '平板电脑',
quantity: 0,
threshold: 15,
status: 'out_of_stock',
status: InventoryStatus.OUT_OF_STOCK,
warehouseId: 'warehouse_2',
warehouseName: '上海仓库',
lastStockUpdate: new Date('2026-03-08'),
@@ -450,12 +450,14 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
const totalItems = mockInventory.length;
const totalStock = mockInventory.reduce((sum, item) => sum + item.quantity, 0);
const lowStockItems = mockInventory.filter(i => i.status === 'low_stock').length;
const outOfStockItems = mockInventory.filter(i => i.status === 'out_of_stock').length;
const lowStockItems = mockInventory.filter(i => i.status === InventoryStatus.LOW_STOCK).length;
const outOfStockItems = mockInventory.filter(i => i.status === InventoryStatus.OUT_OF_STOCK).length;
const warehouseDistribution: Record<string, number> = {};
mockInventory.forEach(item => {
warehouseDistribution[item.warehouseName] = (warehouseDistribution[item.warehouseName] || 0) + item.quantity;
if (item.warehouseName) {
warehouseDistribution[item.warehouseName] = (warehouseDistribution[item.warehouseName] || 0) + item.quantity;
}
});
return {
@@ -466,7 +468,84 @@ export class InventoryDataSourceImpl implements InventoryDataSource {
warehouseDistribution,
};
}
async fetchWarehouses(): Promise<Warehouse[]> {
return [
{
id: 'warehouse_1',
name: '北京仓库',
code: 'BJ-WH-001',
address: '北京市朝阳区建国路88号',
city: '北京',
country: '中国',
capacity: 10000,
currentUsage: 7500,
status: 'active',
manager: '张三',
phone: '010-12345678',
email: 'zhangsan@example.com',
createdAt: '2026-01-01',
updatedAt: '2026-03-15',
},
{
id: 'warehouse_2',
name: '上海仓库',
code: 'SH-WH-001',
address: '上海市浦东新区张江路100号',
city: '上海',
country: '中国',
capacity: 15000,
currentUsage: 12000,
status: 'active',
manager: '李四',
phone: '021-87654321',
email: 'lisi@example.com',
createdAt: '2026-01-15',
updatedAt: '2026-03-16',
},
];
}
async getInventoryForecasts(): Promise<InventoryForecast[]> {
return [
{
id: 'forecast_1',
productId: '1',
productName: '智能手表',
sku: 'WATCH-001',
currentStock: 100,
forecastedDemand: 150,
recommendedOrder: 50,
leadTime: 7,
riskLevel: 'low',
date: '2026-03-21',
},
{
id: 'forecast_2',
productId: '2',
productName: '无线耳机',
sku: 'EARPHONE-001',
currentStock: 200,
forecastedDemand: 180,
recommendedOrder: 0,
leadTime: 5,
riskLevel: 'low',
date: '2026-03-21',
},
{
id: 'forecast_3',
productId: '4',
productName: '智能手机',
sku: 'PHONE-001',
currentStock: 5,
forecastedDemand: 50,
recommendedOrder: 45,
leadTime: 10,
riskLevel: 'high',
date: '2026-03-21',
},
];
}
}
// 导出DataSource实例
export const inventoryDataSource = new InventoryDataSourceImpl();