This commit is contained in:
13684185576
2025-07-22 18:51:12 +08:00
parent a2b8cd74e9
commit 3c9d244817
4 changed files with 77 additions and 71 deletions

View File

@ -6,7 +6,7 @@ import {
removeAllItem
} from "@/utils/storage";
// 白名单
const whiteList = ['/login','/','/StationLevel', '/oatuh_login','/editPassword', '/404', '/401']
const whiteList = ['/login','/oatuh_login','/','/StationLevel','/editPassword', '/404', '/401']
/**
* 路由前置守卫
* to 去哪里
@ -14,42 +14,45 @@ const whiteList = ['/login','/','/StationLevel', '/oatuh_login','/editPassword',
* next 往下走
*/
let onRun = true;
// router.beforeEach(async (to, from, next) => {
// // 存在 token ,进入主页
// // if (store.state.user.token) {
// // 快捷访问
// if (store.getters.token) {
// // 判断用户资料是否获取
// // 若不存在用户信息,则需要获取用户信息
// // 触发获取用户信息的 action并获取用户当前权限
// await store.commit('permission/setRouteReady', true)
// // 添加完动态路由之后,需要在进行一次主动跳转
// const afterMenuList = await getItem('menusPermission');
// // 处理用户权限,筛选出需要添加的权限
// if (store.state.permission.routes == 0) {
// const filterRoutes = await store.dispatch('permission/filterRoutes', afterMenuList)
// filterRoutes.forEach(item => {
// router.addRoute(item)
// })
// next({
// ...to,
// replace: true
// })
// } else {
// next()
// }
// // 利用 addRoute 循环添加
// } else {
// const isOatuh = getItem('isOatuh')
// // 没有token的情况下可以进入白名单
// if (whiteList.indexOf(to.path) > -1) {
// next()
// } else {
// if (isOatuh) {
// next('/oatuh_login')
// } else {
// next('/login')
// }
// }
// }
// })
router.beforeEach(async (to, from, next) => {
// 存在 token ,进入主页
console.log(store.getters.token,'===store.getters.token');
// if (store.state.user.token) {
// 快捷访问
if (store.getters.token) {
// 判断用户资料是否获取
// 若不存在用户信息,则需要获取用户信息
// 触发获取用户信息的 action并获取用户当前权限
await store.commit('permission/setRouteReady', true)
// 添加完动态路由之后,需要在进行一次主动跳转
const afterMenuList = await getItem('menusPermission');
// 处理用户权限,筛选出需要添加的权限
if (store.state.permission.routes == 0) {
const filterRoutes = await store.dispatch('permission/filterRoutes', afterMenuList)
filterRoutes.forEach(item => {
router.addRoute(item)
})
next({
...to,
replace: true
})
} else {
next()
}
// 利用 addRoute 循环添加
} else {
const isOatuh = getItem('isOatuh')
// 没有token的情况下可以进入白名单
if (whiteList.indexOf(to.path) > -1) {
next()
} else {
next('/oatuh_login')
// if (isOatuh) {
// next('/oatuh_login')
// } else {
// next('/login')
// }
}
}
})