Skip to content

Commit 72ee8fb

Browse files
author
piexlMax(奇淼
committed
fix(router): 修复路由keep-alive逻辑并添加组件名称
1 parent 2ec2e9a commit 72ee8fb

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

web/src/pinia/modules/router.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,32 @@ export const useRouterStore = defineStore('router', () => {
5252
const asyncRouterFlag = ref(0)
5353
const setKeepAliveRouters = (history) => {
5454
const keepArrTemp = []
55+
56+
// 1. 首先添加原有的keepAlive配置
57+
keepArrTemp.push(...keepAliveRoutersArr)
58+
5559
history.forEach((item) => {
60+
// 2. 为所有history中的路由强制启用keep-alive
61+
// 通过routeMap获取路由信息,然后通过pathInfo获取组件名
62+
const routeInfo = routeMap[item.name]
63+
if (routeInfo && routeInfo.meta && routeInfo.meta.path) {
64+
const componentName = pathInfo[routeInfo.meta.path]
65+
if (componentName) {
66+
keepArrTemp.push(componentName)
67+
}
68+
}
69+
70+
// 3. 如果子路由在tabs中打开,父路由也需要keepAlive
5671
if (nameMap[item.name]) {
5772
keepArrTemp.push(nameMap[item.name])
5873
}
5974
})
75+
6076
keepAliveRouters.value = Array.from(new Set(keepArrTemp))
77+
console.log(keepAliveRouters.value)
6178
}
6279

80+
6381
const route = useRoute()
6482

6583
emitter.on('setKeepAlive', setKeepAliveRouters)

web/src/view/systemTools/autoCode/mcp.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ import { ref, reactive } from 'vue'
8383
import { ElMessage } from 'element-plus'
8484
import { mcp } from '@/api/autoCode'
8585
86+
defineOptions({
87+
name: 'MCP'
88+
})
89+
8690
const formRef = ref(null)
8791
const form = reactive({
8892
name: '',

web/src/view/systemTools/autoCode/mcpTest.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ import { ElMessage } from 'element-plus'
139139
import { VideoPlay, DocumentCopy } from '@element-plus/icons-vue' // Added DocumentCopy
140140
import { mcpList, mcpTest } from '@/api/autoCode'
141141
142+
defineOptions({
143+
name: 'MCPTest'
144+
})
145+
146+
142147
const mcpTools = ref([])
143148
const testDialogVisible = ref(false)
144149
const currentTestingTool = ref(null)

0 commit comments

Comments
 (0)