Refactor(Navigate): Optimize navigate
Unified management navigation
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user