From fcf31294b7f4e5c5e77f7ee75694e9066e7b5c04 Mon Sep 17 00:00:00 2001 From: callmeyan Date: Mon, 10 Mar 2025 13:45:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(dev/main):=20=E2=9C=A8=EF=B8=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=94=99=E8=AF=AF=E9=A1=B5=E9=9D=A2=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/translations/en-US.json | 5 +++ src/i18n/translations/zh-CN.json | 5 +++ src/routes/error.tsx | 58 ++++++++++++++++++-------------- src/routes/index.tsx | 4 +-- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/i18n/translations/en-US.json b/src/i18n/translations/en-US.json index eb29a4a..9024c99 100644 --- a/src/i18n/translations/en-US.json +++ b/src/i18n/translations/en-US.json @@ -1,9 +1,14 @@ { "AppTitle": "AI Livesteam", + "go_to_home": "Go to Homepage" , "Hello": "Hello", "cancel": "Cancel", "close": "Close", "service_error": "Service exception, please contact customer support.", + "error_401": "You do not have permission to access this page", + "error_403": "You do not have permission to access this page", + "error_404": "Page not found", + "error_500": "Service exception, please contact customer support.", "confirm": { "push_title": "Push Notice", "push_video": "Are you sure editing selected news?", diff --git a/src/i18n/translations/zh-CN.json b/src/i18n/translations/zh-CN.json index f0b7562..11bf1f4 100644 --- a/src/i18n/translations/zh-CN.json +++ b/src/i18n/translations/zh-CN.json @@ -1,9 +1,14 @@ { "AppTitle": "数字人直播", + "go_to_home": "返回首页" , "Hello": "你好", "cancel": "取消", "close": "关闭", "service_error": "新闻异常,无法生成,请咨询客服", + "error_401": "您没有权限访问本页面", + "error_403": "您没有权限访问本页面", + "error_404": "访问的页面不存在", + "error_500": "服务异常,请咨询客服.", "confirm": { "push_title": "推流提示", "push_video": "是否确定一键推流选中新闻视频?", diff --git a/src/routes/error.tsx b/src/routes/error.tsx index 1234960..01b62f5 100644 --- a/src/routes/error.tsx +++ b/src/routes/error.tsx @@ -1,47 +1,53 @@ -import React from "react"; +import React, {useMemo} from "react"; import {isRouteErrorResponse, useNavigate, useRouteError} from 'react-router-dom'; import {Button} from "antd"; import error500 from "@/assets/images/error/Error500.png"; +import {useTranslation} from "react-i18next"; // ==============================|| ELEMENT ERROR - COMMON ||============================== // const ErrorBoundary: React.FC<{ minHeight?: string | number; errorCode?: 401 | 404 | 503 -}> = ({ errorCode}) => { +}> = ({errorCode}) => { + const {t, i18n} = useTranslation() const error = useRouteError() as Error; - let errorMessage = '服务异常,请稍后再试或者联系管理员.' - - const errorConfig: { - [key: number]: string - } = { - 401: '您没有权限访问本页面!', - 404: '访问的页面不存在!', - 503: '服务异常请联系管理员!', - } - if (isRouteErrorResponse(error)) { - if (errorConfig[error.status]) { - errorMessage = `Error ${error.status} - ${errorConfig[error.status]}`; + console.log(error) + const errorMessage = useMemo(() => { + let _message = t('error_500') + const errorConfig: { + [key: number]: string + } = { + 401: t('error_401'), + 403: t('error_403'), + 404: t('error_404'), + 500: t('error_500'), } - } - if (errorCode) { - if (errorConfig[errorCode]) { - errorMessage = `Error ${errorCode} - ${errorConfig[errorCode]}`; + if (isRouteErrorResponse(error)) { + if (errorConfig[error.status]) { + _message = `Error ${error.status} - ${errorConfig[error.status]}`; + } } - } + if (errorCode) { + if (errorConfig[errorCode]) { + _message = `Error ${errorCode} - ${errorConfig[errorCode]}`; + } + } + return _message + }, [i18n, errorCode]) const navigate = useNavigate() const handleGoBack = () => { navigate('/') } - return (
-
+ return (
+
error
-
+
-
+
Internal Server Error
@@ -62,10 +68,10 @@ const ErrorBoundary: React.FC<{ whiteSpace: 'break-spaces' }}>{error.stack} -
} -
+
} +
diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 7cae14d..95e1fbb 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -16,7 +16,7 @@ import useGlobalConfig from "@/hooks/useGlobalConfig.ts"; const router = createBrowserRouter([ ...routes, - {path: '*', element: } + {path: '*', element: } ], { basename: import.meta.env.VITE_APP_BASE_NAME, future: { @@ -28,9 +28,9 @@ const router = createBrowserRouter([ } }) -const {globalConfig} = useGlobalConfig(); // future={{v7_startTransition: true,v7_relativeSplatPath: true}} const AppRouter = () => { + const {globalConfig} = useGlobalConfig(); const {t,i18n} = useTranslation(); useEffect(() => {