diff --git a/components/PageErrorBoundary.tsx b/components/PageErrorBoundary.tsx index 6bb511e..bb1cc12 100644 --- a/components/PageErrorBoundary.tsx +++ b/components/PageErrorBoundary.tsx @@ -1,8 +1,9 @@ import { Component, ErrorInfo, ReactNode } from 'react'; +import { withTranslation, type WithTranslation } from 'react-i18next'; import { AlertCircle, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; -interface Props { +interface Props extends WithTranslation { children: ReactNode; resetKey?: string | number; } @@ -12,11 +13,7 @@ interface State { error: Error | null; } -/** - * 页面级错误边界组件:捕获子组件树中的 JavaScript 错误 - * 完美适配 shadcn/ui 语义化主题与暗黑模式 - */ -export class PageErrorBoundary extends Component { +class PageErrorBoundaryBase extends Component { state: State = { hasError: false, error: null, @@ -41,26 +38,22 @@ export class PageErrorBoundary extends Component { }; render() { + const { t } = this.props; if (this.state.hasError) { return (
- {/* - 1. 适配暗黑模式的容器设计: - 不再使用 border-red-200 / bg-red-50,改用标准的 border-destructive/20 和 bg-destructive/5, - 并在黑夜模式下会自动转为深红底色,绝不刺眼。 - */}
- {/* 2. 状态符号改用标准的 text-destructive 语义色 */}
-

该功能运行异常

+

+ {t('pageErrorBoundary.title')} +

- 该页面在加载或渲染时遇到了内部脚本错误。您可以尝试重试,或者通过导航菜单切换到其他工具。 + {t('pageErrorBoundary.description')}

- {/* 3. 错误日志展示:使用与 shadcn 贴合的深色代码块包裹 */} {this.state.error && (
@@ -69,11 +62,6 @@ export class PageErrorBoundary extends Component {
               
)} - {/* - 4. 严谨调用 shadcn 原子 Button: - 去掉全部手动指定的红底白字类名,直接启用 variant="destructive"。 - 它会自动处理 hover 颜色变化、暗黑模式切换以及无障碍高亮边框。 - */}
@@ -92,4 +80,5 @@ export class PageErrorBoundary extends Component { } } +export const PageErrorBoundary = withTranslation('common')(PageErrorBoundaryBase); export default PageErrorBoundary;