vuex add namespaced

This commit is contained in:
Pan
2019-03-20 13:44:42 +08:00
parent 7c33568883
commit 0c50029cf7
20 changed files with 414 additions and 382 deletions

View File

@@ -29,18 +29,18 @@ router.beforeEach((to, from, next) => {
if (store.getters.roles.length === 0) {
// 判断当前用户是否已拉取完user_info信息
store
.dispatch('getInfo') // dispatch @/store/modules/user login getInfo
.dispatch('user/getInfo')
.then(res => {
// 拉取user_info
const { roles } = res // note: roles must be a object array! such as: [{id: '1', name: 'editor'}, {id: '2', name: 'developer'}]
store.dispatch('generateRoutes', { roles }).then(accessRoutes => {
store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
})
})
.catch(err => {
store.dispatch('resetToken').then(() => {
store.dispatch('user/resetToken').then(() => {
Message.error(err)
next({ path: '/' })
})