Commit 53dbf8d82e9fb539c21fc9b6ad3bdd49ca822e42
1 parent
44249e43
!290 修复三级及以上菜单路由缓存失效问题
Showing
1 changed file
with
12 additions
and
7 deletions
yudao-ui-admin/src/store/modules/permission.js
| 1 | -import { constantRoutes } from '@/router' | ||
| 2 | -import { getRouters } from '@/api/menu' | 1 | +import {constantRoutes} from '@/router' |
| 2 | +import {getRouters} from '@/api/menu' | ||
| 3 | import Layout from '@/layout/index' | 3 | import Layout from '@/layout/index' |
| 4 | import ParentView from '@/components/ParentView'; | 4 | import ParentView from '@/components/ParentView'; |
| 5 | -import { toCamelCase } from "@/utils"; | 5 | +import {toCamelCase} from "@/utils"; |
| 6 | 6 | ||
| 7 | const permission = { | 7 | const permission = { |
| 8 | state: { | 8 | state: { |
| @@ -28,7 +28,7 @@ const permission = { | @@ -28,7 +28,7 @@ const permission = { | ||
| 28 | }, | 28 | }, |
| 29 | actions: { | 29 | actions: { |
| 30 | // 生成路由 | 30 | // 生成路由 |
| 31 | - GenerateRoutes({ commit }) { | 31 | + GenerateRoutes({commit}) { |
| 32 | return new Promise(resolve => { | 32 | return new Promise(resolve => { |
| 33 | // 向后端请求路由数据(菜单) | 33 | // 向后端请求路由数据(菜单) |
| 34 | getRouters().then(res => { | 34 | getRouters().then(res => { |
| @@ -36,7 +36,7 @@ const permission = { | @@ -36,7 +36,7 @@ const permission = { | ||
| 36 | const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据 | 36 | const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据 |
| 37 | const sidebarRoutes = filterAsyncRouter(sdata) | 37 | const sidebarRoutes = filterAsyncRouter(sdata) |
| 38 | const rewriteRoutes = filterAsyncRouter(rdata, false, true) | 38 | const rewriteRoutes = filterAsyncRouter(rdata, false, true) |
| 39 | - rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) | 39 | + rewriteRoutes.push({path: '*', redirect: '/404', hidden: true}) |
| 40 | commit('SET_ROUTES', rewriteRoutes) | 40 | commit('SET_ROUTES', rewriteRoutes) |
| 41 | commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) | 41 | commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) |
| 42 | commit('SET_DEFAULT_ROUTES', sidebarRoutes) | 42 | commit('SET_DEFAULT_ROUTES', sidebarRoutes) |
| @@ -60,6 +60,11 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | @@ -60,6 +60,11 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | ||
| 60 | } | 60 | } |
| 61 | // 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive | 61 | // 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive |
| 62 | route.name = toCamelCase(route.path, true) | 62 | route.name = toCamelCase(route.path, true) |
| 63 | + // 处理三级及以上菜单路由缓存问题,将path名字赋值给name | ||
| 64 | + if (route.path.indexOf("/") !== -1) { | ||
| 65 | + var pathArr = route.path.split("/") | ||
| 66 | + route.name = toCamelCase(pathArr[pathArr.length - 1], true) | ||
| 67 | + } | ||
| 63 | route.hidden = !route.visible | 68 | route.hidden = !route.visible |
| 64 | // 处理 component 属性 | 69 | // 处理 component 属性 |
| 65 | if (route.children) { // 父节点 | 70 | if (route.children) { // 父节点 |
| @@ -86,10 +91,10 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | @@ -86,10 +91,10 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | ||
| 86 | } | 91 | } |
| 87 | 92 | ||
| 88 | function filterChildren(childrenMap, lastRouter = false) { | 93 | function filterChildren(childrenMap, lastRouter = false) { |
| 89 | - let children = [] | 94 | + var children = [] |
| 90 | childrenMap.forEach((el, index) => { | 95 | childrenMap.forEach((el, index) => { |
| 91 | if (el.children && el.children.length) { | 96 | if (el.children && el.children.length) { |
| 92 | - if (el.component === 'ParentView' && !lastRouter) { | 97 | + if (!el.component && !lastRouter) { |
| 93 | el.children.forEach(c => { | 98 | el.children.forEach(c => { |
| 94 | c.path = el.path + '/' + c.path | 99 | c.path = el.path + '/' + c.path |
| 95 | if (c.children && c.children.length) { | 100 | if (c.children && c.children.length) { |