diff --git a/yudao-ui-admin/src/store/modules/permission.js b/yudao-ui-admin/src/store/modules/permission.js index 4b53f7d8d..3316e945f 100644 --- a/yudao-ui-admin/src/store/modules/permission.js +++ b/yudao-ui-admin/src/store/modules/permission.js @@ -1,8 +1,8 @@ -import { constantRoutes } from '@/router' -import { getRouters } from '@/api/menu' +import {constantRoutes} from '@/router' +import {getRouters} from '@/api/menu' import Layout from '@/layout/index' import ParentView from '@/components/ParentView'; -import { toCamelCase } from "@/utils"; +import {toCamelCase} from "@/utils"; const permission = { state: { @@ -28,7 +28,7 @@ const permission = { }, actions: { // 生成路由 - GenerateRoutes({ commit }) { + GenerateRoutes({commit}) { return new Promise(resolve => { // 向后端请求路由数据(菜单) getRouters().then(res => { @@ -36,7 +36,7 @@ const permission = { const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据 const sidebarRoutes = filterAsyncRouter(sdata) const rewriteRoutes = filterAsyncRouter(rdata, false, true) - rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) + rewriteRoutes.push({path: '*', redirect: '/404', hidden: true}) commit('SET_ROUTES', rewriteRoutes) commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) commit('SET_DEFAULT_ROUTES', sidebarRoutes) @@ -60,6 +60,11 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { } // 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive route.name = toCamelCase(route.path, true) + // 处理三级及以上菜单路由缓存问题,将path名字赋值给name + if (route.path.indexOf("/") !== -1) { + var pathArr = route.path.split("/") + route.name = toCamelCase(pathArr[pathArr.length - 1], true) + } route.hidden = !route.visible // 处理 component 属性 if (route.children) { // 父节点 @@ -86,10 +91,10 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { } function filterChildren(childrenMap, lastRouter = false) { - let children = [] + var children = [] childrenMap.forEach((el, index) => { if (el.children && el.children.length) { - if (el.component === 'ParentView' && !lastRouter) { + if (!el.component && !lastRouter) { el.children.forEach(c => { c.path = el.path + '/' + c.path if (c.children && c.children.length) {