Skip to content

Commit f50d7b3

Browse files
authored
feat: add keealive meta config (#242)
1 parent d0e0040 commit f50d7b3

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"nprogress": "^0.2.0",
2626
"qrcode.vue": "^1.7.0",
2727
"tdesign-icons-vue": "^0.1.6",
28-
"tdesign-vue": "^1.0.1",
28+
"tdesign-vue": "^1.3.0",
2929
"tvision-color": "~1.5.0",
3030
"typescript": "^4.2.4",
3131
"vue": "~2.6.14",

src/layouts/components/Content.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
</template>
88
<script lang="ts">
99
import { mapGetters } from 'vuex';
10+
import isBoolean from 'lodash/isBoolean';
11+
import isUndefined from 'lodash/isUndefined';
1012
1113
export default {
1214
computed: {
@@ -16,7 +18,13 @@ export default {
1618
isUseTabsRouter: 'setting/isUseTabsRouter',
1719
}),
1820
aliveViews() {
19-
return this.tabRouterList.filter((route) => route.isAlive).map((route) => route.name);
21+
return this.tabRouterList
22+
.filter((route) => {
23+
const keepAliveConfig = route.meta?.keepAlive;
24+
const isRouteKeepAlive = isUndefined(keepAliveConfig) || (isBoolean(keepAliveConfig) && keepAliveConfig); // 默认开启keepalive
25+
return route.isAlive && isRouteKeepAlive;
26+
})
27+
.map((route) => route.name);
2028
},
2129
},
2230
};

src/pages/dashboard/base/index.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<template>
22
<div>
3+
<t-back-top
4+
container=".tdesign-starter-layout"
5+
:visible-height="0"
6+
style="position: absolute"
7+
:offset="['24px', '80px']"
8+
>
9+
<t-icon name="backtop" size="20px" />
10+
</t-back-top>
311
<!-- 顶部 card -->
412
<top-panel class="row-container" />
513
<!-- 中部图表 -->

src/store/modules/tab-router.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ const state: TTabRouterType = {
2727
isRefreshing: false,
2828
};
2929

30-
// 不需要做多标签tabs页缓存的列表 值为每个页面对应的name 如 DashboardDetail
31-
// const ignoreCacheRoutes = ['DashboardDetail'];
32-
const ignoreCacheRoutes = [];
33-
3430
const mutations = {
3531
// 处理刷新
3632
toggleTabRouterAlive(state: TTabRouterType, routeIdx: number) {
@@ -39,10 +35,9 @@ const mutations = {
3935
},
4036
// 处理新增
4137
appendTabRouterList(state: TTabRouterType, newRoute: TRouterInfo) {
42-
const needAlive = !ignoreCacheRoutes.includes(newRoute.name);
4338
if (!state.tabRouterList.find((route: TRouterInfo) => route.path === newRoute.path))
4439
// eslint-disable-next-line no-param-reassign
45-
state.tabRouterList = state.tabRouterList.concat({ ...newRoute, isAlive: needAlive });
40+
state.tabRouterList = state.tabRouterList.concat({ ...newRoute, isAlive: true });
4641
},
4742
// 处理关闭当前
4843
subtractCurrentTabRouter(state: TTabRouterType, newRoute: TRouterInfo) {

0 commit comments

Comments
 (0)