更新
This commit is contained in:
@@ -49,12 +49,26 @@ const addRoutesRecursively = (routes: any, parentPath = '') => {
|
||||
|
||||
const loginPath = PageEnum.LOGIN
|
||||
const defaultPath = PageEnum.INDEX
|
||||
const changePasswordPath = '/change-password'
|
||||
// 免登录白名单
|
||||
const whiteList: string[] = [PageEnum.LOGIN, PageEnum.ERROR_403]
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
document.title = to.meta.title ?? config.title
|
||||
const userStore = useUserStore()
|
||||
const tabsStore = useTabsStore()
|
||||
|
||||
// 特殊处理:修改密码页面
|
||||
if (to.path === changePasswordPath) {
|
||||
if (!userStore.token) {
|
||||
// 未登录,跳转到登录页
|
||||
next({ path: loginPath })
|
||||
return
|
||||
}
|
||||
// 需要修改密码,允许访问
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
if (whiteList.includes(to.path)) {
|
||||
// 在免登录白名单,直接进入
|
||||
next()
|
||||
@@ -62,6 +76,13 @@ router.beforeEach(async (to, from, next) => {
|
||||
// 获取用户信息
|
||||
const hasGetUserInfo = Object.keys(userStore.userInfo).length !== 0
|
||||
if (hasGetUserInfo) {
|
||||
// 已经获取过用户信息,检查是否需要修改密码
|
||||
if (userStore.isPaw === 0) {
|
||||
// 需要修改密码,强制跳转到修改密码页面
|
||||
next({ path: changePasswordPath })
|
||||
return
|
||||
}
|
||||
|
||||
if (to.path === loginPath) {
|
||||
next({ path: defaultPath })
|
||||
} else {
|
||||
@@ -70,6 +91,14 @@ router.beforeEach(async (to, from, next) => {
|
||||
} else {
|
||||
try {
|
||||
await userStore.getUserInfo()
|
||||
|
||||
// 获取用户信息后,检查是否需要修改密码
|
||||
if (userStore.isPaw === 0) {
|
||||
// 需要修改密码,强制跳转到修改密码页面
|
||||
next({ path: changePasswordPath })
|
||||
return
|
||||
}
|
||||
|
||||
const routes = userStore.routes
|
||||
// 找到第一个有效路由
|
||||
const routeName = findFirstValidRoute(routes)
|
||||
|
||||
Reference in New Issue
Block a user