!290 修复三级及以上菜单路由缓存失效问题
This commit is contained in:
parent
44249e43dd
commit
53dbf8d82e
@ -1,8 +1,8 @@
|
|||||||
import { constantRoutes } from '@/router'
|
import {constantRoutes} from '@/router'
|
||||||
import { getRouters } from '@/api/menu'
|
import {getRouters} from '@/api/menu'
|
||||||
import Layout from '@/layout/index'
|
import Layout from '@/layout/index'
|
||||||
import ParentView from '@/components/ParentView';
|
import ParentView from '@/components/ParentView';
|
||||||
import { toCamelCase } from "@/utils";
|
import {toCamelCase} from "@/utils";
|
||||||
|
|
||||||
const permission = {
|
const permission = {
|
||||||
state: {
|
state: {
|
||||||
@ -28,7 +28,7 @@ const permission = {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// 生成路由
|
// 生成路由
|
||||||
GenerateRoutes({ commit }) {
|
GenerateRoutes({commit}) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
// 向后端请求路由数据(菜单)
|
// 向后端请求路由数据(菜单)
|
||||||
getRouters().then(res => {
|
getRouters().then(res => {
|
||||||
@ -36,7 +36,7 @@ const permission = {
|
|||||||
const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据
|
const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据
|
||||||
const sidebarRoutes = filterAsyncRouter(sdata)
|
const sidebarRoutes = filterAsyncRouter(sdata)
|
||||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
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_ROUTES', rewriteRoutes)
|
||||||
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
|
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
|
||||||
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
|
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
|
||||||
@ -60,6 +60,11 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
|||||||
}
|
}
|
||||||
// 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive
|
// 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive
|
||||||
route.name = toCamelCase(route.path, true)
|
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
|
route.hidden = !route.visible
|
||||||
// 处理 component 属性
|
// 处理 component 属性
|
||||||
if (route.children) { // 父节点
|
if (route.children) { // 父节点
|
||||||
@ -86,10 +91,10 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function filterChildren(childrenMap, lastRouter = false) {
|
function filterChildren(childrenMap, lastRouter = false) {
|
||||||
let children = []
|
var children = []
|
||||||
childrenMap.forEach((el, index) => {
|
childrenMap.forEach((el, index) => {
|
||||||
if (el.children && el.children.length) {
|
if (el.children && el.children.length) {
|
||||||
if (el.component === 'ParentView' && !lastRouter) {
|
if (!el.component && !lastRouter) {
|
||||||
el.children.forEach(c => {
|
el.children.forEach(c => {
|
||||||
c.path = el.path + '/' + c.path
|
c.path = el.path + '/' + c.path
|
||||||
if (c.children && c.children.length) {
|
if (c.children && c.children.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user