import { Component, ErrorInfo, ReactNode } from 'react' import { Button } from './ui' interface Props { children: ReactNode fallback?: ReactNode /** * 该边界是否铺满整个视口。 * * 应用最外层的边界应铺满(`true`,默认);而当边界下沉到 * 路由级、嵌在 SiteLayout 的
里时,铺满视口会撑开 * 布局并让页头页脚错位 —— 那种场景传 `false`,改为局部卡片。 */ fullScreen?: boolean } interface State { hasError: boolean error: Error | null } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null, } public static getDerivedStateFromError(error: Error): State { return { hasError: true, error } } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo) } public render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback } const fullScreen = this.props.fullScreen ?? true return (

EXCEPTION

页面出现错误

{this.state.error?.message || '未知错误'}

) } return this.props.children } }