feat(i18n): 改造10个组件为i18n国际化,同步更新9种语言翻译文件

- 组件改造:EmptyState、ExportPanel、SearchConditionItem、SearchHistoryPanel、
  SearchResultCard、SearchResultList、Select、SortSwitcher、TemplatePanel、
  BottomNavigation、SearchConditionPanel
- 替换硬编码中文为 $t() 调用和 computed 响应式翻译
- 新增翻译键:search(搜索历史/模板/条件)、export(导出选项)、
  common.pleaseSelect 等
- 同步更新 zh-CN、en、zh-TW、ja、ko、es、fr、de、pt 共9种语言文件
- 重构 errorHandler:从 API 错误处理改为本地应用错误处理
- 移除 search.ts 中未使用的 SearchService 接口
This commit is contained in:
张翔
2026-04-29 19:13:55 +08:00
parent 70d3e3a277
commit 330c3af227
26 changed files with 1335 additions and 490 deletions
@@ -1,18 +1,31 @@
import type { ApiError, ErrorType } from './httpClient'
export enum AppErrorType {
CALCULATION_ERROR = 'CALCULATION_ERROR',
DATA_ERROR = 'DATA_ERROR',
STORAGE_ERROR = 'STORAGE_ERROR',
VALIDATION_ERROR = 'VALIDATION_ERROR',
UNKNOWN_ERROR = 'UNKNOWN_ERROR'
}
export interface AppError {
type: AppErrorType
code: number
message: string
detail?: any
}
class ErrorHandler {
private errorMessages: Record<ErrorType, string> = {
NETWORK_ERROR: '网络连接失败,请检查网络设置',
TIMEOUT_ERROR: '请求超时,请稍后重试',
BUSINESS_ERROR: '操作失败,请稍后重试',
AUTH_ERROR: '认证失败,请重新登录',
TOKEN_EXPIRED: '登录已过期,请重新登录',
private errorMessages: Record<AppErrorType, string> = {
CALCULATION_ERROR: '计算出错,请稍后重试',
DATA_ERROR: '数据异常,请稍后重试',
STORAGE_ERROR: '存储操作失败,请检查设备空间',
VALIDATION_ERROR: '输入数据有误,请检查后重试',
UNKNOWN_ERROR: '未知错误,请稍后重试'
}
handleError(error: ApiError): void {
this.logError(error)
this.showErrorMessage(error.message)
handleError(error: AppError | Error): void {
const appError = this.toAppError(error)
this.logError(appError)
this.showErrorMessage(appError.message)
}
showErrorMessage(message: string): void {
@@ -31,8 +44,8 @@ class ErrorHandler {
})
}
logError(error: ApiError): void {
console.error('[API Error]', {
logError(error: AppError): void {
console.error('[App Error]', {
type: error.type,
code: error.code,
message: error.message,
@@ -40,20 +53,23 @@ class ErrorHandler {
})
}
getErrorMessage(error: ApiError): string {
getErrorMessage(error: AppError): string {
return this.errorMessages[error.type] || error.message
}
isAuthError(error: ApiError): boolean {
return error.type === 'AUTH_ERROR' || error.type === 'TOKEN_EXPIRED'
createError(type: AppErrorType, message: string, code: number = 0, detail?: any): AppError {
return { type, code, message, detail }
}
isNetworkError(error: ApiError): boolean {
return error.type === 'NETWORK_ERROR' || error.type === 'TIMEOUT_ERROR'
}
isBusinessError(error: ApiError): boolean {
return error.type === 'BUSINESS_ERROR'
private toAppError(error: AppError | Error): AppError {
if ('type' in error && 'code' in error) {
return error as AppError
}
return {
type: AppErrorType.UNKNOWN_ERROR,
code: 0,
message: error.message || '未知错误'
}
}
}