Refactor:11; Fix:6; Chore:1; Feat:7; Build:1 #49
@@ -2,6 +2,7 @@ import Icon from '@ant-design/icons'
|
||||
import { COLOR_ERROR } from '@/constants/common.constants'
|
||||
import { getRedirectUrl } from '@/util/route'
|
||||
import { getAvatar, getLoginStatus, getNickname, removeToken } from '@/util/auth'
|
||||
import { navigateToLogin, navigateToUser } from '@/util/navigation'
|
||||
import { r_auth_logout } from '@/services/auth'
|
||||
|
||||
const Footer = () => {
|
||||
@@ -15,9 +16,9 @@ const Footer = () => {
|
||||
|
||||
const handleClickAvatar = () => {
|
||||
if (getLoginStatus()) {
|
||||
navigate('/user')
|
||||
navigateToUser(navigate)
|
||||
} else {
|
||||
navigate(getRedirectUrl('/login', `${lastMatch.pathname}${location.search}`))
|
||||
navigateToLogin(navigate, undefined, `${lastMatch.pathname}${location.search}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
>
|
||||
注册
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
>
|
||||
登录
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,6 +3,7 @@ import Icon from '@ant-design/icons'
|
||||
import '@/assets/css/pages/system/tools/code.scss'
|
||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||
import { checkDesktop } from '@/util/common'
|
||||
import { navigateToExecute, navigateToRepository } from '@/util/navigation'
|
||||
import { r_sys_tool_get_one } from '@/services/system'
|
||||
import { IFiles } from '@/components/Playground/shared'
|
||||
import { base64ToFiles } from '@/components/Playground/files'
|
||||
@@ -27,7 +28,7 @@ const Code = () => {
|
||||
title: '注意',
|
||||
content: '运行前请仔细查阅工具代码!',
|
||||
onOk: () => {
|
||||
navigate(`/system/tools/execute/${id}`)
|
||||
navigateToExecute(navigate, id!)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -62,7 +63,7 @@ const Code = () => {
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.error('未找到指定工具')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import '@/assets/css/pages/system/tools/execute.scss'
|
||||
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 FitFullscreen from '@/components/common/FitFullscreen'
|
||||
import Card from '@/components/common/Card'
|
||||
@@ -51,7 +52,7 @@ const Execute = () => {
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.error('未找到指定工具')
|
||||
setTimeout(() => {
|
||||
navigate('/system/tools')
|
||||
navigateToTools(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
DATABASE_UPDATE_SUCCESS,
|
||||
TOOL_NOT_UNDER_REVIEW
|
||||
} from '@/constants/common.constants'
|
||||
import { navigateToCode } from '@/util/navigation'
|
||||
import FlexBox from '@/components/common/FlexBox'
|
||||
import Card from '@/components/common/Card'
|
||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||
@@ -196,7 +197,7 @@ const Tools = () => {
|
||||
|
||||
const handleOnViewBtnClick = (value: ToolVo) => {
|
||||
return () => {
|
||||
navigate(`/system/tools/code/${value.id}`)
|
||||
navigateToCode(navigate, value.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
DATABASE_INSERT_SUCCESS,
|
||||
DATABASE_SELECT_SUCCESS
|
||||
} from '@/constants/common.constants'
|
||||
import { navigateToEdit } from '@/util/navigation'
|
||||
import {
|
||||
r_tool_category_get,
|
||||
r_tool_create,
|
||||
@@ -44,9 +45,7 @@ const Create = () => {
|
||||
void message.success(
|
||||
`创建工具 ${response.data!.name}<${response.data!.toolId}:${response.data!.platform.slice(0, 1)}${response.data!.platform.slice(1).toLowerCase()}:${response.data!.ver}> 成功`
|
||||
)
|
||||
navigate(
|
||||
`/edit/${response.data!.toolId}${response.data!.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${response.data!.platform}` : ''}`
|
||||
)
|
||||
navigateToEdit(navigate, response.data!.toolId, response.data!.platform)
|
||||
break
|
||||
case DATABASE_DUPLICATE_KEY:
|
||||
void message.warning('已存在相同 ID 的应用')
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
TOOL_HAS_BEEN_PUBLISHED,
|
||||
TOOL_UNDER_REVIEW
|
||||
} from '@/constants/common.constants'
|
||||
import { navigateToRepository } from '@/util/navigation'
|
||||
import { r_tool_category_get, r_tool_detail, r_tool_update } from '@/services/tool'
|
||||
import { IFiles, IImportMap, ITsconfig } from '@/components/Playground/shared'
|
||||
import {
|
||||
@@ -118,13 +119,13 @@ const Edit = () => {
|
||||
case TOOL_UNDER_REVIEW:
|
||||
void message.error('保存失败:工具审核中')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
case TOOL_HAS_BEEN_PUBLISHED:
|
||||
void message.error('保存失败:工具已发布')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
@@ -184,13 +185,13 @@ const Edit = () => {
|
||||
case TOOL_UNDER_REVIEW:
|
||||
void message.error('保存失败:工具审核中')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
case TOOL_HAS_BEEN_PUBLISHED:
|
||||
void message.error('保存失败:工具已发布')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
@@ -245,20 +246,20 @@ const Edit = () => {
|
||||
case 'PROCESSING':
|
||||
void message.warning('工具审核中,请勿修改')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
void message.warning('请先创建新版本后编辑工具')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
}
|
||||
break
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.error('未找到指定工具')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
@@ -322,7 +323,7 @@ const Edit = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
return
|
||||
}
|
||||
getTool()
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import '@/assets/css/pages/tools/source.scss'
|
||||
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 { IFiles } from '@/components/Playground/shared'
|
||||
import { base64ToFiles } from '@/components/Playground/files'
|
||||
import Playground from '@/components/Playground'
|
||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||
import Card from '@/components/common/Card'
|
||||
import { getLoginStatus } from '@/util/auth'
|
||||
|
||||
const Source = () => {
|
||||
const navigate = useNavigate()
|
||||
@@ -49,7 +50,7 @@ const Source = () => {
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.error('未找到指定工具')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
@@ -63,22 +64,23 @@ const Source = () => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const platform = searchParams.get('platform')!
|
||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(platform)) {
|
||||
navigateToRepository(navigate)
|
||||
return
|
||||
}
|
||||
if (username === '!' && !getLoginStatus()) {
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
return
|
||||
}
|
||||
if (username !== '!' && ver) {
|
||||
navigate(`/source/${username}/${toolId}`)
|
||||
navigateToSource(navigate, username!, toolId!, platform as Platform)
|
||||
return
|
||||
}
|
||||
if (username === '!' && !ver) {
|
||||
navigate(`/source/!/${toolId}/latest`)
|
||||
return
|
||||
}
|
||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
||||
navigate('/repository')
|
||||
navigateToSource(navigate, '!', toolId!, platform as Platform, 'latest')
|
||||
return
|
||||
}
|
||||
getTool()
|
||||
|
||||
@@ -5,6 +5,7 @@ import Icon from '@ant-design/icons'
|
||||
import '@/assets/css/pages/tools/store.scss'
|
||||
import { COLOR_BACKGROUND, COLOR_MAIN, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||
import { checkDesktop } from '@/util/common'
|
||||
import { navigateToSource, navigateToStore, navigateToView } from '@/util/navigation'
|
||||
import { r_tool_store_get } from '@/services/tool'
|
||||
import Card from '@/components/common/Card'
|
||||
import FlexBox from '@/components/common/FlexBox'
|
||||
@@ -80,21 +81,17 @@ const CommonCard = ({
|
||||
})
|
||||
return
|
||||
}
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnClickAuthor = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
navigate(authorUsername)
|
||||
navigateToStore(navigate, authorUsername)
|
||||
}
|
||||
|
||||
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
navigate(
|
||||
`/source/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToSource(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
@@ -137,16 +134,12 @@ const CommonCard = ({
|
||||
)
|
||||
return
|
||||
}
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
DATABASE_SELECT_SUCCESS
|
||||
} from '@/constants/common.constants'
|
||||
import { checkDesktop } from '@/util/common'
|
||||
import { navigateToRoot, navigateToSource, navigateToView } from '@/util/navigation'
|
||||
import { r_sys_user_info_get_basic } from '@/services/system'
|
||||
import { r_tool_store_get_by_username } from '@/services/tool'
|
||||
import FitFullscreen from '@/components/common/FitFullscreen'
|
||||
@@ -82,16 +83,12 @@ const CommonCard = ({
|
||||
})
|
||||
return
|
||||
}
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnSourceBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
navigate(
|
||||
`/source/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToSource(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnAndroidBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
@@ -134,16 +131,12 @@ const CommonCard = ({
|
||||
)
|
||||
return
|
||||
}
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
const handleOnWebBtnClick = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
navigate(
|
||||
`/view/${authorUsername}/${toolId}${platform !== import.meta.env.VITE_PLATFORM ? `?platform=${platform}` : ''}`
|
||||
)
|
||||
navigateToView(navigate, authorUsername, toolId, platform)
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -269,7 +262,7 @@ const User = () => {
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.warning('用户不存在')
|
||||
setTimeout(() => {
|
||||
navigate('/')
|
||||
navigateToRoot(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import '@/assets/css/pages/tools/view.scss'
|
||||
import { DATABASE_NO_RECORD_FOUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants'
|
||||
import { getLoginStatus } from '@/util/auth'
|
||||
import { navigateToRepository, navigateToRoot, navigateToView } from '@/util/navigation'
|
||||
import { r_tool_detail } from '@/services/tool'
|
||||
import compiler from '@/components/Playground/compiler'
|
||||
import { IImportMap } from '@/components/Playground/shared'
|
||||
@@ -72,7 +73,7 @@ const View = () => {
|
||||
case DATABASE_NO_RECORD_FOUND:
|
||||
void message.error('未找到指定工具')
|
||||
setTimeout(() => {
|
||||
navigate('/repository')
|
||||
navigateToRepository(navigate)
|
||||
}, 3000)
|
||||
break
|
||||
default:
|
||||
@@ -86,22 +87,23 @@ const View = () => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const platform = searchParams.get('platform')!
|
||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(platform)) {
|
||||
navigateToRepository(navigate)
|
||||
return
|
||||
}
|
||||
if (username === '!' && !getLoginStatus()) {
|
||||
setTimeout(() => {
|
||||
navigate('/')
|
||||
navigateToRoot(navigate)
|
||||
}, 3000)
|
||||
return
|
||||
}
|
||||
if (username !== '!' && ver) {
|
||||
navigate(`/view/${username}/${toolId}`)
|
||||
navigateToView(navigate, username!, toolId!, platform as Platform)
|
||||
return
|
||||
}
|
||||
if (username === '!' && !ver) {
|
||||
navigate(`/view/!/${toolId}/latest`)
|
||||
return
|
||||
}
|
||||
if (!['WEB', 'DESKTOP', 'ANDROID'].includes(searchParams.get('platform')!)) {
|
||||
navigate('/repository')
|
||||
navigateToView(navigate, '!', toolId!, platform as Platform)
|
||||
return
|
||||
}
|
||||
getTool()
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from '@/constants/common.constants'
|
||||
import { checkDesktop } from '@/util/common'
|
||||
import { getLoginStatus } from '@/util/auth'
|
||||
import { navigateToEdit, navigateToSource, navigateToView } from '@/util/navigation'
|
||||
import {
|
||||
r_tool_cancel,
|
||||
r_tool_delete,
|
||||
@@ -145,8 +146,12 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
||||
|
||||
const handleOnOpenTool = () => {
|
||||
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
||||
navigate(
|
||||
`/view/!/${selectedTool.toolId}/${selectedTool.ver}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
||||
navigateToView(
|
||||
navigate,
|
||||
'!',
|
||||
selectedTool.toolId,
|
||||
selectedTool.platform,
|
||||
selectedTool.ver
|
||||
)
|
||||
} else {
|
||||
void message.warning('此应用需要桌面端环境,请在桌面端打开')
|
||||
@@ -157,9 +162,7 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
||||
if (['NONE', 'REJECT'].includes(selectedTool.review)) {
|
||||
return () => {
|
||||
if (checkDesktop() || selectedTool.platform !== 'DESKTOP') {
|
||||
navigate(
|
||||
`/edit/${selectedTool.toolId}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
||||
)
|
||||
navigateToEdit(navigate, selectedTool.toolId, selectedTool.platform)
|
||||
} else {
|
||||
void message.warning('此应用需要桌面端环境,请在桌面端编辑')
|
||||
}
|
||||
@@ -171,8 +174,12 @@ const ToolCard = ({ tools, onDelete, onUpgrade, onSubmit, onCancel }: ToolCardPr
|
||||
const handleOnSourceTool = () => {
|
||||
if (selectedTool.review === 'PASS') {
|
||||
return () => {
|
||||
navigate(
|
||||
`/source/!/${selectedTool.toolId}/${selectedTool.ver}${selectedTool.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${selectedTool.platform}` : ''}`
|
||||
navigateToSource(
|
||||
navigate,
|
||||
'!',
|
||||
selectedTool.toolId,
|
||||
selectedTool.platform,
|
||||
selectedTool.ver
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -406,8 +413,10 @@ const Tools = () => {
|
||||
checkDesktop() ||
|
||||
response.data!.platform !== 'DESKTOP'
|
||||
) {
|
||||
navigate(
|
||||
`/edit/${response.data!.toolId}${response.data!.platform !== import.meta.env.VITE_PLATFORM ? `?platform=${response.data!.platform}` : ''}`
|
||||
navigateToEdit(
|
||||
navigate,
|
||||
response.data!.toolId,
|
||||
response.data!.platform
|
||||
)
|
||||
}
|
||||
resolve()
|
||||
|
||||
119
src/util/navigation.tsx
Normal file
119
src/util/navigation.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user