import { defaultRoutes, rolesOfRoutes } from "@/router/routes-config";
import { createAsyncRoutes } from "@/utils/router-generator";
const state = {
  // 侧边栏菜单
  sideBarRoutes: [],
  // 顶部面包屑
  topBarRoutes: [],
  // 生成后路由
  routes: []
};

const actions = {

  createRouter({ commit }, payload) {
    // 生成路由
    return new Promise((resolve, reject) => {
      // 侧边栏
      const sList = JSON.parse(JSON.stringify(rolesOfRoutes));
      const rList = JSON.parse(JSON.stringify(rolesOfRoutes));
      // 生成后侧边栏
      const sideBarRoutes = createAsyncRoutes(sList[0].children, payload);
      const routes = createAsyncRoutes(rList, payload);
      commit("setSideBar", sideBarRoutes);
      console.log(sideBarRoutes);
      resolve(routes);
    });
  }

};

const mutations = {
  setSideBar(state, payload) {
    state.sideBarRoutes = payload;
  }
};

const getters = {

};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
};