fix: 绑定页面登录态检查 + 登录后返回原页面
Login.vue: - goCasdoorLogin() 前将 redirect 参数存入 sessionStorage - 登录成功后检查 sessionStorage 跳回原页面 - wecomLogin 流程同样支持 returnUrl WecomBind.vue: - onMounted 检测未登录 → 跳转 /login?redirect=/wecom-bind?token=xxx - 登录后自动回到绑定页面,auth.user 不再为空 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,8 @@ onMounted(async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
await auth.casdoorLogin(code, state)
|
||||
const returnUrl = sessionStorage.getItem('login_return_url')
|
||||
if (returnUrl) { sessionStorage.removeItem('login_return_url'); router.push(returnUrl); return }
|
||||
ElMessage.success('登录成功')
|
||||
router.push(auth.isManager ? '/m' : '/')
|
||||
} catch (e: any) {
|
||||
@@ -45,6 +47,8 @@ onMounted(async () => {
|
||||
name: res.data.name,
|
||||
role: res.data.role,
|
||||
})
|
||||
const returnUrl = sessionStorage.getItem('login_return_url')
|
||||
if (returnUrl) { sessionStorage.removeItem('login_return_url'); router.push(returnUrl); return }
|
||||
ElMessage.success('登录成功')
|
||||
router.push(auth.isManager ? '/m' : '/')
|
||||
} catch (e: any) {
|
||||
@@ -56,7 +60,11 @@ onMounted(async () => {
|
||||
})
|
||||
|
||||
function goCasdoorLogin() {
|
||||
// Redirect to Casdoor authorization page
|
||||
// Save return URL before redirecting to Casdoor
|
||||
const returnUrl = (route.query.redirect as string) || ''
|
||||
if (returnUrl) {
|
||||
sessionStorage.setItem('login_return_url', returnUrl)
|
||||
}
|
||||
const endpoint = import.meta.env.VITE_CASDOOR_ENDPOINT
|
||||
const clientId = import.meta.env.VITE_CASDOOR_CLIENT_ID
|
||||
const redirectUri = encodeURIComponent(window.location.origin + '/login')
|
||||
|
||||
@@ -18,6 +18,12 @@ onMounted(() => {
|
||||
if (!bindToken) {
|
||||
errorMsg.value = '无效的绑定链接'
|
||||
setTimeout(() => router.replace('/'), 2000)
|
||||
return
|
||||
}
|
||||
if (!auth.isLoggedIn) {
|
||||
// Not logged in yet — redirect to login, then come back here
|
||||
router.push(`/login?redirect=${encodeURIComponent(route.fullPath)}`)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user