提交 6ca00859 authored 作者: pengxiaohui's avatar pengxiaohui

修复没权限重复跳转bug

上级 073f2da2
import store from '@/store'
import router, { resetRouter } from '@/router'
// import router, { resetRouter } from '@/router'
export default class BeforeEnter {
constructor(opt) {
this.opt = opt || {}
......@@ -11,23 +11,26 @@ export default class BeforeEnter {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return
} else {
const hasPermissions = store.state.user.permissions && store.state.user.permissions.length > 0
if (hasPermissions) {
next()
} else {
// console.log(1234444)
await store.dispatch('checkRolesPermissions')
const permissions = store.state.user.permissions
// 基于权限获取可接入的路由
const accessRoutes = await store.dispatch('permission/routesByPermissions', permissions)
// 重新设置路由
resetRouter()
// dynamically add accessible routes
router.addRoutes(accessRoutes)
// hack method to ensure that addRoutes is complete
// set the replace: true, so the navigation will not leave a history record
next({ ...to, replace: true })
}
// const hasPermissions = store.state.user.permissions && store.state.user.permissions.length > 0
// if (hasPermissions) {
// next()
// } else {
// try {
// await store.dispatch('checkRolesPermissions')
// const permissions = store.state.user.permissions
// // 基于权限获取可接入的路由
// const accessRoutes = await store.dispatch('permission/routesByPermissions', permissions)
// // 重新设置路由
// resetRouter()
// // dynamically add accessible routes
// router.addRoutes(accessRoutes)
// // hack method to ensure that addRoutes is complete
// // set the replace: true, so the navigation will not leave a history record
// next({ ...to, replace: true })
// } catch (error) {
// next()
// }
// }
}
// store.dispatch('setUserRoles')
next()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论