feat: support keep-alive meta config (#470)

* feat: support keepalive meta config

* chore: remove console
This commit is contained in:
yuyang 2023-04-13 15:33:03 +08:00 committed by GitHub
parent 7642c320b3
commit 2123e86991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -221,6 +221,7 @@ export default [
component: '/form/step/index',
meta: {
title: '分步表单页',
keepAlive: false,
},
},
],

View File

@ -26,4 +26,7 @@ export interface RouteMeta {
hidden?: boolean;
hiddenBreadcrumb?: boolean;
single?: boolean;
keepAlive?: boolean;
frameSrc?: string;
frameBlank?: boolean;
}

View File

@ -10,6 +10,8 @@
</template>
<script setup lang="ts">
import isBoolean from 'lodash/isBoolean';
import isUndefined from 'lodash/isUndefined';
import type { ComputedRef } from 'vue';
import { computed } from 'vue';
@ -31,8 +33,13 @@ import { useTabsRouterStore } from '@/store';
const aliveViews = computed(() => {
const tabsRouterStore = useTabsRouterStore();
const { tabRouters } = tabsRouterStore;
return tabRouters.filter((route) => route.isAlive).map((route) => route.name);
return tabRouters
.filter((route) => {
const keepAliveConfig = route.meta?.keepAlive;
const isRouteKeepAlive = isUndefined(keepAliveConfig) || (isBoolean(keepAliveConfig) && keepAliveConfig); // keepalive
return route.isAlive && isRouteKeepAlive;
})
.map((route) => route.name);
}) as ComputedRef<string[]>;
const isRefreshing = computed(() => {