From ff0e1dcd27295a9cd2eb99a828c9f367aee583e9 Mon Sep 17 00:00:00 2001 From: liuyun Date: Sun, 11 Oct 2026 22:13:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(layout):=20=E5=A4=9A=E9=A1=B5=E7=AD=BE=20k?= =?UTF-8?q?eep-alive=EF=BC=88=E9=BB=98=E8=AE=A4=E7=BC=93=E5=AD=98=EF=BC=8C?= =?UTF-8?q?meta.keepAlive:false=20=E5=8F=AF=E5=85=B3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 11 个菜单页面补 defineOptions name(缓存标识) - tabs store 加 keepAlive 字段 + pathToName 辅助 - layout 用 keep-alive 包裹 router-view,按打开且未关闭缓存的页签缓存 Co-Authored-By: Claude Opus 4.8 --- components.d.ts | 2 ++ src/layouts/default.vue | 13 ++++++++++--- src/pages/index.vue | 2 ++ src/pages/monitor/audit/index.vue | 2 ++ src/pages/monitor/login-log/index.vue | 2 ++ src/pages/monitor/session/index.vue | 2 ++ src/pages/system/config/index.vue | 2 ++ src/pages/system/dict/index.vue | 2 ++ src/pages/system/org/index.vue | 2 ++ src/pages/system/resource/index.vue | 2 ++ src/pages/system/role/index.vue | 2 ++ src/pages/system/tenant/index.vue | 2 ++ src/pages/system/user/index.vue | 2 ++ src/stores/modules/tabs.ts | 9 ++++++++- 14 files changed, 42 insertions(+), 4 deletions(-) diff --git a/components.d.ts b/components.d.ts index 3b15375..316f41e 100644 --- a/components.d.ts +++ b/components.d.ts @@ -38,6 +38,7 @@ declare module 'vue' { ElPagination: typeof import('element-plus/es')['ElPagination'] ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] + ElResult: typeof import('element-plus/es')['ElResult'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSlider: typeof import('element-plus/es')['ElSlider'] @@ -98,6 +99,7 @@ declare global { const ElPagination: typeof import('element-plus/es')['ElPagination'] const ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] const ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] + const ElResult: typeof import('element-plus/es')['ElResult'] const ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] const ElSelect: typeof import('element-plus/es')['ElSelect'] const ElSlider: typeof import('element-plus/es')['ElSlider'] diff --git a/src/layouts/default.vue b/src/layouts/default.vue index 5553c6d..08dee7e 100644 --- a/src/layouts/default.vue +++ b/src/layouts/default.vue @@ -57,7 +57,11 @@ @close-all="handleCloseAll" />
- + + + + +
@@ -72,7 +76,7 @@ import { computed, onMounted, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' import { ElMessage } from 'element-plus' import { useAppStore } from '@/stores/modules/app' -import { HOME_PATH, useTabsStore } from '@/stores/modules/tabs' +import { HOME_PATH, pathToName, useTabsStore } from '@/stores/modules/tabs' import { useAuthStore } from '@/stores/modules/auth' import { useMenuStore } from '@/stores/modules/menu' import { useDictStore } from '@/stores/modules/dict' @@ -110,6 +114,9 @@ onMounted(() => { const activePath = computed(() => route.path) +/** keep-alive 缓存的组件名集合:打开且未关闭缓存的页签(keepAlive !== false 以兼容旧持久化数据)。 */ +const cachedNames = computed(() => tabsStore.tabs.filter((t) => t.keepAlive !== false).map((t) => pathToName(t.path))) + /** 当前路由对应的顶级菜单(及其叶子)。 */ const activeTop = computed(() => { for (const m of menus.value) { @@ -297,7 +304,7 @@ watch( const top = activeTop.value const leaf = top?.children?.find((c) => (c.path ?? c.code) === p) const title = leaf?.name ?? top?.name ?? p - tabsStore.addTab({ path: p, title, closable: p !== '/' }) + tabsStore.addTab({ path: p, title, closable: p !== '/', keepAlive: route.meta.keepAlive !== false }) }, { immediate: true }, ) diff --git a/src/pages/index.vue b/src/pages/index.vue index 4b6b383..becd6e4 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -35,6 +35,8 @@