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

修复没权限重复跳转bug

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