diff --git a/web/src/store/module/router.js b/web/src/store/module/router.js index e16f50df..156477c8 100644 --- a/web/src/store/module/router.js +++ b/web/src/store/module/router.js @@ -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 } } } diff --git a/web/src/view/dashboard/index.vue b/web/src/view/dashboard/index.vue index 13c11469..a0b089e0 100644 --- a/web/src/view/dashboard/index.vue +++ b/web/src/view/dashboard/index.vue @@ -96,6 +96,7 @@ import echartsLine from '@/view/dashboard/dashbordCharts/echartsLine.vue' import dashbordTable from '@/view/dashboard/dashbordTable/dashbordTable.vue' export default { + name: 'Dashboard', components: { echartsLine, dashbordTable diff --git a/web/src/view/example/index.vue b/web/src/view/example/index.vue index f0289660..16aaeead 100644 --- a/web/src/view/example/index.vue +++ b/web/src/view/example/index.vue @@ -1,17 +1,12 @@ diff --git a/web/src/view/layout/index.vue b/web/src/view/layout/index.vue index 4ac0bfbf..e20e653b 100644 --- a/web/src/view/layout/index.vue +++ b/web/src/view/layout/index.vue @@ -78,19 +78,13 @@ - + - + - - - - - - diff --git a/web/src/view/routerHolder.vue b/web/src/view/routerHolder.vue index bffeb30a..53d157c9 100644 --- a/web/src/view/routerHolder.vue +++ b/web/src/view/routerHolder.vue @@ -1,18 +1,13 @@ diff --git a/web/src/view/superAdmin/index.vue b/web/src/view/superAdmin/index.vue index eb33a579..dfe264fd 100644 --- a/web/src/view/superAdmin/index.vue +++ b/web/src/view/superAdmin/index.vue @@ -1,17 +1,12 @@ diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index a2ad6610..22c3a1c1 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -129,9 +129,8 @@ - id , created_at , updated_at , deleted_at 会自动生成请勿重复创建 -
+
预览代码 生成代码
@@ -454,4 +453,7 @@ export default { float: right; } } +.auto-btn-list{ + margin-top: 16px; +} diff --git a/web/src/view/systemTools/index.vue b/web/src/view/systemTools/index.vue index 16df741b..58e15e7c 100644 --- a/web/src/view/systemTools/index.vue +++ b/web/src/view/systemTools/index.vue @@ -1,17 +1,12 @@