|
|
@ -11,7 +11,8 @@ const permission = { |
|
|
|
addRoutes: [], |
|
|
|
defaultRoutes: [], |
|
|
|
topbarRouters: [], |
|
|
|
sidebarRouters: [] |
|
|
|
sidebarRouters: [], |
|
|
|
indexPage: '', |
|
|
|
}, |
|
|
|
mutations: { |
|
|
|
SET_ROUTES: (state, routes) => { |
|
|
@ -29,6 +30,9 @@ const permission = { |
|
|
|
}] |
|
|
|
state.topbarRouters = routes.concat(index); |
|
|
|
}, |
|
|
|
SET_INDEX_PAGE: (state, routes) => { |
|
|
|
state.indexPage = routes |
|
|
|
}, |
|
|
|
SET_SIDEBAR_ROUTERS: (state, routes) => { |
|
|
|
state.sidebarRouters = routes |
|
|
|
}, |
|
|
@ -38,9 +42,23 @@ const permission = { |
|
|
|
GenerateRoutes({ commit }) { |
|
|
|
return new Promise(resolve => { |
|
|
|
// 向后端请求路由数据
|
|
|
|
getRouters(1).then(res => { |
|
|
|
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); |
|
|
@ -50,6 +68,7 @@ const permission = { |
|
|
|
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) |
|
|
|
commit('SET_DEFAULT_ROUTES', sidebarRoutes) |
|
|
|
commit('SET_TOPBAR_ROUTES', sidebarRoutes) |
|
|
|
commit('SET_INDEX_PAGE', indexdata) |
|
|
|
resolve(rewriteRoutes) |
|
|
|
}) |
|
|
|
}) |
|
|
|