|
|
@@ -1,4 +1,4 @@
|
|
|
-import router from './router'
|
|
|
+import router, { selfAddRoutes } from './router'
|
|
|
import store from './store'
|
|
|
import { Message } from 'element-ui'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
@@ -28,27 +28,30 @@ router.beforeEach(async(to, from, next) => {
|
|
|
} else {
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
|
+ console.log('ssss', hasRoles)
|
|
|
if (hasRoles) {
|
|
|
next()
|
|
|
} else {
|
|
|
try {
|
|
|
// get user info
|
|
|
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
|
|
- const { roles } = await store.dispatch('user/getInfo')
|
|
|
-
|
|
|
+ // const { roles } = await store.dispatch('user/getInfo')
|
|
|
+ const { roles } = ['admin'];
|
|
|
// generate accessible routes map based on roles
|
|
|
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
|
|
|
-
|
|
|
// dynamically add accessible routes
|
|
|
- router.addRoutes(accessRoutes)
|
|
|
+
|
|
|
+ // router.addRoutes(accessRoutes)
|
|
|
+ selfAddRoutes(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) {
|
|
|
+ console.log('------>', error, '<------')
|
|
|
// remove token and go to login page to re-login
|
|
|
await store.dispatch('user/resetToken')
|
|
|
- Message.error(error || 'Has Error')
|
|
|
+ // Message.error(error || 'Has Error')
|
|
|
next(`/login?redirect=${to.path}`)
|
|
|
NProgress.done()
|
|
|
}
|
|
|
@@ -56,7 +59,7 @@ router.beforeEach(async(to, from, next) => {
|
|
|
}
|
|
|
} else {
|
|
|
/* has no token*/
|
|
|
-
|
|
|
+alert('no token')
|
|
|
if (whiteList.indexOf(to.path) !== -1) {
|
|
|
// in the free login whitelist, go directly
|
|
|
next()
|