Refactor(Navigate): Optimize navigate
Unified management navigation
This commit is contained in:
@@ -2,6 +2,7 @@ import Icon from '@ant-design/icons'
|
|||||||
import { COLOR_ERROR } from '@/constants/common.constants'
|
import { COLOR_ERROR } from '@/constants/common.constants'
|
||||||
import { getRedirectUrl } from '@/util/route'
|
import { getRedirectUrl } from '@/util/route'
|
||||||
import { getAvatar, getLoginStatus, getNickname, removeToken } from '@/util/auth'
|
import { getAvatar, getLoginStatus, getNickname, removeToken } from '@/util/auth'
|
||||||
|
import { navigateToLogin, navigateToUser } from '@/util/navigation'
|
||||||
import { r_auth_logout } from '@/services/auth'
|
import { r_auth_logout } from '@/services/auth'
|
||||||
|
|
||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
@@ -15,9 +16,9 @@ const Footer = () => {
|
|||||||
|
|
||||||
const handleClickAvatar = () => {
|
const handleClickAvatar = () => {
|
||||||
if (getLoginStatus()) {
|
if (getLoginStatus()) {
|
||||||
navigate('/user')
|
navigateToUser(navigate)
|
||||||
} else {
|
} else {
|
||||||
navigate(getRedirectUrl('/login', `${lastMatch.pathname}${location.search}`))
|
navigateToLogin(navigate, undefined, `${lastMatch.pathname}${location.search}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
PERMISSION_USER_NOT_FOUND,
|
PERMISSION_USER_NOT_FOUND,
|
||||||
SYSTEM_INVALID_CAPTCHA_CODE
|
SYSTEM_INVALID_CAPTCHA_CODE
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
|
import { navigateToLogin } from '@/util/navigation'
|
||||||
import { r_auth_forget, r_auth_retrieve } from '@/services/auth'
|
import { r_auth_forget, r_auth_retrieve } from '@/services/auth'
|
||||||
import FitCenter from '@/components/common/FitCenter'
|
import FitCenter from '@/components/common/FitCenter'
|
||||||
import FlexBox from '@/components/common/FlexBox'
|
import FlexBox from '@/components/common/FlexBox'
|
||||||
@@ -272,7 +273,15 @@ const Forget = () => {
|
|||||||
|
|
||||||
<div className={'footer'}>
|
<div className={'footer'}>
|
||||||
找到了?
|
找到了?
|
||||||
<a onClick={() => navigate(`/login`, { replace: true })}>登录</a>
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
navigateToLogin(navigate, undefined, undefined, {
|
||||||
|
replace: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
登录
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ import {
|
|||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { getUserInfo, setToken } from '@/util/auth'
|
import { getUserInfo, setToken } from '@/util/auth'
|
||||||
import { utcToLocalTime } from '@/util/datetime'
|
import { utcToLocalTime } from '@/util/datetime'
|
||||||
|
import {
|
||||||
|
navigateToForget,
|
||||||
|
navigateToRedirect,
|
||||||
|
navigateToRegister,
|
||||||
|
navigateToRoot
|
||||||
|
} from '@/util/navigation'
|
||||||
import { r_auth_login } from '@/services/auth'
|
import { r_auth_login } from '@/services/auth'
|
||||||
import { AppContext } from '@/App'
|
import { AppContext } from '@/App'
|
||||||
import FitCenter from '@/components/common/FitCenter'
|
import FitCenter from '@/components/common/FitCenter'
|
||||||
@@ -78,7 +84,7 @@ const SignIn = () => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
void getUserInfo().then((user) => {
|
void getUserInfo().then((user) => {
|
||||||
refreshRouter()
|
refreshRouter()
|
||||||
navigate(searchParams.get('redirect') ?? '/repository')
|
navigateToRedirect(navigate, searchParams, '/repository')
|
||||||
|
|
||||||
notification.success({
|
notification.success({
|
||||||
message: '欢迎回来',
|
message: '欢迎回来',
|
||||||
@@ -255,14 +261,14 @@ const SignIn = () => {
|
|||||||
<FlexBox direction={'horizontal'} className={'addition'}>
|
<FlexBox direction={'horizontal'} className={'addition'}>
|
||||||
<a
|
<a
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate('/')
|
navigateToRoot(navigate)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
返回主页
|
返回主页
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(`/forget${location.search}`, { replace: true })
|
navigateToForget(navigate, location.search, { replace: true })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
忘记密码?
|
忘记密码?
|
||||||
@@ -283,7 +289,7 @@ const SignIn = () => {
|
|||||||
还没有账号?
|
还没有账号?
|
||||||
<a
|
<a
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/register${location.search}`, { replace: true })
|
navigateToRegister(navigate, location.search, { replace: true })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
注册
|
注册
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
SYSTEM_MATCH_SENSITIVE_WORD
|
SYSTEM_MATCH_SENSITIVE_WORD
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { getLoginStatus, setToken } from '@/util/auth'
|
import { getLoginStatus, setToken } from '@/util/auth'
|
||||||
|
import { navigateToLogin } from '@/util/navigation'
|
||||||
import { r_auth_register, r_auth_resend } from '@/services/auth'
|
import { r_auth_register, r_auth_resend } from '@/services/auth'
|
||||||
import FitCenter from '@/components/common/FitCenter'
|
import FitCenter from '@/components/common/FitCenter'
|
||||||
import FlexBox from '@/components/common/FlexBox'
|
import FlexBox from '@/components/common/FlexBox'
|
||||||
@@ -49,9 +50,7 @@ const SignUp = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (getLoginStatus()) {
|
if (getLoginStatus()) {
|
||||||
navigate(`/login${location.search}`, {
|
navigateToLogin(navigate, location.search, undefined, { replace: true })
|
||||||
replace: true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, [location.pathname])
|
}, [location.pathname])
|
||||||
|
|
||||||
@@ -245,7 +244,9 @@ const SignUp = () => {
|
|||||||
已有账号?
|
已有账号?
|
||||||
<a
|
<a
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/login${location.search}`, { replace: true })
|
navigateToLogin(navigate, location.search, undefined, {
|
||||||
|
replace: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
登录
|
登录
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
SYSTEM_MATCH_SENSITIVE_WORD
|
SYSTEM_MATCH_SENSITIVE_WORD
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { getLoginStatus, getUserInfo, requestUserInfo } from '@/util/auth'
|
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_auth_resend, r_auth_verify } from '@/services/auth'
|
||||||
import { r_api_avatar_random_base64 } from '@/services/api/avatar'
|
import { r_api_avatar_random_base64 } from '@/services/api/avatar'
|
||||||
import { AppContext } from '@/App'
|
import { AppContext } from '@/App'
|
||||||
@@ -32,7 +32,7 @@ const Verify = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!getLoginStatus()) {
|
if (!getLoginStatus()) {
|
||||||
navigate(getRedirectUrl('/login', `${location.pathname}${location.search}`), {
|
navigateToLogin(navigate, undefined, `${location.pathname}${location.search}`, {
|
||||||
replace: true
|
replace: true
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -81,7 +81,7 @@ const Verify = () => {
|
|||||||
break
|
break
|
||||||
case PERMISSION_NO_VERIFICATION_REQUIRED:
|
case PERMISSION_NO_VERIFICATION_REQUIRED:
|
||||||
void message.warning('账户已验证')
|
void message.warning('账户已验证')
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
void message.error('出错了,请稍后重试')
|
void message.error('出错了,请稍后重试')
|
||||||
@@ -128,7 +128,7 @@ const Verify = () => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
void requestUserInfo().then(() => {
|
void requestUserInfo().then(() => {
|
||||||
refreshRouter()
|
refreshRouter()
|
||||||
navigate(searchParams.get('redirect') ?? '/repository')
|
navigateToRedirect(navigate, searchParams, '/repository')
|
||||||
})
|
})
|
||||||
}, 1500)
|
}, 1500)
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import Icon from '@ant-design/icons'
|
|||||||
import '@/assets/css/pages/system/tools/code.scss'
|
import '@/assets/css/pages/system/tools/code.scss'
|
||||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||||
import { checkDesktop } from '@/util/common'
|
import { checkDesktop } from '@/util/common'
|
||||||
|
import { navigateToExecute, navigateToRepository } from '@/util/navigation'
|
||||||
import { r_sys_tool_get_one } from '@/services/system'
|
import { r_sys_tool_get_one } from '@/services/system'
|
||||||
import { IFiles } from '@/components/Playground/shared'
|
import { IFiles } from '@/components/Playground/shared'
|
||||||
import { base64ToFiles } from '@/components/Playground/files'
|
import { base64ToFiles } from '@/components/Playground/files'
|
||||||
@@ -27,7 +28,7 @@ const Code = () => {
|
|||||||
title: '注意',
|
title: '注意',
|
||||||
content: '运行前请仔细查阅工具代码!',
|
content: '运行前请仔细查阅工具代码!',
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
navigate(`/system/tools/execute/${id}`)
|
navigateToExecute(navigate, id!)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -62,7 +63,7 @@ const Code = () => {
|
|||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.error('未找到指定工具')
|
void message.error('未找到指定工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import '@/assets/css/pages/system/tools/execute.scss'
|
import '@/assets/css/pages/system/tools/execute.scss'
|
||||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||||
|
import { navigateToTools } from '@/util/navigation'
|
||||||
import { r_sys_tool_get_one } from '@/services/system'
|
import { r_sys_tool_get_one } from '@/services/system'
|
||||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
@@ -51,7 +52,7 @@ const Execute = () => {
|
|||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.error('未找到指定工具')
|
void message.error('未找到指定工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/system/tools')
|
navigateToTools(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
DATABASE_UPDATE_SUCCESS,
|
DATABASE_UPDATE_SUCCESS,
|
||||||
TOOL_NOT_UNDER_REVIEW
|
TOOL_NOT_UNDER_REVIEW
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
|
import { navigateToCode } from '@/util/navigation'
|
||||||
import FlexBox from '@/components/common/FlexBox'
|
import FlexBox from '@/components/common/FlexBox'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||||
@@ -198,7 +199,7 @@ const Tools = () => {
|
|||||||
|
|
||||||
const handleOnViewBtnClick = (value: ToolVo) => {
|
const handleOnViewBtnClick = (value: ToolVo) => {
|
||||||
return () => {
|
return () => {
|
||||||
navigate(`/system/tools/code/${value.id}`)
|
navigateToCode(navigate, value.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
DATABASE_INSERT_SUCCESS,
|
DATABASE_INSERT_SUCCESS,
|
||||||
DATABASE_SELECT_SUCCESS
|
DATABASE_SELECT_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
|
import { navigateToEdit } from '@/util/navigation'
|
||||||
import {
|
import {
|
||||||
r_tool_category_get,
|
r_tool_category_get,
|
||||||
r_tool_create,
|
r_tool_create,
|
||||||
@@ -44,9 +45,7 @@ const Create = () => {
|
|||||||
void message.success(
|
void message.success(
|
||||||
`创建工具 ${response.data!.name}<${response.data!.toolId}:${response.data!.platform.slice(0, 1)}${response.data!.platform.slice(1).toLowerCase()}:${response.data!.ver}> 成功`
|
`创建工具 ${response.data!.name}<${response.data!.toolId}:${response.data!.platform.slice(0, 1)}${response.data!.platform.slice(1).toLowerCase()}:${response.data!.ver}> 成功`
|
||||||
)
|
)
|
||||||
navigate(
|
navigateToEdit(navigate, response.data!.toolId, response.data!.platform)
|
||||||
`/edit/${response.data!.toolId}${response.data!.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${response.data!.platform}` : ''}`
|
|
||||||
)
|
|
||||||
break
|
break
|
||||||
case DATABASE_DUPLICATE_KEY:
|
case DATABASE_DUPLICATE_KEY:
|
||||||
void message.warning('已存在相同 ID 的应用')
|
void message.warning('已存在相同 ID 的应用')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
TOOL_HAS_BEEN_PUBLISHED,
|
TOOL_HAS_BEEN_PUBLISHED,
|
||||||
TOOL_UNDER_REVIEW
|
TOOL_UNDER_REVIEW
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
|
import { navigateToRepository } from '@/util/navigation'
|
||||||
import { r_tool_category_get, r_tool_detail, r_tool_update } from '@/services/tool'
|
import { r_tool_category_get, r_tool_detail, r_tool_update } from '@/services/tool'
|
||||||
import { IFiles, IImportMap, ITsconfig } from '@/components/Playground/shared'
|
import { IFiles, IImportMap, ITsconfig } from '@/components/Playground/shared'
|
||||||
import {
|
import {
|
||||||
@@ -118,13 +119,13 @@ const Edit = () => {
|
|||||||
case TOOL_UNDER_REVIEW:
|
case TOOL_UNDER_REVIEW:
|
||||||
void message.error('保存失败:工具审核中')
|
void message.error('保存失败:工具审核中')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
case TOOL_HAS_BEEN_PUBLISHED:
|
case TOOL_HAS_BEEN_PUBLISHED:
|
||||||
void message.error('保存失败:工具已发布')
|
void message.error('保存失败:工具已发布')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -184,13 +185,13 @@ const Edit = () => {
|
|||||||
case TOOL_UNDER_REVIEW:
|
case TOOL_UNDER_REVIEW:
|
||||||
void message.error('保存失败:工具审核中')
|
void message.error('保存失败:工具审核中')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
case TOOL_HAS_BEEN_PUBLISHED:
|
case TOOL_HAS_BEEN_PUBLISHED:
|
||||||
void message.error('保存失败:工具已发布')
|
void message.error('保存失败:工具已发布')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -245,20 +246,20 @@ const Edit = () => {
|
|||||||
case 'PROCESSING':
|
case 'PROCESSING':
|
||||||
void message.warning('工具审核中,请勿修改')
|
void message.warning('工具审核中,请勿修改')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
void message.warning('请先创建新版本后编辑工具')
|
void message.warning('请先创建新版本后编辑工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.error('未找到指定工具')
|
void message.error('未找到指定工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -322,7 +323,7 @@ const Edit = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
getTool()
|
getTool()
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import '@/assets/css/pages/tools/source.scss'
|
import '@/assets/css/pages/tools/source.scss'
|
||||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||||
|
import { getLoginStatus } from '@/util/auth'
|
||||||
|
import { navigateToRepository, navigateToSource } from '@/util/navigation'
|
||||||
import { r_tool_detail } from '@/services/tool'
|
import { r_tool_detail } from '@/services/tool'
|
||||||
import { IFiles } from '@/components/Playground/shared'
|
import { IFiles } from '@/components/Playground/shared'
|
||||||
import { base64ToFiles } from '@/components/Playground/files'
|
import { base64ToFiles } from '@/components/Playground/files'
|
||||||
import Playground from '@/components/Playground'
|
import Playground from '@/components/Playground'
|
||||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
import { getLoginStatus } from '@/util/auth'
|
|
||||||
|
|
||||||
const Source = () => {
|
const Source = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@@ -49,7 +50,7 @@ const Source = () => {
|
|||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.error('未找到指定工具')
|
void message.error('未找到指定工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -63,22 +64,23 @@ const Source = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const platform = searchParams.get('platform')!
|
||||||
|
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(platform)) {
|
||||||
|
navigateToRepository(navigate)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (username === '!' && !getLoginStatus()) {
|
if (username === '!' && !getLoginStatus()) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (username !== '!' && ver) {
|
if (username !== '!' && ver) {
|
||||||
navigate(`/source/${username}/${toolId}`)
|
navigateToSource(navigate, username!, toolId!, platform as Platform)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (username === '!' && !ver) {
|
if (username === '!' && !ver) {
|
||||||
navigate(`/source/!/${toolId}/latest`)
|
navigateToSource(navigate, '!', toolId!, platform as Platform, 'latest')
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
|
||||||
navigate('/repository')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
getTool()
|
getTool()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Icon from '@ant-design/icons'
|
|||||||
import '@/assets/css/pages/tools/store.scss'
|
import '@/assets/css/pages/tools/store.scss'
|
||||||
import { COLOR_BACKGROUND, COLOR_MAIN, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
import { COLOR_BACKGROUND, COLOR_MAIN, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||||
import { checkDesktop } from '@/util/common'
|
import { checkDesktop } from '@/util/common'
|
||||||
|
import { navigateToSource, navigateToStore, navigateToView } from '@/util/navigation'
|
||||||
import { r_tool_store_get } from '@/services/tool'
|
import { r_tool_store_get } from '@/services/tool'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
import FlexBox from '@/components/common/FlexBox'
|
import FlexBox from '@/components/common/FlexBox'
|
||||||
@@ -80,21 +81,17 @@ const CommonCard = ({
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnClickAuthor = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnClickAuthor = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
navigate(authorUsername)
|
navigateToStore(navigate, authorUsername)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
navigate(
|
navigateToSource(navigate, authorUsername, toolId, platform)
|
||||||
`/source/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
@@ -137,16 +134,12 @@ const CommonCard = ({
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
DATABASE_SELECT_SUCCESS
|
DATABASE_SELECT_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { checkDesktop } from '@/util/common'
|
import { checkDesktop } from '@/util/common'
|
||||||
|
import { navigateToRoot, navigateToSource, navigateToView } from '@/util/navigation'
|
||||||
import { r_sys_user_info_get_basic } from '@/services/system'
|
import { r_sys_user_info_get_basic } from '@/services/system'
|
||||||
import { r_tool_store_get_by_username } from '@/services/tool'
|
import { r_tool_store_get_by_username } from '@/services/tool'
|
||||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||||
@@ -82,16 +83,12 @@ const CommonCard = ({
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
navigate(
|
navigateToSource(navigate, authorUsername, toolId, platform)
|
||||||
`/source/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
@@ -134,16 +131,12 @@ const CommonCard = ({
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
navigate(
|
navigateToView(navigate, authorUsername, toolId, platform)
|
||||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -269,7 +262,7 @@ const User = () => {
|
|||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.warning('用户不存在')
|
void message.warning('用户不存在')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/')
|
navigateToRoot(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import '@/assets/css/pages/tools/view.scss'
|
import '@/assets/css/pages/tools/view.scss'
|
||||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||||
import { getLoginStatus } from '@/util/auth'
|
import { getLoginStatus } from '@/util/auth'
|
||||||
|
import { navigateToRepository, navigateToRoot, navigateToView } from '@/util/navigation'
|
||||||
import { r_tool_detail } from '@/services/tool'
|
import { r_tool_detail } from '@/services/tool'
|
||||||
import compiler from '@/components/Playground/compiler'
|
import compiler from '@/components/Playground/compiler'
|
||||||
import { IImportMap } from '@/components/Playground/shared'
|
import { IImportMap } from '@/components/Playground/shared'
|
||||||
@@ -72,7 +73,7 @@ const View = () => {
|
|||||||
case DATABASE_NO_RECORD_FOUND:
|
case DATABASE_NO_RECORD_FOUND:
|
||||||
void message.error('未找到指定工具')
|
void message.error('未找到指定工具')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/repository')
|
navigateToRepository(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -86,22 +87,23 @@ const View = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const platform = searchParams.get('platform')!
|
||||||
|
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(platform)) {
|
||||||
|
navigateToRepository(navigate)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (username === '!' && !getLoginStatus()) {
|
if (username === '!' && !getLoginStatus()) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/')
|
navigateToRoot(navigate)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (username !== '!' && ver) {
|
if (username !== '!' && ver) {
|
||||||
navigate(`/view/${username}/${toolId}`)
|
navigateToView(navigate, username!, toolId!, platform as Platform)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (username === '!' && !ver) {
|
if (username === '!' && !ver) {
|
||||||
navigate(`/view/!/${toolId}/latest`)
|
navigateToView(navigate, '!', toolId!, platform as Platform)
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
|
||||||
navigate('/repository')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
getTool()
|
getTool()
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { checkDesktop } from '@/util/common'
|
import { checkDesktop } from '@/util/common'
|
||||||
import { getLoginStatus } from '@/util/auth'
|
import { getLoginStatus } from '@/util/auth'
|
||||||
|
import { navigateToEdit, navigateToSource, navigateToView } from '@/util/navigation'
|
||||||
import {
|
import {
|
||||||
r_tool_cancel,
|
r_tool_cancel,
|
||||||
r_tool_delete,
|
r_tool_delete,
|
||||||
@@ -145,8 +146,12 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
|||||||
|
|
||||||
const handleOnOpenTool = () => {
|
const handleOnOpenTool = () => {
|
||||||
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
||||||
navigate(
|
navigateToView(
|
||||||
`/view/!/${selectedTool.toolId}/${selectedTool.ver}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
navigate,
|
||||||
|
'!',
|
||||||
|
selectedTool.toolId,
|
||||||
|
selectedTool.platform,
|
||||||
|
selectedTool.ver
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
void message.warning('此应用需要桌面端环境,请在桌面端打开')
|
void message.warning('此应用需要桌面端环境,请在桌面端打开')
|
||||||
@@ -157,9 +162,7 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
|||||||
if (['NONE', 'REJECT'].includes(selectedTool.review)) {
|
if (['NONE', 'REJECT'].includes(selectedTool.review)) {
|
||||||
return () => {
|
return () => {
|
||||||
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
||||||
navigate(
|
navigateToEdit(navigate, selectedTool.toolId, selectedTool.platform)
|
||||||
`/edit/${selectedTool.toolId}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
void message.warning('此应用需要桌面端环境,请在桌面端编辑')
|
void message.warning('此应用需要桌面端环境,请在桌面端编辑')
|
||||||
}
|
}
|
||||||
@@ -171,8 +174,12 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
|||||||
const handleOnSourceTool = () => {
|
const handleOnSourceTool = () => {
|
||||||
if (selectedTool.review === 'PASS') {
|
if (selectedTool.review === 'PASS') {
|
||||||
return () => {
|
return () => {
|
||||||
navigate(
|
navigateToSource(
|
||||||
`/source/!/${selectedTool.toolId}/${selectedTool.ver}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
navigate,
|
||||||
|
'!',
|
||||||
|
selectedTool.toolId,
|
||||||
|
selectedTool.platform,
|
||||||
|
selectedTool.ver
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,8 +413,10 @@ const Tools = () => {
|
|||||||
checkDesktop() ||
|
checkDesktop() ||
|
||||||
response.data!.platform !== 'DESKTOP'
|
response.data!.platform !== 'DESKTOP'
|
||||||
) {
|
) {
|
||||||
navigate(
|
navigateToEdit(
|
||||||
`/edit/${response.data!.toolId}${response.data!.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${response.data!.platform}` : ''}`
|
navigate,
|
||||||
|
response.data!.toolId,
|
||||||
|
response.data!.platform
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
|||||||
127
src/renderer/src/util/navigation.tsx
Normal file
127
src/renderer/src/util/navigation.tsx
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
import { NavigateFunction, NavigateOptions } from 'react-router'
|
||||||
|
import { getRedirectUrl } from '@/util/route'
|
||||||
|
|
||||||
|
export const navigateToRoot = (navigate: NavigateFunction, options?: NavigateOptions) => {
|
||||||
|
navigate('/', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToStore = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
username?: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(`/store${username ? `/${username}` : ''}`, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToRepository = (navigate: NavigateFunction, options?: NavigateOptions) => {
|
||||||
|
navigate('/repository', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToLogin = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
locationSearch?: string,
|
||||||
|
redirectUrl?: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(
|
||||||
|
redirectUrl ? getRedirectUrl('/login', redirectUrl) : `/login${locationSearch}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToView = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
username: string,
|
||||||
|
toolId: string,
|
||||||
|
platform: Platform,
|
||||||
|
version?: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(
|
||||||
|
`/view/${username}/${toolId}${version ? `/${version}` : ''}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToSource = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
username: string,
|
||||||
|
toolId: string,
|
||||||
|
platform: Platform,
|
||||||
|
version?: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(
|
||||||
|
`/source/${username}/${toolId}${version ? `/${version}` : ''}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToRedirect = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
searchParams: URLSearchParams,
|
||||||
|
defaultUrl: '/repository' | '/',
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(searchParams.get('redirect') ?? defaultUrl, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToForget = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
locationSearch: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(`/forget/${locationSearch}`, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToRegister = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
locationSearch: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(`/register/${locationSearch}`, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToExecute = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
toolId: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(`/system/tools/execute/${toolId}`, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToCode = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
toolId: string,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(`/system/tools/code/${toolId}`, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToEdit = (
|
||||||
|
navigate: NavigateFunction,
|
||||||
|
toolId: string,
|
||||||
|
platform: Platform,
|
||||||
|
options?: NavigateOptions
|
||||||
|
) => {
|
||||||
|
navigate(
|
||||||
|
`/edit/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToUser = (navigate: NavigateFunction, options?: NavigateOptions) => {
|
||||||
|
navigate('/user', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const navigateToTools = (navigate: NavigateFunction, options?: NavigateOptions) => {
|
||||||
|
navigate('/system/tools', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getViewPath = (
|
||||||
|
username: string,
|
||||||
|
toolId: string,
|
||||||
|
platform: Platform,
|
||||||
|
version?: string
|
||||||
|
) =>
|
||||||
|
`/view/${username}/${toolId}${version ? `/${version}` : ''}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||||
Reference in New Issue
Block a user