This commit is contained in:
张成
2025-10-08 19:30:09 +08:00
parent 7e888970d3
commit 99f73eff84
6 changed files with 1339 additions and 3 deletions

View File

@@ -95,7 +95,15 @@ export default {
this.collapsed = collapsed
},
goHome() {
this.$router.push({ path: '/' })
// 避免重复导航到当前页面
if (this.$route.path !== '/' && this.$route.path !== '/home') {
this.$router.push({ path: '/' }).catch(err => {
// 忽略重复导航错误
if (err.name !== 'NavigationDuplicated') {
console.error(err)
}
})
}
},
turnToPage(route) {
let { name, params, query } = {}
@@ -109,10 +117,21 @@ export default {
window.open(name.split('_')[1])
return
}
// 避免重复导航到当前页面
if (this.$route.name === name) {
return
}
this.$router.push({
name,
params,
query
}).catch(err => {
// 忽略重复导航错误
if (err.name !== 'NavigationDuplicated') {
console.error(err)
}
})
},
handleCollapsedChange(state) {

View File

@@ -43,12 +43,21 @@ export const setupRouterGuards = (router, ViewUI, homeName = 'home') => {
}
if (!token && to.name !== 'login') {
// 未登录且访问非登录页 → 跳转到登录页
next({ name: 'login' })
} else if (!token && to.name === 'login') {
// 未登录且访问登录页 → 允许访问
next()
} else if (token && to.name === 'login') {
next({ name: homeName })
// 已登录且访问登录页 → 重定向到首页
// 避免重复导航警告
if (from.name === homeName) {
next(false)
} else {
next({ name: homeName })
}
} else {
// 其他情况 → 允许访问
next()
}
})

View File

@@ -53,7 +53,11 @@ export default {
Page404
})
this.$Message.success('登录成功!')
window.location.reload()
// 跳转到首页(使用 location.href 触发完整页面加载)
setTimeout(() => {
window.location.href = window.location.origin + window.location.pathname + '#/'
}, 500)
} catch (error) {
console.error('登录失败:', error)
// 处理不同类型的错误