修改分模块
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
/*
|
||||
* @Date: 2020-12-14 09:07:03
|
||||
* @LastEditors: gtz
|
||||
* @LastEditTime: 2021-02-25 09:42:36
|
||||
* @LastEditors: zwq
|
||||
* @LastEditTime: 2021-12-22 16:13:30
|
||||
* @FilePath: \basic-admin\src\permission.js
|
||||
* @Description: 路由权限检查
|
||||
*/
|
||||
import router from './router'
|
||||
// import { resetRouter } from '@/router'
|
||||
import { Message } from 'element-ui'
|
||||
import NProgress from 'nprogress' // progress bar
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
||||
@@ -35,38 +34,28 @@ router.beforeEach(async(to, from, next) => {
|
||||
next({ path: '/' })
|
||||
NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
||||
} else {
|
||||
const hasRoles = store.getters.menus && store.getters.menus.length > 0
|
||||
console.log('store.getters.menus', store.getters.menus)
|
||||
console.log('store.getters', store.getters)
|
||||
console.log('hasRoles=', hasRoles)
|
||||
if (hasRoles) {
|
||||
console.log('hasRoles=', store.getters.menus)
|
||||
// next()
|
||||
NProgress.done()
|
||||
try {
|
||||
// // generate accessible routes map based on roles
|
||||
// const accessRoutes = await store.dispatch('permission/generateRoutes')
|
||||
// console.log(accessRoutes)
|
||||
// router.addRoutes(accessRoutes)
|
||||
next()
|
||||
NProgress.done()
|
||||
} else {
|
||||
try {
|
||||
// // generate accessible routes map based on roles
|
||||
const { menus } = await store.dispatch('user/getInfo')
|
||||
console.log(menus)
|
||||
const accessRoutes = await store.dispatch('permission/generateRoutes', menus)
|
||||
console.log('accessRoutes', accessRoutes)
|
||||
router.addRoutes(accessRoutes)
|
||||
next({ ...to, replace: true })
|
||||
// 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) {
|
||||
} catch (error) {
|
||||
// remove token and go to login page to re-login
|
||||
next(`/login?redirect=${to.path}`)
|
||||
await store.dispatch('user/resetToken')
|
||||
Message.error(error || 'Has Error')
|
||||
NProgress.done()
|
||||
}
|
||||
next(`/login?redirect=${to.path}`)
|
||||
await store.dispatch('user/resetToken')
|
||||
Message.error(error || 'Has Error')
|
||||
NProgress.done()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* has no token*/
|
||||
console.log('has no token to.path=' + to.path)
|
||||
console.log('to.path=' + to.path)
|
||||
console.log('whiteList.indexOf(to.path)=' + whiteList.indexOf(to.path))
|
||||
if (whiteList.indexOf(to.path) !== -1) {
|
||||
// in the free login whitelist, go directly
|
||||
|
||||
Reference in New Issue
Block a user