Refactor(Navigate): Optimize navigate

Unified management navigation
This commit is contained in:
2024-04-26 11:25:42 +08:00
parent 296a45df00
commit 64c510cd42
16 changed files with 220 additions and 82 deletions

View File

@@ -8,6 +8,7 @@ import {
PERMISSION_USER_NOT_FOUND,
SYSTEM_INVALID_CAPTCHA_CODE
} from '@/constants/common.constants'
import { navigateToLogin } from '@/util/navigation'
import { r_auth_forget, r_auth_retrieve } from '@/services/auth'
import FitCenter from '@/components/common/FitCenter'
import FlexBox from '@/components/common/FlexBox'
@@ -272,7 +273,15 @@ const Forget = () => {
<div className={'footer'}>
<a onClick={() => navigate(`/login`, { replace: true })}></a>
<a
onClick={() =>
navigateToLogin(navigate, undefined, undefined, {
replace: true
})
}
>
</a>
</div>
</div>
</FlexBox>

View File

@@ -12,6 +12,12 @@ import {
} from '@/constants/common.constants'
import { getUserInfo, setToken } from '@/util/auth'
import { utcToLocalTime } from '@/util/datetime'
import {
navigateToForget,
navigateToRedirect,
navigateToRegister,
navigateToRoot
} from '@/util/navigation'
import { r_auth_login } from '@/services/auth'
import { AppContext } from '@/App'
import FitCenter from '@/components/common/FitCenter'
@@ -78,7 +84,7 @@ const SignIn = () => {
setTimeout(() => {
void getUserInfo().then((user) => {
refreshRouter()
navigate(searchParams.get('redirect') ?? '/repository')
navigateToRedirect(navigate, searchParams, '/repository')
notification.success({
message: '欢迎回来',
@@ -255,14 +261,14 @@ const SignIn = () => {
<FlexBox direction={'horizontal'} className={'addition'}>
<a
onClick={() => {
navigate('/')
navigateToRoot(navigate)
}}
>
</a>
<a
onClick={() => {
navigate(`/forget${location.search}`, { replace: true })
navigateToForget(navigate, location.search, { replace: true })
}}
>
@@ -283,7 +289,7 @@ const SignIn = () => {
<a
onClick={() =>
navigate(`/register${location.search}`, { replace: true })
navigateToRegister(navigate, location.search, { replace: true })
}
>

View File

@@ -8,6 +8,7 @@ import {
SYSTEM_MATCH_SENSITIVE_WORD
} from '@/constants/common.constants'
import { getLoginStatus, setToken } from '@/util/auth'
import { navigateToLogin } from '@/util/navigation'
import { r_auth_register, r_auth_resend } from '@/services/auth'
import FitCenter from '@/components/common/FitCenter'
import FlexBox from '@/components/common/FlexBox'
@@ -49,9 +50,7 @@ const SignUp = () => {
return
}
if (getLoginStatus()) {
navigate(`/login${location.search}`, {
replace: true
})
navigateToLogin(navigate, location.search, undefined, { replace: true })
}
}, [location.pathname])
@@ -245,7 +244,9 @@ const SignUp = () => {
<a
onClick={() =>
navigate(`/login${location.search}`, { replace: true })
navigateToLogin(navigate, location.search, undefined, {
replace: true
})
}
>

View File

@@ -7,7 +7,7 @@ import {
SYSTEM_MATCH_SENSITIVE_WORD
} from '@/constants/common.constants'
import { getLoginStatus, getUserInfo, requestUserInfo } from '@/util/auth'
import { getRedirectUrl } from '@/util/route'
import { navigateToLogin, navigateToRedirect, navigateToRepository } from '@/util/navigation'
import { r_auth_resend, r_auth_verify } from '@/services/auth'
import { r_api_avatar_random_base64 } from '@/services/api/avatar'
import { AppContext } from '@/App'
@@ -32,7 +32,7 @@ const Verify = () => {
}
if (!getLoginStatus()) {
navigate(getRedirectUrl('/login', `${location.pathname}${location.search}`), {
navigateToLogin(navigate, undefined, `${location.pathname}${location.search}`, {
replace: true
})
return
@@ -81,7 +81,7 @@ const Verify = () => {
break
case PERMISSION_NO_VERIFICATION_REQUIRED:
void message.warning('账户已验证')
navigate('/repository')
navigateToRepository(navigate)
break
default:
void message.error('出错了,请稍后重试')
@@ -128,7 +128,7 @@ const Verify = () => {
setTimeout(() => {
void requestUserInfo().then(() => {
refreshRouter()
navigate(searchParams.get('redirect') ?? '/repository')
navigateToRedirect(navigate, searchParams, '/repository')
})
}, 1500)
break