fix: new tab but no select newest

This commit is contained in:
scarqin 2022-08-10 20:09:36 +08:00
parent b7dcea772f
commit 7a6807c736
3 changed files with 14 additions and 16 deletions

View File

@ -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: {} });
}
}

View File

@ -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();

View File

@ -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();