feat: 优化登录后的页面重定向逻辑

- 在路由守卫中,将重定向参数改为完整的编码路径
- 在登录成功后,根据重定向参数跳转到原请求页面
- 优化了账户、邮箱和手机登录后的重定向逻辑

Closes #IC42TM
Closes #1
This commit is contained in:
2025-07-07 21:11:20 +08:00
parent 3b3b35e0cb
commit aaefb7f8e4
5 changed files with 43 additions and 21 deletions

View File

@@ -124,12 +124,19 @@ const handleLogin = async () => {
const { redirect, ...othersQuery } = router.currentRoute.value.query
const { rememberMe } = loginConfig.value
loginConfig.value.username = rememberMe ? form.username : ''
await router.push({
path: (redirect as string) || '/',
query: {
...othersQuery,
},
})
// 如果有重定向参数,解码并直接跳转到完整路径
if (redirect) {
const redirectPath = decodeURIComponent(redirect as string)
await router.push(redirectPath)
} else {
await router.push({
path: '/',
query: {
...othersQuery,
},
})
}
Message.success('欢迎使用')
} catch (error) {
console.error(error)

View File

@@ -72,12 +72,19 @@ const handleLogin = async () => {
await userStore.emailLogin(form)
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
await router.push({
path: (redirect as string) || '/',
query: {
...othersQuery,
},
})
// 如果有重定向参数,解码并直接跳转到完整路径
if (redirect) {
const redirectPath = decodeURIComponent(redirect as string)
await router.push(redirectPath)
} else {
await router.push({
path: '/',
query: {
...othersQuery,
},
})
}
Message.success('欢迎使用')
} catch (error) {
form.captcha = ''

View File

@@ -72,12 +72,19 @@ const handleLogin = async () => {
await userStore.phoneLogin(form)
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
await router.push({
path: (redirect as string) || '/',
query: {
...othersQuery,
},
})
// 如果有重定向参数,解码并直接跳转到完整路径
if (redirect) {
const redirectPath = decodeURIComponent(redirect as string)
await router.push(redirectPath)
} else {
await router.push({
path: '/',
query: {
...othersQuery,
},
})
}
Message.success('欢迎使用')
} catch (error) {
form.captcha = ''