diff --git a/packages/plugins/@hera/plugin-core/src/client/components/custom-components/CustomAssociatedField.tsx b/packages/plugins/@hera/plugin-core/src/client/components/custom-components/CustomAssociatedField.tsx index 9a884d44e..dda7356c9 100644 --- a/packages/plugins/@hera/plugin-core/src/client/components/custom-components/CustomAssociatedField.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/components/custom-components/CustomAssociatedField.tsx @@ -1,11 +1,12 @@ import { SchemaComponent } from '@nocobase/client'; import React from 'react'; -import { ErrorBoundary } from './ErrorBoundary'; +import { ErrorBoundary } from 'react-error-boundary'; +import { ErrorBoundaryFallBack } from './ErrorBoundary'; export const CustomAssociatedField = (props) => { if (!props.component) return; return ( - + }> { return
请选择组件
; @@ -14,7 +15,7 @@ export const CustomComponentStub = (props) => { export const CustomComponentDispatcher = (props) => { if (!props.component) return; return ( - + }> { if (!props.component) return; return ( - + }> { +export const ErrorBoundaryFallBack = () => { const { t } = useTranslation(); - const [hasError, setHasError] = useState(false); - - useEffect(() => { - // 捕获子组件的错误 - const handleError = (error) => { - console.error('Error caught by ErrorBoundary:', error); - setHasError(true); - }; - - // TODO: 或者上报至错误服务器,记录 - // 添加错误处理函数到 window - window.addEventListener('error', handleError); - // 移除事件监听器 - return () => { - window.removeEventListener('error', handleError); - }; - }, []); - // 如果有错误,展示备用, 可以通过fallback回调自定义,或者显示默认 UI 组件 - if (hasError) { - return fallback ? fallback :
{t('Something went wrong. Please try again later.')}
; - } - - // 否则渲染子组件 - return children; + return
{t('Something went wrong. Please contact the developer to resolve the issue.')}
; }; diff --git a/packages/plugins/@hera/plugin-core/src/locale/en-US.json b/packages/plugins/@hera/plugin-core/src/locale/en-US.json index f0c49852b..0d741f266 100644 --- a/packages/plugins/@hera/plugin-core/src/locale/en-US.json +++ b/packages/plugins/@hera/plugin-core/src/locale/en-US.json @@ -19,5 +19,5 @@ "Please select": "Please select", "Association field": "Association field", "HomePage Config": "HomePage Config", - "Something went wrong. Please try again later.": "Something went wrong. Please try again later." + "Something went wrong. Please contact the developer to resolve the issue.": "Something went wrong. Please contact the developer to resolve the issue." } diff --git a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json index c6de3b9be..6a550ec41 100644 --- a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json +++ b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json @@ -19,5 +19,5 @@ "Please select": "请选择", "Association field": "关联字段", "HomePage Config": "主页配置", - "Something went wrong. Please try again later.": "系统内部显示错误,请稍后再试" + "Something went wrong. Please contact the developer to resolve the issue.": "系统内部错误,请联系开发者解决" }