refactor: 优化代码结构并修复类型问题
- 移除未使用的TabPane组件 - 修复类型定义和导入方式 - 优化mock数据源的环境变量判断逻辑 - 更新文档结构并归档旧文件 - 添加新的UI组件和Memo组件 - 调整API路径和响应处理
This commit is contained in:
225
dashboard/src/contexts/LocaleContext.tsx
Normal file
225
dashboard/src/contexts/LocaleContext.tsx
Normal file
@@ -0,0 +1,225 @@
|
||||
import React, { createContext, useState, useContext, ReactNode } from 'react';
|
||||
|
||||
interface LocaleContextType {
|
||||
locale: string;
|
||||
setLocale: (locale: string) => void;
|
||||
t: (key: string, options?: Record<string, any>) => string;
|
||||
}
|
||||
|
||||
const zhCN = {
|
||||
'app.name': 'Crawlful Hub',
|
||||
'app.title': '跨境电商管理平台',
|
||||
'nav.home': '首页',
|
||||
'nav.dashboard': '控制台',
|
||||
'nav.products': '商品管理',
|
||||
'nav.orders': '订单管理',
|
||||
'nav.inventory': '库存管理',
|
||||
'nav.logistics': '物流管理',
|
||||
'nav.finance': '财务管理',
|
||||
'nav.marketing': '营销管理',
|
||||
'nav.analytics': '数据分析',
|
||||
'nav.settings': '系统设置',
|
||||
'login.title': '欢迎回来',
|
||||
'login.subtitle': '登录您的账户',
|
||||
'login.username': '用户名或邮箱',
|
||||
'login.password': '密码',
|
||||
'login.remember': '记住我',
|
||||
'login.forgot': '忘记密码?',
|
||||
'login.submit': '登录',
|
||||
'login.noAccount': '还没有账户?',
|
||||
'login.signup': '立即注册',
|
||||
'login.verificationCode': '验证码',
|
||||
'login.loginSuccess': '登录成功,正在跳转...',
|
||||
'login.loginFailed': '登录失败,请检查您的凭证',
|
||||
'login.invalidCaptcha': '验证码错误',
|
||||
'login.orContinueWith': '或使用以下方式登录',
|
||||
'login.welcomeBack': '欢迎回来',
|
||||
'dashboard.title': '控制台',
|
||||
'dashboard.totalSales': '总销售额',
|
||||
'dashboard.orders': '订单数',
|
||||
'dashboard.conversion': '转化率',
|
||||
'dashboard.avgOrderValue': '平均订单价值',
|
||||
'dashboard.salesTrend': '销售与订单趋势',
|
||||
'dashboard.topProducts': '热销商品',
|
||||
'dashboard.recentOrders': '最近订单',
|
||||
'dashboard.refresh': '刷新',
|
||||
'dashboard.export': '导出',
|
||||
'dashboard.customize': '自定义',
|
||||
'dashboard.allShops': '所有店铺',
|
||||
'common.search': '搜索',
|
||||
'common.reset': '重置',
|
||||
'common.confirm': '确认',
|
||||
'common.cancel': '取消',
|
||||
'common.save': '保存',
|
||||
'common.delete': '删除',
|
||||
'common.edit': '编辑',
|
||||
'common.add': '添加',
|
||||
'common.view': '查看',
|
||||
'common.submit': '提交',
|
||||
'common.loading': '加载中...',
|
||||
'common.noData': '暂无数据',
|
||||
'common.success': '操作成功',
|
||||
'common.error': '操作失败',
|
||||
'common.warning': '警告',
|
||||
'common.info': '提示',
|
||||
'common.yes': '是',
|
||||
'common.no': '否',
|
||||
'common.all': '全部',
|
||||
'common.select': '请选择',
|
||||
'common.required': '必填',
|
||||
'common.optional': '选填',
|
||||
'common.up': '上升',
|
||||
'common.down': '下降',
|
||||
'product.list': '商品列表',
|
||||
'product.add': '添加商品',
|
||||
'product.edit': '编辑商品',
|
||||
'product.delete': '删除商品',
|
||||
'product.name': '商品名称',
|
||||
'product.price': '价格',
|
||||
'product.stock': '库存',
|
||||
'product.status': '状态',
|
||||
'product.category': '分类',
|
||||
'order.list': '订单列表',
|
||||
'order.detail': '订单详情',
|
||||
'order.status': '订单状态',
|
||||
'order.amount': '订单金额',
|
||||
'order.date': '下单日期',
|
||||
'order.customer': '客户信息',
|
||||
'settings.title': '系统设置',
|
||||
'settings.profile': '个人资料',
|
||||
'settings.system': '系统配置',
|
||||
'settings.users': '用户管理',
|
||||
'settings.language': '语言设置',
|
||||
'settings.theme': '主题设置',
|
||||
};
|
||||
|
||||
const enUS = {
|
||||
'app.name': 'Crawlful Hub',
|
||||
'app.title': 'Cross-Border E-commerce Management Platform',
|
||||
'nav.home': 'Home',
|
||||
'nav.dashboard': 'Dashboard',
|
||||
'nav.products': 'Products',
|
||||
'nav.orders': 'Orders',
|
||||
'nav.inventory': 'Inventory',
|
||||
'nav.logistics': 'Logistics',
|
||||
'nav.finance': 'Finance',
|
||||
'nav.marketing': 'Marketing',
|
||||
'nav.analytics': 'Analytics',
|
||||
'nav.settings': 'Settings',
|
||||
'login.title': 'Welcome Back',
|
||||
'login.subtitle': 'Sign in to your account',
|
||||
'login.username': 'Username or Email',
|
||||
'login.password': 'Password',
|
||||
'login.remember': 'Remember me',
|
||||
'login.forgot': 'Forgot password?',
|
||||
'login.submit': 'Sign In',
|
||||
'login.noAccount': "Don't have an account?",
|
||||
'login.signup': 'Sign up',
|
||||
'login.verificationCode': 'Verification Code',
|
||||
'login.loginSuccess': 'Login successful! Redirecting...',
|
||||
'login.loginFailed': 'Login failed. Please check your credentials.',
|
||||
'login.invalidCaptcha': 'Invalid verification code',
|
||||
'login.orContinueWith': 'Or continue with',
|
||||
'login.welcomeBack': 'Welcome Back',
|
||||
'dashboard.title': 'Dashboard',
|
||||
'dashboard.totalSales': 'Total Sales',
|
||||
'dashboard.orders': 'Orders',
|
||||
'dashboard.conversion': 'Conversion Rate',
|
||||
'dashboard.avgOrderValue': 'Avg Order Value',
|
||||
'dashboard.salesTrend': 'Sales and Orders Trend',
|
||||
'dashboard.topProducts': 'Top Performing Products',
|
||||
'dashboard.recentOrders': 'Recent Orders',
|
||||
'dashboard.refresh': 'Refresh',
|
||||
'dashboard.export': 'Export',
|
||||
'dashboard.customize': 'Customize',
|
||||
'dashboard.allShops': 'All Shops',
|
||||
'common.search': 'Search',
|
||||
'common.reset': 'Reset',
|
||||
'common.confirm': 'Confirm',
|
||||
'common.cancel': 'Cancel',
|
||||
'common.save': 'Save',
|
||||
'common.delete': 'Delete',
|
||||
'common.edit': 'Edit',
|
||||
'common.add': 'Add',
|
||||
'common.view': 'View',
|
||||
'common.submit': 'Submit',
|
||||
'common.loading': 'Loading...',
|
||||
'common.noData': 'No Data',
|
||||
'common.success': 'Success',
|
||||
'common.error': 'Error',
|
||||
'common.warning': 'Warning',
|
||||
'common.info': 'Info',
|
||||
'common.yes': 'Yes',
|
||||
'common.no': 'No',
|
||||
'common.all': 'All',
|
||||
'common.select': 'Please select',
|
||||
'common.required': 'Required',
|
||||
'common.optional': 'Optional',
|
||||
'common.up': 'Up',
|
||||
'common.down': 'Down',
|
||||
'product.list': 'Product List',
|
||||
'product.add': 'Add Product',
|
||||
'product.edit': 'Edit Product',
|
||||
'product.delete': 'Delete Product',
|
||||
'product.name': 'Product Name',
|
||||
'product.price': 'Price',
|
||||
'product.stock': 'Stock',
|
||||
'product.status': 'Status',
|
||||
'product.category': 'Category',
|
||||
'order.list': 'Order List',
|
||||
'order.detail': 'Order Detail',
|
||||
'order.status': 'Order Status',
|
||||
'order.amount': 'Order Amount',
|
||||
'order.date': 'Order Date',
|
||||
'order.customer': 'Customer Info',
|
||||
'settings.title': 'Settings',
|
||||
'settings.profile': 'Profile',
|
||||
'settings.system': 'System',
|
||||
'settings.users': 'User Management',
|
||||
'settings.language': 'Language',
|
||||
'settings.theme': 'Theme',
|
||||
};
|
||||
|
||||
const translations = {
|
||||
'zh-CN': zhCN,
|
||||
'en-US': enUS,
|
||||
};
|
||||
|
||||
const LocaleContext = createContext<LocaleContextType | undefined>(undefined);
|
||||
|
||||
export const LocaleProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const [locale, setLocale] = useState<string>('zh-CN');
|
||||
|
||||
const t = (key: string, options?: Record<string, any>): string => {
|
||||
const translation = translations[locale]?.[key] || translations['en-US']?.[key] || key;
|
||||
if (options) {
|
||||
return Object.entries(options).reduce((result, [placeholder, value]) => {
|
||||
return result.replace(new RegExp(`\{${placeholder}\}`, 'g'), String(value));
|
||||
}, translation);
|
||||
}
|
||||
return translation;
|
||||
};
|
||||
|
||||
return (
|
||||
<LocaleContext.Provider value={{ locale, setLocale, t }}>
|
||||
{children}
|
||||
</LocaleContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const defaultContext: LocaleContextType = {
|
||||
locale: 'zh-CN',
|
||||
setLocale: () => {},
|
||||
t: (key: string) => key,
|
||||
};
|
||||
|
||||
export const useLocale = (): LocaleContextType => {
|
||||
const context = useContext(LocaleContext);
|
||||
if (!context) {
|
||||
console.warn('useLocale is used outside LocaleProvider, using default context');
|
||||
return defaultContext;
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
export default LocaleContext;
|
||||
Reference in New Issue
Block a user