Skip to content

Commit

Permalink
fix: tab extends deep copy error
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Sep 6, 2022
1 parent 51b79b5 commit 4ea5a20
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/workbench/browser/src/app/pages/api/api-tab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export class ApiTabService {
replaceTab.isFixed = true;
}
}
// console.log('updatePartialTab', inData, currentTab, replaceTab);
this.apiTabComponent.updatePartialTab(inData.url, replaceTab);
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MessageService } from 'eo/workbench/browser/src/app/shared/services/mes
import { EoMessageService } from 'eo/workbench/browser/src/app/eoui/message/eo-message.service';
import { ModalService } from 'eo/workbench/browser/src/app/shared/services/modal.service';
import { debug } from 'console';
import { eoDeepCopy } from 'eo/workbench/browser/src/app/utils';
/**
* Api tab service operate tabs array add/replace/close...
* Tab change by url change(router event)
Expand Down Expand Up @@ -58,10 +59,12 @@ export class ApiTabOperateService {
* @returns tabItem
*/
newDefaultTab() {
const tabItem: TabItem = this.getBaiscTabFromUrl(this.BASIC_TABS[0].pathname);
const tabItem = Object.assign({}, eoDeepCopy(this.BASIC_TABS[0]));
tabItem.params = {};
tabItem.uuid = tabItem.params.pageID = Date.now();
Object.assign(tabItem, { isLoading: false });
this.tabStorage.addTab(tabItem);
this.navigateTabRoute(tabItem);
this.navigateTabRoute(tabItem as TabItem);
}

closeTab(index: number) {
Expand Down Expand Up @@ -132,7 +135,7 @@ export class ApiTabOperateService {
* @param url
* @returns tabInfo
*/
getTabInfoFromUrl(url): { uuid: number; pathname: string; params: any } {
getBasicInfoFromUrl(url): { uuid: number; pathname: string; params: any } {
const urlArr = url.split('?');
const params: any = {};
const basicTab = this.BASIC_TABS.find((val) => urlArr[0].includes(val.pathname));
Expand Down Expand Up @@ -160,9 +163,9 @@ export class ApiTabOperateService {
* @param url
* @returns tabInfo
*/
getBaiscTabFromUrl(url): TabItem {
const result = this.getTabInfoFromUrl(url);
const basicTab = this.BASIC_TABS.find((val) => result.pathname === val.pathname);
generateTabFromUrl(url): TabItem {
const result = this.getBasicInfoFromUrl(url);
const basicTab = eoDeepCopy(this.BASIC_TABS.find((val) => result.pathname === val.pathname));
if (!basicTab) {
throw new Error(`EO_ERROR: Please check this router has added in BASIC_TABS,current route:${url}`);
}
Expand All @@ -178,8 +181,8 @@ export class ApiTabOperateService {
* @param res.url location.pathname+location.search
*/
operateTabAfterRouteChange(res: { url: string }) {
const pureTab = this.getTabInfoFromUrl(res.url);
const nextTab = this.getBaiscTabFromUrl(res.url);
const pureTab = this.getBasicInfoFromUrl(res.url);
const nextTab = this.generateTabFromUrl(res.url);
const existTab = this.getSameContentTab(pureTab);
//!Every tab must has pageID
//If lack pageID,Jump to exist tab item to keep same pageID and so on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ApiTabComponent implements OnInit, OnDestroy {
* @returns
*/
getExistTabByUrl(url: string): TabItem | null {
const existTab = this.tabOperate.getSameContentTab(this.tabOperate.getTabInfoFromUrl(url));
const existTab = this.tabOperate.getSameContentTab(this.tabOperate.getBasicInfoFromUrl(url));
if (!existTab) {
return null;
}
Expand Down Expand Up @@ -148,8 +148,6 @@ export class ApiTabComponent implements OnInit, OnDestroy {
extends: Object.assign({}, existTab.extends, tabItem.extends),
})
);
//! Prevent rendering delay
// this.cdRef.detectChanges();
}
/**
* Cache tab header/tabs content for restore when page close or component destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,9 @@ export class ApiTestComponent implements OnInit, OnDestroy {
this.modelChange.emit(this.model);
}
ngOnInit(): void {
console.log('ngOnInit');
this.watchEnvChange();
}
ngOnDestroy() {
console.log('ngOnDestroy');
this.destroy$.next();
this.destroy$.complete();
this.testServer.close();
Expand Down

0 comments on commit 4ea5a20

Please sign in to comment.