* fix:#731 (#749)
* 代码生成器样式调整
Co-authored-by: songkang1993 <38366752+songkang1993@users.noreply.github.com>
This commit is contained in:
奇淼(piexlmax
2021-09-29 19:04:21 +08:00
committed by GitHub
parent 5b7c1fb8fe
commit 01eb096920
8 changed files with 38 additions and 38 deletions
+23
View File
@@ -3,6 +3,7 @@ import { asyncRouterHandle } from '@/utils/asyncRouter'
import { asyncMenu } from '@/api/menu'
const routerList = []
const keepAliveRouters = []
const formatRouter = (routes) => {
routes && routes.forEach(item => {
@@ -16,11 +17,24 @@ const formatRouter = (routes) => {
})
}
const KeepAliveFilter = (routes) => {
routes && routes.forEach(item => {
// 子菜单中有 keep-alive 的,父菜单也必须 keep-alive,否则无效。这里将子菜单中有 keep-alive 的父菜单也加入。
if ((item.children && item.children.some(ch => ch.meta.keepAlive) || item.meta.keepAlive)) {
item.component().then(val => { keepAliveRouters.push(val.default.name) })
}
if (item.children && item.children.length > 0) {
KeepAliveFilter(item.children)
}
})
}
export const router = {
namespaced: true,
state: {
asyncRouters: [],
routerList: routerList,
keepAliveRouters: keepAliveRouters
},
mutations: {
setRouterList(state, routerList) {
@@ -29,6 +43,10 @@ export const router = {
// 设置动态路由
setAsyncRouter(state, asyncRouters) {
state.asyncRouters = asyncRouters
},
// 设置需要缓存的路由
setKeepAliveRouters(state, keepAliveRouters) {
state.keepAliveRouters = keepAliveRouters
}
},
actions: {
@@ -62,8 +80,10 @@ export const router = {
})
asyncRouterHandle(baseRouter)
KeepAliveFilter(asyncRouter)
commit('setAsyncRouter', baseRouter)
commit('setRouterList', routerList)
commit('setKeepAliveRouters', keepAliveRouters)
return true
}
},
@@ -74,6 +94,9 @@ export const router = {
},
routerList(state) {
return state.routerList
},
keepAliveRouters(state) {
return state.keepAliveRouters
}
}
}