【类 型】:fix
【原 因】:安卓端 身份token过期会弹窗提示 需要重新打开app 【过 程】:强制跳转到登陆页面 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
a59233a6d9
commit
653b1bf513
@ -6,37 +6,37 @@ import 'nprogress/nprogress.css' // 进度条 style
|
||||
NProgress.configure({ showSpinner: false }) // 进度条 Configuration
|
||||
|
||||
/**
|
||||
* @description: 路由守卫
|
||||
* @description: 路由前置守卫
|
||||
*/
|
||||
router.beforeEach((to, from, next) => {
|
||||
// start 进度条
|
||||
NProgress.start()
|
||||
// 设置title
|
||||
document.title = getPageTitle(to.meta.title)
|
||||
|
||||
store.commit('user/initUser') // 用户信息初始化
|
||||
// 初始化用户信息
|
||||
store.commit('user/initUser')
|
||||
const power = store.state.user.power
|
||||
const token = store.state.user.token
|
||||
|
||||
// 判断 token 是否存在
|
||||
if (!token) {
|
||||
if (to.path === '/login') {
|
||||
next()
|
||||
} else {
|
||||
next('/login') // 直接调用 next('/login')
|
||||
// 安卓端兼容性更强的方式,强制跳转登录页
|
||||
router.replace('/login')
|
||||
}
|
||||
} else {
|
||||
if (to.path === '/login') {
|
||||
next('/')
|
||||
next('/') // 已登录访问登录页,重定向首页
|
||||
} else {
|
||||
if (to.meta.roles && to.meta.roles.indexOf(power) >= 0) { // 确保 roles 存在
|
||||
// 校验权限
|
||||
if (!to.meta.roles || to.meta.roles.indexOf(power) >= 0) {
|
||||
next()
|
||||
} else {
|
||||
next('/')
|
||||
next('/') // 权限不足时跳转首页
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user