马宇豪
2024-03-01 f542d731de01e6897243b2072523ecdaa6c63505
src/store/modules/permission.js
@@ -11,7 +11,8 @@
    addRoutes: [],
    defaultRoutes: [],
    topbarRouters: [],
    sidebarRouters: []
    sidebarRouters: [],
    indexPage: ''
  },
  mutations: {
    SET_ROUTES: (state, routes) => {
@@ -27,6 +28,9 @@
    SET_SIDEBAR_ROUTERS: (state, routes) => {
      state.sidebarRouters = routes
    },
    SET_INDEX_PAGE: (state, routes) => {
      state.indexPage = routes
    }
  },
  actions: {
    // 生成路由
@@ -36,6 +40,20 @@
        getRouters().then(res => {
          const sdata = JSON.parse(JSON.stringify(res.data))
          const rdata = JSON.parse(JSON.stringify(res.data))
          let indexdata = res.data[0].path + "/" + res.data[0].children[0].path
          if (res.data[0].children[0].query !== undefined) { //如果当前路由存在路由参数,则带入
            let query = JSON.parse(res.data[0].children[0].query);
            let temp = '';
            for (var val in query) {
              if (temp.length == 0) {
                temp = "?";
              } else {
                temp = temp + "&";
              }
              temp = temp + val + "=" + query[val];
            }
            indexdata = indexdata + temp;
          }
          const sidebarRoutes = filterAsyncRouter(sdata)
          const rewriteRoutes = filterAsyncRouter(rdata, false, true)
          const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
@@ -45,6 +63,7 @@
          commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
          commit('SET_DEFAULT_ROUTES', sidebarRoutes)
          commit('SET_TOPBAR_ROUTES', sidebarRoutes)
          commit('SET_INDEX_PAGE', indexdata)
          resolve(rewriteRoutes)
        })
      })