From 53dbf8d82e9fb539c21fc9b6ad3bdd49ca822e42 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 29 Nov 2022 22:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=81290=20=E4=BF=AE=E5=A4=8D=E4=B8=89?= =?UTF-8?q?=E7=BA=A7=E5=8F=8A=E4=BB=A5=E4=B8=8A=E8=8F=9C=E5=8D=95=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E7=BC=93=E5=AD=98=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/store/modules/permission.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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) {