From 7a6807c73608156c2999138b4253e47d75d4c4bd Mon Sep 17 00:00:00 2001 From: scarqin <1054139596@qq.com> Date: Wed, 10 Aug 2022 20:09:36 +0800 Subject: [PATCH] fix: new tab but no select newest --- .../pages/api/tab/api-tab-operate.service.ts | 20 ++++++++++--------- .../app/pages/api/tab/api-tab.component.ts | 9 +++------ .../app/pages/api/test/api-test.component.ts | 1 - 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/workbench/browser/src/app/pages/api/tab/api-tab-operate.service.ts b/src/workbench/browser/src/app/pages/api/tab/api-tab-operate.service.ts index b9bc4d8d..6e57464b 100644 --- a/src/workbench/browser/src/app/pages/api/tab/api-tab-operate.service.ts +++ b/src/workbench/browser/src/app/pages/api/tab/api-tab-operate.service.ts @@ -26,15 +26,14 @@ export class ApiTabOperateService { private router: Router, private message: EoMessageService, private modal: ModalService - ) { - } + ) {} //Init tab info //Maybe from tab cache info or router url init(BASIC_TABS) { this.BASIC_TABS = BASIC_TABS; const tabCache = this.tabStorage.getPersistenceStorage(); if (tabCache && tabCache.tabOrder?.length) { - this.tabStorage.tabOrder = tabCache.tabOrder; + this.tabStorage.tabOrder = tabCache.tabOrder.filter((uuid) => tabCache.tabsByID.hasOwnProperty(uuid)); const tabsByID = new Map(); Object.values(tabCache.tabsByID).forEach((tabItem) => { tabsByID.set(tabItem.uuid, tabItem); @@ -144,8 +143,12 @@ export class ApiTabOperateService { * @param tab * @returns */ - getSameContentTabIndex(tab: TabItem): number { + getSameContentTabIndex(tab: TabItem): number { let result = -1; + const sameTabIDTab = this.tabStorage.tabsByID.get(tab.uuid); + if (sameTabIDTab && !sameTabIDTab.params.uuid && sameTabIDTab.pathname === tab.pathname) { + return this.tabStorage.tabOrder.findIndex((uuid) => uuid === sameTabIDTab.uuid); + } const mapObj = Object.fromEntries(this.tabStorage.tabsByID); for (const key in mapObj) { if (Object.prototype.hasOwnProperty.call(mapObj, key)) { @@ -203,7 +206,7 @@ export class ApiTabOperateService { const tmpTabItem = this.getBaiscTabFromUrl(res.url); const sameContentIndex = this.getSameContentTabIndex(tmpTabItem); const existTab = this.getTabByIndex(sameContentIndex); - // console.log('operateTabAfterRouteChange', existTab, tmpTabItem); + console.log('operateTabAfterRouteChange', existTab, tmpTabItem); //If page lack pageID //Jump to exist tab item to keep same pageID and so on if (!res.url.includes('pageID')) { @@ -222,8 +225,8 @@ export class ApiTabOperateService { //same tab content,selected it if (existTab) { - this.selectedIndex = sameContentIndex; - this.updateChildView(); + this.selectedIndex = sameContentIndex; + this.updateChildView(); return; } //If has same content tab (same {params.uuid}),replace it and merge data @@ -231,7 +234,7 @@ export class ApiTabOperateService { for (const key in mapObj) { if (Object.prototype.hasOwnProperty.call(mapObj, key)) { const tab = mapObj[key]; - if (tab.params.uuid === tmpTabItem.params.uuid) { + if (tab.params.uuid && tab.params.uuid === tmpTabItem.params.uuid) { const mergeTab = this.preventBlankTab(tab, tmpTabItem); mergeTab.content = tab.content; mergeTab.baseContent = tab.baseContent; @@ -314,5 +317,4 @@ export class ApiTabOperateService { private updateChildView() { this.messageService.send({ type: 'tabContentInit', data: {} }); } - } diff --git a/src/workbench/browser/src/app/pages/api/tab/api-tab.component.ts b/src/workbench/browser/src/app/pages/api/tab/api-tab.component.ts index f92ec42e..929087a2 100644 --- a/src/workbench/browser/src/app/pages/api/tab/api-tab.component.ts +++ b/src/workbench/browser/src/app/pages/api/tab/api-tab.component.ts @@ -119,13 +119,10 @@ export class ApiTabComponent implements OnInit, OnDestroy { getTabByUrl(url: string): TabItem | null { const tabItem = this.tabOperate.getBaiscTabFromUrl(url); const existTabIndex = this.tabOperate.getSameContentTabIndex(tabItem); - if (existTabIndex !== -1) { - return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]); + if (existTabIndex === -1) { + return null; } - if (!url.includes('uuid')) { - return this.tabStorage.tabsByID.get(tabItem.uuid) || null; - } - return null; + return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]); } getCurrentTab() { return this.tabOperate.getCurrentTab(); diff --git a/src/workbench/browser/src/app/pages/api/test/api-test.component.ts b/src/workbench/browser/src/app/pages/api/test/api-test.component.ts index ae5ae76e..56e57da0 100644 --- a/src/workbench/browser/src/app/pages/api/test/api-test.component.ts +++ b/src/workbench/browser/src/app/pages/api/test/api-test.component.ts @@ -386,7 +386,6 @@ export class ApiTestComponent implements OnInit, OnDestroy { */ private changeStatus(status) { this.status = status; - console.log('changeStatus',status); switch (status) { case 'testing': { this.setTestSecondsTimmer();