From 2ba30beddf15c829ad51a8cd244b3fec415241cb Mon Sep 17 00:00:00 2001 From: dingjiahuichina Date: Thu, 11 Dec 2025 08:16:33 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DHome=E9=A1=B5=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E8=B7=B3=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/dev-store.spec | 4 ++- frontend/src/layout/index.vue | 28 ++++++++++--------- frontend/src/stores/tabStore.ts | 12 +++++--- frontend/src/utils/index.ts | 2 +- frontend/src/views/Home.vue | 15 ++++++++-- frontend/src/views/components/GridDisplay.vue | 13 +++++---- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/build/dev-store.spec b/build/dev-store.spec index 22b4a89..f4503a3 100644 --- a/build/dev-store.spec +++ b/build/dev-store.spec @@ -1,7 +1,7 @@ %global debug_package %{nil} Name: dev-store -Version: 1.0.5 +Version: 1.0.6 Release: 1 Summary: Development Store Management System @@ -304,6 +304,8 @@ if [ $1 -eq 0 ]; then fi %changelog +* Thu Dec 11 2025 dingjiahui - 1.0.6-1 +- Fix the issue where clicking a component button incorrectly navigates to the Home page. * Tue Dec 9 2025 dingjiahui - 1.0.5-1 - Optimize the processing logic for parsing MCP READMEs * Wed Dec 3 2025 dingjiahui - 1.0.4-1 diff --git a/frontend/src/layout/index.vue b/frontend/src/layout/index.vue index d3a13fd..074fe67 100644 --- a/frontend/src/layout/index.vue +++ b/frontend/src/layout/index.vue @@ -117,13 +117,13 @@ const updateTime = ref('2025'); // 页签管理 const { tabs, activeTabId, addTab, removeTab, setActiveTab, updateCurrentTab, updateCurrentTabId, updateTabTitle, reorderTabs, findHomeTab } = useTabStore(); -// 计算keep-alive的key:Home页使用固定key,Detail页使用path +// 计算keep-alive的key:基于route const keepAliveKey = computed(() => { - if (route.name === 'Home') { - // Home组件使用固定key,但内部通过页签ID管理不同状态 + if (route.path === '/') { + // Home页使用固定key return 'home'; } - // Detail页使用path,确保不同的detail有独立的缓存 + // Detail页使用path作为key return route.path; }); @@ -196,12 +196,13 @@ watch(() => route.fullPath, () => { // 根据路由类型更新ID和标题 if (route.path === '/') { - // Home页 - 只更新路由信息和标题,不改变页签ID - // Home页签的ID由toHomePage方法或初始化时确定 - updateCurrentTab({ path: route.path, query: route.query }); - updateTabTitle(activeTabId.value, 'Home'); + // Home页 - 只在当前活动页签是Home页签时才更新 + if (currentTabId === 'home') { + updateCurrentTab({ path: route.path, query: route.query }); + updateTabTitle(activeTabId.value, 'Home'); + } } else if (route.name === 'McpServerDetail' || route.name === 'OedpPluginDetail') { - // Detail页面 - 只有当页签ID匹配时才更新路由信息 + // Detail页面 // 从路径中提取 tag 和 key const pathParts = route.path.split('/').filter(p => p); if (pathParts.length >= 2) { @@ -209,10 +210,11 @@ watch(() => route.fullPath, () => { const key = pathParts[1]; const expectedTabId = `${tag}-${key}`; - // 只有当前页签ID匹配时才更新路由信息 - if (currentTabId === expectedTabId) { - updateCurrentTab({ path: route.path, query: route.query }); - } + // 激活对应的页签 + setActiveTab(expectedTabId); + + // 更新路由信息 + updateCurrentTab({ path: route.path, query: route.query }); } } }, { immediate: true }); diff --git a/frontend/src/stores/tabStore.ts b/frontend/src/stores/tabStore.ts index 612d927..93159a2 100644 --- a/frontend/src/stores/tabStore.ts +++ b/frontend/src/stores/tabStore.ts @@ -36,15 +36,19 @@ const tabStore = reactive({ }); export function useTabStore() { - const addTab = (tab: Tab) => { + const addTab = (tab: Tab, activate: boolean = true) => { const existingTab = tabStore.tabs.find(t => t.id === tab.id); if (existingTab) { - // 如果页签已存在,切换到该页签 - tabStore.activeTabId = tab.id; + // 如果页签已存在,根据activate参数决定是否切换 + if (activate) { + tabStore.activeTabId = tab.id; + } } else { // 否则新增页签 tabStore.tabs.push(tab); - tabStore.activeTabId = tab.id; + if (activate) { + tabStore.activeTabId = tab.id; + } } }; diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index efeed30..a7d7885 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -49,7 +49,7 @@ export async function updateRouteQuery( } }); - await router.push({ query: newQuery }); + await router.push({ path: route.path, query: newQuery }); } /** diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index c2e32a1..5c46ad5 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -313,6 +313,9 @@ const handleSortTabChange = async () => { watch( () => route.query.tag, (nv) => { + // 只在当前路由是 Home 页时才处理 + if (route.path !== '/') return; + const state = getCurrentState(); if (nv) { // 更新激活的 Tab @@ -321,7 +324,7 @@ watch( // 重新获取数据 } else { // 如果 URL 中没有 type 参数,跳转到默认值 - router.replace({ query: { ...route.query, tag: 'mcp' } }); + router.replace({ path: route.path, query: { ...route.query, tag: 'mcp' } }); } }, { immediate: true } @@ -352,12 +355,17 @@ const stopPolling = () => { // 监听同步成功事件的处理函数 const handleSyncSuccess = async () => { + // 只在当前路由是 Home 页时才刷新数据 + if (route.path !== '/') return; // 立即刷新数据 await getAndCheck(); }; // 初始化状态和URL参数的公共函数 const initializeStateAndUrl = () => { + // 只在当前路由是 Home 页时才处理 + if (route.path !== '/') return; + // 初始化当前页签的状态 const tabId = currentTabId.value; if (!homeStatesMap.has(tabId)) { @@ -405,7 +413,7 @@ const initializeStateAndUrl = () => { } if (needsUpdate) { - router.replace({ query: currentQuery }); + router.replace({ path: route.path, query: currentQuery }); } }; @@ -426,6 +434,9 @@ onMounted(async () => { // 组件被激活(显示)时 - keep-alive onActivated(() => { + // 只在当前路由是 Home 页时才处理 + if (route.path !== '/') return; + // 同步路由状态 initializeStateAndUrl(); diff --git a/frontend/src/views/components/GridDisplay.vue b/frontend/src/views/components/GridDisplay.vue index ce6c0f5..9ef5024 100644 --- a/frontend/src/views/components/GridDisplay.vue +++ b/frontend/src/views/components/GridDisplay.vue @@ -88,19 +88,20 @@ const props = withDefaults( ); // 跳转至详情页 tag, key - 新增页签 -const goToDetail = (key: string) => { +const goToDetail = async (key: string) => { const item = props.itemList.find((i: any) => i.key === key); const detailPath = `/${props.tag}/${key}`; + const tabId = `${props.tag}-${key}`; - // 添加新页签 + // 先添加页签(不激活) addTab({ - id: `${props.tag}-${key}`, + id: tabId, title: item?.name || key, route: { path: detailPath } - }); + }, false); - // 跳转到详情页 - router.push(detailPath); + // 然后跳转到详情页 + await router.push(detailPath); }; -- Gitee