From 75b59f6ffe6387450663a43d56dd7d5e93b9746e Mon Sep 17 00:00:00 2001 From: zhaowei Date: Thu, 17 Jul 2025 08:51:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B9=E7=9B=AE=E9=87=8C=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=88=B0=E9=A6=96=E9=A1=B5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/src/app.tsx | 17 ++++++++++------- react-ui/src/components/ErrorBoundary/index.tsx | 3 ++- .../components/RightContent/AvatarDropdown.tsx | 2 +- react-ui/src/pages/404.tsx | 3 ++- .../src/pages/Home/components/Intro/index.tsx | 2 +- .../src/pages/Home/components/Service/index.tsx | 2 +- react-ui/src/pages/User/Login/login.tsx | 3 ++- react-ui/src/pages/missingPage.jsx | 3 ++- react-ui/src/utils/constant.ts | 3 +++ react-ui/src/utils/index.ts | 12 +++++++++++- 10 files changed, 35 insertions(+), 15 deletions(-) diff --git a/react-ui/src/app.tsx b/react-ui/src/app.tsx index c0ea08c5..16d0e562 100644 --- a/react-ui/src/app.tsx +++ b/react-ui/src/app.tsx @@ -20,7 +20,8 @@ import { setRemoteMenu, } from './services/session'; import './styles/menu.less'; -import { needAuth } from './utils'; +import { isLoginPage, needAuth } from './utils'; +import { HomeUrl } from './utils/constant'; import { closeAllModals } from './utils/modal'; import { gotoLoginPage } from './utils/ui'; export { requestConfig as request } from './requestConfig'; @@ -41,7 +42,7 @@ export async function getInitialState(): Promise { } as API.CurrentUser; } catch (error) { console.error('getInitialState', error); - gotoLoginPage(); + gotoLoginPage(true); } return undefined; }; @@ -117,27 +118,29 @@ export const layout: RuntimeConfig['layout'] = ({ initialState }) => { }; export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => { + debugger; // console.log('onRouteChange'); // 路由切换时,尤其是回退时,关闭打开的弹框 closeAllModals(); const { location } = e; + const pathname = location.pathname; const token = getAccessToken(); // 没有 token,跳转到登录页面 - if (!token && needAuth(location.pathname)) { - gotoLoginPage(); + if (!token && needAuth(pathname)) { + gotoLoginPage(false); return; } // 有 token, 登录页面直接跳转到首页 - if (token && !needAuth(location.pathname)) { - history.push('/'); + if (token && isLoginPage(pathname)) { + history.push(HomeUrl); } const menus = getRemoteMenu(); // 没有菜单,刷新页面 - if (menus === null && needAuth(location.pathname)) { + if (menus === null && needAuth(pathname)) { history.go(0); } }; diff --git a/react-ui/src/components/ErrorBoundary/index.tsx b/react-ui/src/components/ErrorBoundary/index.tsx index 66bc8d94..2483c9e9 100644 --- a/react-ui/src/components/ErrorBoundary/index.tsx +++ b/react-ui/src/components/ErrorBoundary/index.tsx @@ -1,4 +1,5 @@ import KFEmpty, { EmptyType } from '@/components/KFEmpty'; +import { HomeUrl } from '@/utils/constant'; import { Button } from 'antd'; import { Component, ReactNode } from 'react'; @@ -55,7 +56,7 @@ function ErrorBoundaryFallback({ error }: { error: Error | null }) {