fix(router): 修复路由keep-alive逻辑并添加组件名称

This commit is contained in:
piexlMax(奇淼
2025-07-10 14:52:59 +08:00
parent 2ec2e9a66e
commit 72ee8fb6fc
3 changed files with 27 additions and 0 deletions

View File

@@ -52,14 +52,32 @@ export const useRouterStore = defineStore('router', () => {
const asyncRouterFlag = ref(0)
const setKeepAliveRouters = (history) => {
const keepArrTemp = []
// 1. 首先添加原有的keepAlive配置
keepArrTemp.push(...keepAliveRoutersArr)
history.forEach((item) => {
// 2. 为所有history中的路由强制启用keep-alive
// 通过routeMap获取路由信息然后通过pathInfo获取组件名
const routeInfo = routeMap[item.name]
if (routeInfo && routeInfo.meta && routeInfo.meta.path) {
const componentName = pathInfo[routeInfo.meta.path]
if (componentName) {
keepArrTemp.push(componentName)
}
}
// 3. 如果子路由在tabs中打开父路由也需要keepAlive
if (nameMap[item.name]) {
keepArrTemp.push(nameMap[item.name])
}
})
keepAliveRouters.value = Array.from(new Set(keepArrTemp))
console.log(keepAliveRouters.value)
}
const route = useRoute()
emitter.on('setKeepAlive', setKeepAliveRouters)

View File

@@ -83,6 +83,10 @@ import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { mcp } from '@/api/autoCode'
defineOptions({
name: 'MCP'
})
const formRef = ref(null)
const form = reactive({
name: '',

View File

@@ -139,6 +139,11 @@ import { ElMessage } from 'element-plus'
import { VideoPlay, DocumentCopy } from '@element-plus/icons-vue' // Added DocumentCopy
import { mcpList, mcpTest } from '@/api/autoCode'
defineOptions({
name: 'MCPTest'
})
const mcpTools = ref([])
const testDialogVisible = ref(false)
const currentTestingTool = ref(null)