refactor(terminology): 统一术语标准并优化代码类型安全
- 将B2B统一为TOB术语 - 将状态值统一为大写格式 - 优化类型声明,避免使用any - 将float类型替换为decimal以提高精度 - 新增术语标准化文档 - 优化路由结构和菜单分类 - 添加TypeORM实体类 - 增强加密模块安全性 - 重构前端路由结构 - 完善任务模板和验收标准
This commit is contained in:
@@ -25,34 +25,39 @@ const MenuComponent: React.FC = () => {
|
||||
label: <Link to="/dashboard">Dashboard</Link>,
|
||||
},
|
||||
{
|
||||
key: '/product',
|
||||
key: '/products',
|
||||
icon: <ShoppingOutlined />,
|
||||
label: <Link to="/product">Product</Link>,
|
||||
label: <Link to="/products">Products</Link>,
|
||||
},
|
||||
{
|
||||
key: '/orders',
|
||||
icon: <OrderedListOutlined />,
|
||||
label: <Link to="/orders">Orders</Link>,
|
||||
},
|
||||
{
|
||||
key: '/ad',
|
||||
icon: <TabletOutlined />,
|
||||
label: <Link to="/ad">Ad</Link>,
|
||||
},
|
||||
{
|
||||
key: '/inventory',
|
||||
icon: <InboxOutlined />,
|
||||
label: <Link to="/inventory">Inventory</Link>,
|
||||
},
|
||||
{
|
||||
key: '/finance',
|
||||
icon: <DollarOutlined />,
|
||||
label: <Link to="/finance">Finance</Link>,
|
||||
},
|
||||
{
|
||||
key: '/marketing/ads',
|
||||
icon: <TabletOutlined />,
|
||||
label: <Link to="/marketing/ads">Ads</Link>,
|
||||
},
|
||||
{
|
||||
key: '/b2b',
|
||||
icon: <TeamOutlined />,
|
||||
label: <Link to="/b2b">B2B</Link>,
|
||||
},
|
||||
{
|
||||
key: '/finance',
|
||||
icon: <DollarOutlined />,
|
||||
label: <Link to="/finance">Finance</Link>,
|
||||
key: '/independent-sites',
|
||||
icon: <HomeOutlined />,
|
||||
label: <Link to="/independent-sites">Independent Sites</Link>,
|
||||
},
|
||||
{
|
||||
key: '/compliance',
|
||||
@@ -64,11 +69,6 @@ const MenuComponent: React.FC = () => {
|
||||
icon: <SettingOutlined />,
|
||||
label: <Link to="/settings">Settings</Link>,
|
||||
},
|
||||
{
|
||||
key: '/independent-site',
|
||||
icon: <HomeOutlined />,
|
||||
label: <Link to="/independent-site">Independent Site</Link>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -16,18 +16,30 @@ const AppRoutes: React.FC = () => {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
{/* 根路径重定向到仪表板 */}
|
||||
<Route path="/" element={<Navigate to="/dashboard" />} />
|
||||
|
||||
{/* 主布局路由 */}
|
||||
<Route path="/" element={<Layout />}>
|
||||
{/* 核心功能路由 */}
|
||||
<Route path="dashboard" element={<DashboardPage />} />
|
||||
<Route path="product" element={<ProductPage />} />
|
||||
<Route path="products" element={<ProductPage />} />
|
||||
<Route path="orders" element={<OrdersPage />} />
|
||||
<Route path="ad" element={<AdPage />} />
|
||||
<Route path="inventory" element={<InventoryPage />} />
|
||||
<Route path="b2b" element={<B2BPage />} />
|
||||
<Route path="finance" element={<FinancePage />} />
|
||||
|
||||
{/* 营销相关路由 */}
|
||||
<Route path="marketing/ads" element={<AdPage />} />
|
||||
|
||||
{/* B2B相关路由 */}
|
||||
<Route path="b2b" element={<B2BPage />} />
|
||||
|
||||
{/* 独立站相关路由 */}
|
||||
<Route path="independent-sites" element={<IndependentSiteList />} />
|
||||
|
||||
{/* 合规与设置路由 */}
|
||||
<Route path="compliance" element={<CompliancePage />} />
|
||||
<Route path="settings" element={<SettingsPage />} />
|
||||
<Route path="independent-site" element={<IndependentSiteList />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</Router>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import axios from 'axios';
|
||||
|
||||
// 请求缓存
|
||||
const requestCache = new Map<string, { data: any; timestamp: number }>();
|
||||
const CACHE_DURATION = 5 * 60 * 1000; // 5分钟缓存
|
||||
|
||||
// 创建axios实例
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:3000/api', // 后端API基础URL
|
||||
@@ -23,6 +27,14 @@ api.interceptors.request.use(
|
||||
// 响应拦截器
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
// 缓存GET请求的响应
|
||||
if (response.config.method === 'get') {
|
||||
const cacheKey = `${response.config.url}${JSON.stringify(response.config.params)}`;
|
||||
requestCache.set(cacheKey, {
|
||||
data: response.data,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
@@ -32,13 +44,45 @@ api.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
// 带缓存的GET请求
|
||||
const cachedGet = async (url: string, params?: any) => {
|
||||
const cacheKey = `${url}${JSON.stringify(params)}`;
|
||||
const cachedItem = requestCache.get(cacheKey);
|
||||
|
||||
if (cachedItem && (Date.now() - cachedItem.timestamp) < CACHE_DURATION) {
|
||||
return cachedItem.data;
|
||||
}
|
||||
|
||||
const response = await api.get(url, { params });
|
||||
return response;
|
||||
};
|
||||
|
||||
// 批量请求处理
|
||||
const batchRequest = async (requests: Array<{ url: string; method: string; data?: any; params?: any }>) => {
|
||||
try {
|
||||
const responses = await Promise.all(
|
||||
requests.map(request => {
|
||||
if (request.method === 'get') {
|
||||
return cachedGet(request.url, request.params);
|
||||
} else {
|
||||
return api[request.method as keyof typeof api](request.url, request.data, { params: request.params });
|
||||
}
|
||||
})
|
||||
);
|
||||
return responses;
|
||||
} catch (error) {
|
||||
console.error('Batch request failed:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 商品相关API
|
||||
export const productApi = {
|
||||
// 获取商品列表
|
||||
getProducts: (params?: any) => api.get('/products', { params }),
|
||||
getProducts: (params?: any) => cachedGet('/products', params),
|
||||
|
||||
// 获取商品详情
|
||||
getProduct: (id: string) => api.get(`/products/${id}`),
|
||||
getProduct: (id: string) => cachedGet(`/products/${id}`),
|
||||
|
||||
// 创建商品
|
||||
createProduct: (data: any) => api.post('/products', data),
|
||||
@@ -50,34 +94,51 @@ export const productApi = {
|
||||
updatePrice: (id: string, price: number) => api.patch(`/products/${id}/price`, { price }),
|
||||
|
||||
// AI定价
|
||||
getAiPricing: (id: string) => api.get(`/products/${id}/ai-pricing`),
|
||||
getAiPricing: (id: string) => cachedGet(`/products/${id}/ai-pricing`),
|
||||
|
||||
// 上下架商品
|
||||
toggleStatus: (id: string) => api.patch(`/products/${id}/status`),
|
||||
|
||||
// 批量操作
|
||||
batchUpdate: (ids: string[], data: any) => api.post('/products/batch', { ids, data }),
|
||||
|
||||
// 批量获取商品详情
|
||||
batchGetProducts: (ids: string[]) => batchRequest(
|
||||
ids.map(id => ({ url: `/products/${id}`, method: 'get' }))
|
||||
),
|
||||
};
|
||||
|
||||
// 订单相关API
|
||||
export const orderApi = {
|
||||
// 获取订单列表
|
||||
getOrders: (params?: any) => api.get('/orders', { params }),
|
||||
getOrders: (params?: any) => cachedGet('/orders', params),
|
||||
|
||||
// 获取订单详情
|
||||
getOrder: (id: string) => api.get(`/orders/${id}`),
|
||||
getOrder: (id: string) => cachedGet(`/orders/${id}`),
|
||||
|
||||
// 更新订单状态
|
||||
updateStatus: (id: string, status: string) => api.patch(`/orders/${id}/status`, { status }),
|
||||
|
||||
// 处理订单
|
||||
processOrder: (id: string, data: any) => api.post(`/orders/${id}/process`, data),
|
||||
|
||||
// 批量获取订单详情
|
||||
batchGetOrders: (ids: string[]) => batchRequest(
|
||||
ids.map(id => ({ url: `/orders/${id}`, method: 'get' }))
|
||||
),
|
||||
};
|
||||
|
||||
// Dashboard相关API
|
||||
export const dashboardApi = {
|
||||
// 获取Dashboard数据
|
||||
getDashboardData: (params?: any) => api.get('/dashboard', { params }),
|
||||
getDashboardData: (params?: any) => cachedGet('/dashboard', params),
|
||||
};
|
||||
|
||||
// 导出批量请求函数
|
||||
export const apiUtils = {
|
||||
batchRequest,
|
||||
cachedGet,
|
||||
clearCache: () => requestCache.clear(),
|
||||
};
|
||||
|
||||
export default api;
|
||||
Reference in New Issue
Block a user