Browse Source

feat: 项目里跳转到首页调整

dev-zw-home
zhaowei 6 months ago
parent
commit
75b59f6ffe
10 changed files with 35 additions and 15 deletions
  1. +10
    -7
      react-ui/src/app.tsx
  2. +2
    -1
      react-ui/src/components/ErrorBoundary/index.tsx
  3. +1
    -1
      react-ui/src/components/RightContent/AvatarDropdown.tsx
  4. +2
    -1
      react-ui/src/pages/404.tsx
  5. +1
    -1
      react-ui/src/pages/Home/components/Intro/index.tsx
  6. +1
    -1
      react-ui/src/pages/Home/components/Service/index.tsx
  7. +2
    -1
      react-ui/src/pages/User/Login/login.tsx
  8. +2
    -1
      react-ui/src/pages/missingPage.jsx
  9. +3
    -0
      react-ui/src/utils/constant.ts
  10. +11
    -1
      react-ui/src/utils/index.ts

+ 10
- 7
react-ui/src/app.tsx View File

@@ -20,7 +20,8 @@ import {
setRemoteMenu, setRemoteMenu,
} from './services/session'; } from './services/session';
import './styles/menu.less'; import './styles/menu.less';
import { needAuth } from './utils';
import { isLoginPage, needAuth } from './utils';
import { HomeUrl } from './utils/constant';
import { closeAllModals } from './utils/modal'; import { closeAllModals } from './utils/modal';
import { gotoLoginPage } from './utils/ui'; import { gotoLoginPage } from './utils/ui';
export { requestConfig as request } from './requestConfig'; export { requestConfig as request } from './requestConfig';
@@ -41,7 +42,7 @@ export async function getInitialState(): Promise<GlobalInitialState> {
} as API.CurrentUser; } as API.CurrentUser;
} catch (error) { } catch (error) {
console.error('getInitialState', error); console.error('getInitialState', error);
gotoLoginPage();
gotoLoginPage(true);
} }
return undefined; return undefined;
}; };
@@ -117,27 +118,29 @@ export const layout: RuntimeConfig['layout'] = ({ initialState }) => {
}; };


export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => { export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => {
debugger;
// console.log('onRouteChange'); // console.log('onRouteChange');


// 路由切换时,尤其是回退时,关闭打开的弹框 // 路由切换时,尤其是回退时,关闭打开的弹框
closeAllModals(); closeAllModals();


const { location } = e; const { location } = e;
const pathname = location.pathname;
const token = getAccessToken(); const token = getAccessToken();
// 没有 token,跳转到登录页面 // 没有 token,跳转到登录页面
if (!token && needAuth(location.pathname)) {
gotoLoginPage();
if (!token && needAuth(pathname)) {
gotoLoginPage(false);
return; return;
} }


// 有 token, 登录页面直接跳转到首页 // 有 token, 登录页面直接跳转到首页
if (token && !needAuth(location.pathname)) {
history.push('/');
if (token && isLoginPage(pathname)) {
history.push(HomeUrl);
} }


const menus = getRemoteMenu(); const menus = getRemoteMenu();
// 没有菜单,刷新页面 // 没有菜单,刷新页面
if (menus === null && needAuth(location.pathname)) {
if (menus === null && needAuth(pathname)) {
history.go(0); history.go(0);
} }
}; };


+ 2
- 1
react-ui/src/components/ErrorBoundary/index.tsx View File

@@ -1,4 +1,5 @@
import KFEmpty, { EmptyType } from '@/components/KFEmpty'; import KFEmpty, { EmptyType } from '@/components/KFEmpty';
import { HomeUrl } from '@/utils/constant';
import { Button } from 'antd'; import { Button } from 'antd';
import { Component, ReactNode } from 'react'; import { Component, ReactNode } from 'react';


@@ -55,7 +56,7 @@ function ErrorBoundaryFallback({ error }: { error: Error | null }) {
<Button <Button
type="default" type="default"
onClick={() => { onClick={() => {
window.history.pushState({}, '', '/');
window.history.pushState({}, '', HomeUrl);
window.location.reload(); window.location.reload();
}} }}
> >


+ 1
- 1
react-ui/src/components/RightContent/AvatarDropdown.tsx View File

@@ -87,7 +87,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
const { logoutUri } = clientInfo; const { logoutUri } = clientInfo;
location.replace(logoutUri); location.replace(logoutUri);
} else { } else {
gotoLoginPage();
gotoLoginPage(true);
} }
}; };
const actionClassName = useEmotionCss(({ token }) => { const actionClassName = useEmotionCss(({ token }) => {


+ 2
- 1
react-ui/src/pages/404.tsx View File

@@ -1,4 +1,5 @@
import KFEmpty, { EmptyType } from '@/components/KFEmpty'; import KFEmpty, { EmptyType } from '@/components/KFEmpty';
import { HomeUrl } from '@/utils/constant';
import { useNavigate } from '@umijs/max'; import { useNavigate } from '@umijs/max';


const NoFoundPage = () => { const NoFoundPage = () => {
@@ -12,7 +13,7 @@ const NoFoundPage = () => {
content={'很抱歉,您访问的页面地址有误,\n或者该页面不存在。'} content={'很抱歉,您访问的页面地址有误,\n或者该页面不存在。'}
hasFooter={true} hasFooter={true}
buttonTitle="返回首页" buttonTitle="返回首页"
onButtonClick={() => navigate('/')}
onButtonClick={() => navigate(HomeUrl)}
></KFEmpty> ></KFEmpty>
); );
}; };


+ 1
- 1
react-ui/src/pages/Home/components/Intro/index.tsx View File

@@ -14,7 +14,7 @@ function IntroBlock() {
以支持材料工程师、科学家和研究人员在材料设计、性能评估和工艺优化方面的工作。 以支持材料工程师、科学家和研究人员在材料设计、性能评估和工艺优化方面的工作。
</div> </div>
<div className={styles['intro__button']} onClick={() => navigate('/workspace')}> <div className={styles['intro__button']} onClick={() => navigate('/workspace')}>
进入首页
开始使用
</div> </div>
<StatisticsBlock></StatisticsBlock> <StatisticsBlock></StatisticsBlock>
</div> </div>


+ 1
- 1
react-ui/src/pages/Home/components/Service/index.tsx View File

@@ -46,7 +46,7 @@ function ServiceBlock() {
<BlockTitle <BlockTitle
title="热门APP" title="热门APP"
style={{ marginBottom: '5rem' }} style={{ marginBottom: '5rem' }}
onClick={() => navigate('dataset/modelDeployment')}
onClick={() => navigate('/dataset/modelDeployment')}
></BlockTitle> ></BlockTitle>
<Flex align="center" justify="space-between" style={{ width: '100%' }}> <Flex align="center" justify="space-between" style={{ width: '100%' }}>
{serviceData.map((item) => { {serviceData.map((item) => {


+ 2
- 1
react-ui/src/pages/User/Login/login.tsx View File

@@ -1,6 +1,7 @@
import { clearSessionToken, setSessionToken } from '@/access'; import { clearSessionToken, setSessionToken } from '@/access';
import { getCaptchaImg, login } from '@/services/system/auth'; import { getCaptchaImg, login } from '@/services/system/auth';
import { parseJsonText } from '@/utils'; import { parseJsonText } from '@/utils';
import { HomeUrl } from '@/utils/constant';
import { safeInvoke } from '@/utils/functional'; import { safeInvoke } from '@/utils/functional';
import LocalStorage from '@/utils/localStorage'; import LocalStorage from '@/utils/localStorage';
import { to } from '@/utils/promise'; import { to } from '@/utils/promise';
@@ -97,7 +98,7 @@ const Login = () => {


await fetchUserInfo(); await fetchUserInfo();
const urlParams = new URL(window.location.href).searchParams; const urlParams = new URL(window.location.href).searchParams;
history.replace(urlParams.get('redirect') || '/');
history.replace(urlParams.get('redirect') || HomeUrl);
} else { } else {
if (error?.data?.code === 500 && error?.data?.msg === '验证码错误') { if (error?.data?.code === 500 && error?.data?.msg === '验证码错误') {
captchaInputRef.current?.focus({ captchaInputRef.current?.focus({


+ 2
- 1
react-ui/src/pages/missingPage.jsx View File

@@ -1,5 +1,6 @@
import KFEmpty, { EmptyType } from '@/components/KFEmpty'; import KFEmpty, { EmptyType } from '@/components/KFEmpty';
import { useNavigate } from '@umijs/max'; import { useNavigate } from '@umijs/max';
import { HomeUrl } from '@/utils/constant';


const MissingPage = () => { const MissingPage = () => {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -12,7 +13,7 @@ const MissingPage = () => {
content={'很抱歉,您访问的正在开发中,\n请耐心等待。'} content={'很抱歉,您访问的正在开发中,\n请耐心等待。'}
hasFooter={true} hasFooter={true}
buttonTitle="返回首页" buttonTitle="返回首页"
onButtonClick={() => navigate('/')}
onButtonClick={() => navigate(HomeUrl)}
></KFEmpty> ></KFEmpty>
); );
}; };


+ 3
- 0
react-ui/src/utils/constant.ts View File

@@ -20,3 +20,6 @@ export const ServiceCreatedMessage = 'serviceCreated';


// 实验完成 // 实验完成
export const ExperimentCompleted = 'ExperimentCompleted'; export const ExperimentCompleted = 'ExperimentCompleted';

// 首页地址
export const HomeUrl = '/workspace';

+ 11
- 1
react-ui/src/utils/index.ts View File

@@ -298,7 +298,17 @@ export const getGitUrl = (url?: string, branch?: string): string => {
* @return {boolean} true if the pathname needs to be authorized, false otherwise * @return {boolean} true if the pathname needs to be authorized, false otherwise
*/ */
export const needAuth = (pathname: string): boolean => { export const needAuth = (pathname: string): boolean => {
return !whiteList.includes(pathname);
return !whiteList.includes(pathname as PageEnum);
};

/**
* 是否是登录页
*
* @param {string} pathname - the pathname to be checked
* @return {boolean} true if the pathname needs to be authorized, false otherwise
*/
export const isLoginPage = (pathname: string): boolean => {
return pathname === PageEnum.LOGIN || pathname === PageEnum.Authorize;
}; };


/** /**


Loading…
Cancel
Save