feat: 实现Operation-Agent核心功能及电商平台适配器

refactor: 重构项目结构,分离server和dashboard代码
style: 统一代码风格,修复lint警告
test: 添加平台适配器工厂测试用例
ci: 更新CI/CD流程,增加语义验证和性能测试
docs: 添加语义中心文档,定义统一数据模型和状态机
This commit is contained in:
2026-03-19 15:23:56 +08:00
parent aa2cf560c6
commit 8de9ea0aaa
41 changed files with 5615 additions and 497 deletions

View File

@@ -0,0 +1,57 @@
import axios from 'axios';
// 创建axios实例
const http = axios.create({
baseURL: 'http://localhost:3000', // 后端API基础URL
timeout: 10000, // 请求超时时间
headers: {
'Content-Type': 'application/json',
},
});
// 请求拦截器
http.interceptors.request.use(
(config) => {
// 可以在这里添加token等认证信息
// const token = localStorage.getItem('token');
// if (token) {
// config.headers.Authorization = `Bearer ${token}`;
// }
return config;
},
(error) => {
return Promise.reject(error);
}
);
// 响应拦截器
http.interceptors.response.use(
(response) => {
return response;
},
(error) => {
// 处理错误响应
if (error.response) {
switch (error.response.status) {
case 401:
// 未授权处理
break;
case 403:
// 禁止访问处理
break;
case 404:
// 资源不存在处理
break;
case 500:
// 服务器错误处理
break;
default:
// 其他错误处理
break;
}
}
return Promise.reject(error);
}
);
export { http };

View File

@@ -0,0 +1,95 @@
import { http } from './http';
export interface StoreBindingData {
merchantId: string;
platform: string;
platformShopId: string;
name: string;
description?: string;
authInfo: Record<string, any>;
}
export interface Store {
id: string;
merchantId: string;
name: string;
platform: string;
platformShopId: string;
description: string;
status: string;
created_at: string;
updated_at: string;
}
export interface SyncResult {
success: boolean;
count: number;
}
export class OperationAgentService {
/**
* 绑定店铺
*/
async bindStore(data: StoreBindingData): Promise<Store> {
const response = await http.post<Store>('/api/operation-agent/stores', data);
return response.data;
}
/**
* 获取商户的店铺列表
*/
async getStores(merchantId: string): Promise<Store[]> {
const response = await http.get<Store[]>(`/api/operation-agent/stores/${merchantId}`);
return response.data;
}
/**
* 获取店铺详情
*/
async getStore(storeId: string): Promise<Store> {
const response = await http.get<Store>(`/api/operation-agent/stores/detail/${storeId}`);
return response.data;
}
/**
* 同步店铺商品
*/
async syncProducts(storeId: string): Promise<SyncResult> {
const response = await http.post<SyncResult>(`/api/operation-agent/stores/${storeId}/products/sync`);
return response.data;
}
/**
* 同步店铺订单
*/
async syncOrders(storeId: string): Promise<SyncResult> {
const response = await http.post<SyncResult>(`/api/operation-agent/stores/${storeId}/orders/sync`);
return response.data;
}
/**
* 更新商品价格
*/
async updateProductPrice(storeId: string, productId: string, price: number): Promise<boolean> {
const response = await http.put<boolean>(`/api/operation-agent/stores/${storeId}/products/${productId}/price`, { price });
return response.data;
}
/**
* 停用店铺
*/
async deactivateStore(storeId: string): Promise<Store> {
const response = await http.put<Store>(`/api/operation-agent/stores/${storeId}/deactivate`);
return response.data;
}
/**
* 重新激活店铺
*/
async reactivateStore(storeId: string): Promise<Store> {
const response = await http.put<Store>(`/api/operation-agent/stores/${storeId}/reactivate`);
return response.data;
}
}
export const operationAgentService = new OperationAgentService();