fix(router): 修复路由keep-alive逻辑并添加组件名称
This commit is contained in:
@@ -52,14 +52,32 @@ export const useRouterStore = defineStore('router', () => {
|
|||||||
const asyncRouterFlag = ref(0)
|
const asyncRouterFlag = ref(0)
|
||||||
const setKeepAliveRouters = (history) => {
|
const setKeepAliveRouters = (history) => {
|
||||||
const keepArrTemp = []
|
const keepArrTemp = []
|
||||||
|
|
||||||
|
// 1. 首先添加原有的keepAlive配置
|
||||||
|
keepArrTemp.push(...keepAliveRoutersArr)
|
||||||
|
|
||||||
history.forEach((item) => {
|
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]) {
|
if (nameMap[item.name]) {
|
||||||
keepArrTemp.push(nameMap[item.name])
|
keepArrTemp.push(nameMap[item.name])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
keepAliveRouters.value = Array.from(new Set(keepArrTemp))
|
keepAliveRouters.value = Array.from(new Set(keepArrTemp))
|
||||||
|
console.log(keepAliveRouters.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
emitter.on('setKeepAlive', setKeepAliveRouters)
|
emitter.on('setKeepAlive', setKeepAliveRouters)
|
||||||
|
@@ -83,6 +83,10 @@ import { ref, reactive } from 'vue'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { mcp } from '@/api/autoCode'
|
import { mcp } from '@/api/autoCode'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'MCP'
|
||||||
|
})
|
||||||
|
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
|
@@ -139,6 +139,11 @@ import { ElMessage } from 'element-plus'
|
|||||||
import { VideoPlay, DocumentCopy } from '@element-plus/icons-vue' // Added DocumentCopy
|
import { VideoPlay, DocumentCopy } from '@element-plus/icons-vue' // Added DocumentCopy
|
||||||
import { mcpList, mcpTest } from '@/api/autoCode'
|
import { mcpList, mcpTest } from '@/api/autoCode'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'MCPTest'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
const mcpTools = ref([])
|
const mcpTools = ref([])
|
||||||
const testDialogVisible = ref(false)
|
const testDialogVisible = ref(false)
|
||||||
const currentTestingTool = ref(null)
|
const currentTestingTool = ref(null)
|
||||||
|
Reference in New Issue
Block a user