diff --git a/frontend/src/store.ts b/frontend/src/store.ts index 0833ae2..e081769 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -736,6 +736,18 @@ export const useStore = create()( return { tabs: newTabs, activeTabId: existingTab.id }; } } + // 语义去重:对 query 类型按 savedQueryId 匹配已有 Tab(避免保存后重复打开) + if (tab.type === 'query' && tab.savedQueryId) { + const savedQueryIndex = state.tabs.findIndex(t => + t.type === 'query' && (t.savedQueryId === tab.savedQueryId || t.id === tab.savedQueryId) + ); + if (savedQueryIndex !== -1) { + const existingTab = state.tabs[savedQueryIndex]; + const newTabs = [...state.tabs]; + newTabs[savedQueryIndex] = { ...existingTab, ...tab, id: existingTab.id }; + return { tabs: newTabs, activeTabId: existingTab.id }; + } + } return { tabs: [...state.tabs, tab], activeTabId: tab.id }; }),