| | |
| | | addRoutes: [], |
| | | defaultRoutes: [], |
| | | topbarRouters: [], |
| | | sidebarRouters: [] |
| | | sidebarRouters: [], |
| | | indexPage: '' |
| | | }, |
| | | mutations: { |
| | | SET_ROUTES: (state, routes) => { |
| | |
| | | SET_SIDEBAR_ROUTERS: (state, routes) => { |
| | | state.sidebarRouters = routes |
| | | }, |
| | | SET_INDEX_PAGE: (state, routes) => { |
| | | state.indexPage = routes |
| | | } |
| | | }, |
| | | actions: { |
| | | // 生成路由 |
| | |
| | | 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); |
| | |
| | | commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) |
| | | commit('SET_DEFAULT_ROUTES', sidebarRoutes) |
| | | commit('SET_TOPBAR_ROUTES', sidebarRoutes) |
| | | commit('SET_INDEX_PAGE', indexdata) |
| | | resolve(rewriteRoutes) |
| | | }) |
| | | }) |