From 0db8c9b94a9ac655549d5eba5c2a6c92ac386c06 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 08 十月 2026 11:20:56 +0800
Subject: [PATCH] 提交最新代码
---
culture/src/layouts/components/AppContent.vue | 44 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/culture/src/layouts/components/AppContent.vue b/culture/src/layouts/components/AppContent.vue
index 62372dc..45abca8 100644
--- a/culture/src/layouts/components/AppContent.vue
+++ b/culture/src/layouts/components/AppContent.vue
@@ -1,8 +1,9 @@
<template>
<div @click="foldFun" style="height: 100%;">
- <keep-alive :include="keepAliveList">
- <router-view />
+ <keep-alive ref="keepAlive">
+ <router-view v-if="shouldCacheView" :key="routeCacheKey" />
</keep-alive>
+ <router-view v-if="!shouldCacheView" :key="$route.fullPath" />
</div>
</template>
@@ -15,9 +16,46 @@
}
},
computed: {
- ...mapState(['keepAliveList'])
+ ...mapState(['tagList', 'cachePruneRequest']),
+ activeTag() {
+ return this.tagList.find(tag => {
+ const fullPath = tag.fullPath || this.$router.resolve({
+ path: tag.path,
+ query: tag.query || {}
+ }).route.fullPath
+ return fullPath === this.$route.fullPath
+ })
+ },
+ shouldCacheView() {
+ return Boolean(this.$route.meta.keepAlive || this.$route.meta.hide)
+ },
+ routeCacheKey() {
+ return this.activeTag && this.activeTag.cacheKey
+ ? this.activeTag.cacheKey
+ : (this.$route.query._view || this.$route.fullPath)
+ }
+ },
+ watch: {
+ cachePruneRequest(request) {
+ if (request && request.keys) {
+ request.keys.forEach(key => this.pruneCacheEntry(key))
+ }
+ }
},
methods: {
+ pruneCacheEntry(key) {
+ const keepAlive = this.$refs.keepAlive
+ if (!keepAlive || !keepAlive.cache || !keepAlive.keys) return
+
+ const cached = keepAlive.cache[key]
+ if (cached && cached.componentInstance) {
+ cached.componentInstance.$destroy()
+ }
+ keepAlive.cache[key] = null
+
+ const index = keepAlive.keys.indexOf(key)
+ if (index > -1) keepAlive.keys.splice(index, 1)
+ },
foldFun() {
if (window.innerWidth < 1000) {
this.$store.commit('SET_ISFOLD', true)
--
Gitblit v1.7.1