mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-11-10 14:57:09 +08:00
feat: 优化登录后的页面重定向逻辑
- 在路由守卫中,将重定向参数改为完整的编码路径 - 在登录成功后,根据重定向参数跳转到原请求页面 - 优化了账户、邮箱和手机登录后的重定向逻辑 Closes #IC42TM Closes #1
This commit is contained in:
@@ -110,7 +110,7 @@ export const setupRouterGuard = (router: Router) => {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
|
// 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
|
||||||
await userStore.logoutCallBack()
|
await userStore.logoutCallBack()
|
||||||
next(`/login?redirect=${to.path}`)
|
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
@@ -123,7 +123,7 @@ export const setupRouterGuard = (router: Router) => {
|
|||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
// 其他没有访问权限的页面将被重定向到登录页面
|
// 其他没有访问权限的页面将被重定向到登录页面
|
||||||
next('/login')
|
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ http.interceptors.response.use(
|
|||||||
async onOk() {
|
async onOk() {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
await userStore.logoutCallBack()
|
await userStore.logoutCallBack()
|
||||||
await router.replace('/login')
|
const currentPath = router.currentRoute.value.fullPath
|
||||||
|
await router.replace(`/login?redirect=${encodeURIComponent(currentPath)}`)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -124,12 +124,19 @@ const handleLogin = async () => {
|
|||||||
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
||||||
const { rememberMe } = loginConfig.value
|
const { rememberMe } = loginConfig.value
|
||||||
loginConfig.value.username = rememberMe ? form.username : ''
|
loginConfig.value.username = rememberMe ? form.username : ''
|
||||||
|
|
||||||
|
// 如果有重定向参数,解码并直接跳转到完整路径
|
||||||
|
if (redirect) {
|
||||||
|
const redirectPath = decodeURIComponent(redirect as string)
|
||||||
|
await router.push(redirectPath)
|
||||||
|
} else {
|
||||||
await router.push({
|
await router.push({
|
||||||
path: (redirect as string) || '/',
|
path: '/',
|
||||||
query: {
|
query: {
|
||||||
...othersQuery,
|
...othersQuery,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
Message.success('欢迎使用')
|
Message.success('欢迎使用')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|||||||
@@ -72,12 +72,19 @@ const handleLogin = async () => {
|
|||||||
await userStore.emailLogin(form)
|
await userStore.emailLogin(form)
|
||||||
tabsStore.reset()
|
tabsStore.reset()
|
||||||
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
||||||
|
|
||||||
|
// 如果有重定向参数,解码并直接跳转到完整路径
|
||||||
|
if (redirect) {
|
||||||
|
const redirectPath = decodeURIComponent(redirect as string)
|
||||||
|
await router.push(redirectPath)
|
||||||
|
} else {
|
||||||
await router.push({
|
await router.push({
|
||||||
path: (redirect as string) || '/',
|
path: '/',
|
||||||
query: {
|
query: {
|
||||||
...othersQuery,
|
...othersQuery,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
Message.success('欢迎使用')
|
Message.success('欢迎使用')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
form.captcha = ''
|
form.captcha = ''
|
||||||
|
|||||||
@@ -72,12 +72,19 @@ const handleLogin = async () => {
|
|||||||
await userStore.phoneLogin(form)
|
await userStore.phoneLogin(form)
|
||||||
tabsStore.reset()
|
tabsStore.reset()
|
||||||
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
||||||
|
|
||||||
|
// 如果有重定向参数,解码并直接跳转到完整路径
|
||||||
|
if (redirect) {
|
||||||
|
const redirectPath = decodeURIComponent(redirect as string)
|
||||||
|
await router.push(redirectPath)
|
||||||
|
} else {
|
||||||
await router.push({
|
await router.push({
|
||||||
path: (redirect as string) || '/',
|
path: '/',
|
||||||
query: {
|
query: {
|
||||||
...othersQuery,
|
...othersQuery,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
Message.success('欢迎使用')
|
Message.success('欢迎使用')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
form.captcha = ''
|
form.captcha = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user