/**
 * 向后端请求用户的菜单，动态生成路由
 */
import { generatorDynamicRouter, constantRouterMap } from '@/router/generator-platform-routers'

const permission = {
  state: {
    routers: constantRouterMap,
    addRouters: []
  },
  mutations: {
    SET_ROUTERS: (state, routers) => {
      state.addRouters = routers
      state.routers = constantRouterMap.concat(routers)
    }
  },
  actions: {
    GenerateRoutes ({ commit }, menus) {
      return new Promise(resolve => {
        generatorDynamicRouter(menus.menus).then(routers => {
          commit('SET_ROUTERS', routers)
          resolve()
        })
      })
    }
  }
}

export default permission
