|
@@ -27,19 +27,19 @@ const permission = {
|
|
|
},
|
|
|
SET_SIDEBAR_ROUTERS: (state, routes) => {
|
|
|
state.sidebarRouters = routes
|
|
|
- },
|
|
|
+ }
|
|
|
},
|
|
|
actions: {
|
|
|
// 生成路由
|
|
|
GenerateRoutes({ commit }) {
|
|
|
- return new Promise(resolve => {
|
|
|
+ return new Promise((resolve) => {
|
|
|
// 向后端请求路由数据
|
|
|
- getRouters().then(res => {
|
|
|
- console.log(res.data)
|
|
|
+ getRouters().then((res) => {
|
|
|
+ // console.log(res.data)
|
|
|
const arr = []
|
|
|
try {
|
|
|
eachTree(res.data, (element) => {
|
|
|
- console.log(element.meta.title)
|
|
|
+ // console.log(element.meta.title)
|
|
|
element.meta.title = i18n.t(element.meta.title)
|
|
|
arr.push(element.meta.title)
|
|
|
})
|
|
@@ -47,14 +47,14 @@ const permission = {
|
|
|
console.log(error)
|
|
|
}
|
|
|
|
|
|
- console.log(arr)
|
|
|
+ // console.log(arr)
|
|
|
const sdata = JSON.parse(JSON.stringify(res.data))
|
|
|
const rdata = JSON.parse(JSON.stringify(res.data))
|
|
|
const sidebarRoutes = filterAsyncRouter(sdata)
|
|
|
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
|
|
- const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
|
|
|
+ const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
|
|
|
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
|
|
|
- router.addRoutes(asyncRoutes);
|
|
|
+ router.addRoutes(asyncRoutes)
|
|
|
commit('SET_ROUTES', rewriteRoutes)
|
|
|
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
|
|
|
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
|
|
@@ -68,7 +68,7 @@ const permission = {
|
|
|
|
|
|
// 遍历后台传来的路由字符串,转换为组件对象
|
|
|
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
|
|
- return asyncRouterMap.filter(route => {
|
|
|
+ return asyncRouterMap.filter((route) => {
|
|
|
if (type && route.children) {
|
|
|
route.children = filterChildren(route.children)
|
|
|
}
|
|
@@ -99,7 +99,7 @@ function filterChildren(childrenMap, lastRouter = false) {
|
|
|
childrenMap.forEach((el, index) => {
|
|
|
if (el.children && el.children.length) {
|
|
|
if (el.component === 'ParentView' && !lastRouter) {
|
|
|
- el.children.forEach(c => {
|
|
|
+ el.children.forEach((c) => {
|
|
|
c.path = el.path + '/' + c.path
|
|
|
if (c.children && c.children.length) {
|
|
|
children = children.concat(filterChildren(c.children, c))
|
|
@@ -121,7 +121,7 @@ function filterChildren(childrenMap, lastRouter = false) {
|
|
|
// 动态路由遍历,验证是否具备权限
|
|
|
export function filterDynamicRoutes(routes) {
|
|
|
const res = []
|
|
|
- routes.forEach(route => {
|
|
|
+ routes.forEach((route) => {
|
|
|
if (route.permissions) {
|
|
|
if (auth.hasPermiOr(route.permissions)) {
|
|
|
res.push(route)
|