/*
 * @Author: your name
 * @Date: 2022-02-22 14:22:47
 * @LastEditTime: 2022-02-23 10:44:43
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \lowcode-ui\src\store\modules\async-router.js
 */
/**
 * 向后端请求用户的菜单，动态生成路由
 */
 import { constantRouterMap } from '@/config/router.config'

 const permission = {
   state: {
     routers: constantRouterMap,
     addRouters: []
   },
   mutations: {
     SET_ROUTERS: (state, routers) => {
       state.addRouters = routers
       state.routers = constantRouterMap.concat(routers)
     }
   },
   actions: {
     GenerateRoutes ({ commit }, routes) {
      return new Promise(resolve => {
        const routelist = routes.constRoutes
        commit('SET_ROUTERS', routelist)
        resolve(routelist)
      })
     },
         // 动态添加主界面路由，需要缓存
    UpdatePageRouter ({ commit }, routes) {
      return new Promise(resolve => {
        const routelist = routes.contentPages
        commit('SET_ROUTERS', routelist)
        resolve(routelist)
      })
    }
   }
 }

 export default permission
