inleft
2022-02-15 d734432a8bbbf863dc3de305f56e831c56ac767a
commit | author | age
9bcb19 1 /**
I 2  * 向后端请求用户的菜单,动态生成路由
3  */
4 import { constantRouterMap } from '@/config/router.config'
5 import { generatorDynamicRouter } from '@/router/generator-routers'
6
7 const permission = {
8   state: {
9     routers: constantRouterMap,
10     addRouters: []
11   },
12   mutations: {
13     SET_ROUTERS: (state, routers) => {
14       state.addRouters = routers
15       state.routers = constantRouterMap.concat(routers)
16     }
17   },
18   actions: {
19     GenerateRoutes ({ commit }, data) {
20       return new Promise(resolve => {
21         generatorDynamicRouter(data).then(routers => {
22           commit('SET_ROUTERS', routers)
23           resolve()
24         })
25       }).catch(err => {
26         // eslint-disable-next-line no-undef
27         reject(err)
28       })
29     }
30   }
31 }
32
33 export default permission