diff --git a/src/workbench/browser/src/app/pages/api/api-tab.service.ts b/src/workbench/browser/src/app/pages/api/api-tab.service.ts index 987aa24ff..85e18511c 100644 --- a/src/workbench/browser/src/app/pages/api/api-tab.service.ts +++ b/src/workbench/browser/src/app/pages/api/api-tab.service.ts @@ -111,7 +111,6 @@ export class ApiTabService { return; } this.bindChildComponentChangeEvent(); - console.log('updatechildview'); //?Why should use getCurrentTab()? //Because maybe current tab has't finish init const currentTab = this.apiTabComponent.getTabByUrl(url); @@ -175,7 +174,7 @@ export class ApiTabService { replaceTab.isFixed = true; } //Has tested set fixed - if(currentTab.pathname === '/home/api/test'&&model.testStartTime!==undefined){ + if (currentTab.pathname === '/home/api/test' && model.testStartTime !== undefined) { replaceTab.isFixed = true; } @@ -199,7 +198,7 @@ export class ApiTabService { * * @param inData.url get component fit tab data */ - afterContentChanged(inData: { when: 'init' | 'editing' |'saved'; url: string; model: any }) { + afterContentChanged(inData: { when: 'init' | 'editing' | 'saved'; url: string; model: any }) { if (!this.apiTabComponent) { console.warn(`EO_WARNING:apiTabComponent hasn't init yet!`); return; @@ -211,4 +210,15 @@ export class ApiTabService { } this.updateTab(currentTab, inData); } + handleDataBeforeCache(tabsByID) { + Object.values(tabsByID).forEach((val: TabItem) => { + if (val.pathname === '/home/api/test'&&val.content?.test?.testResult) { + val.content.test.testResult = { + request: {}, + response: {}, + }; + } + }); + return tabsByID; + } } diff --git a/src/workbench/browser/src/app/pages/api/api.component.html b/src/workbench/browser/src/app/pages/api/api.component.html index 0ab588116..aafee8ff6 100644 --- a/src/workbench/browser/src/app/pages/api/api.component.html +++ b/src/workbench/browser/src/app/pages/api/api.component.html @@ -29,7 +29,7 @@
- +
{ return new Promise((resolve) => { this.storage.run('apiDataLoad', [uuid], (result: StorageRes) => { if (result.status === StorageResStatus.success) { resolve(result.data); + } else { + this.message.error(`Can't find this api`); } }); }); 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 7e2890fca..7b32edf9a 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 @@ -27,7 +27,6 @@ export class ApiTabOperateService { private message: EoMessageService, private modal: ModalService ) { - this.watchPageLeave(); } //Init tab info //Maybe from tab cache info or router url @@ -223,8 +222,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 @@ -315,10 +314,5 @@ export class ApiTabOperateService { private updateChildView() { this.messageService.send({ type: 'tabContentInit', data: {} }); } - private watchPageLeave() { - const that = this; - window.addEventListener('beforeunload', function(e) { - that.tabStorage.setPersistenceStorage(that.selectedIndex); - }); - } + } diff --git a/src/workbench/browser/src/app/pages/api/tab/api-tab-storage.service.ts b/src/workbench/browser/src/app/pages/api/tab/api-tab-storage.service.ts index b39bca966..236df8ddb 100644 --- a/src/workbench/browser/src/app/pages/api/tab/api-tab-storage.service.ts +++ b/src/workbench/browser/src/app/pages/api/tab/api-tab-storage.service.ts @@ -46,15 +46,18 @@ export class ApiTabStorageService { * @param tab * @param data */ - setPersistenceStorage(selectedIndex) { - const tabsByID = Object.fromEntries(this.tabsByID); + setPersistenceStorage(selectedIndex, opts) { + let tabsByID = Object.fromEntries(this.tabsByID); Object.values(tabsByID).forEach((val) => { if (!val.hasChanged) { ['baseContent', 'content'].forEach((keyName) => { - val[keyName]=null; + val[keyName] = null; }); } }); + if (opts.handleDataBeforeCache) { + tabsByID = opts.handleDataBeforeCache(tabsByID); + } window.localStorage.setItem( this.cacheName, JSON.stringify({ 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 0be582429..0544b4184 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 @@ -13,6 +13,7 @@ import { KeyValue } from '@angular/common'; }) export class ApiTabComponent implements OnInit, OnDestroy { @Input() list; + @Input() handleDataBeforeCache; @Output() beforeClose = new EventEmitter(); MAX_TAB_LIMIT = 15; routerSubscribe: Subscription; @@ -27,6 +28,7 @@ export class ApiTabComponent implements OnInit, OnDestroy { ngOnInit(): void { this.tabOperate.init(this.list); this.watchRouterChange(); + this.watchPageLeave(); } newTab() { if (this.tabStorage.tabOrder.length >= this.MAX_TAB_LIMIT) { @@ -93,12 +95,12 @@ export class ApiTabComponent implements OnInit, OnDestroy { } tabs.push({ uuid: tab.uuid, - type:tab.type, + type: tab.type, title: tab.title, pathname: tab.pathname, params: tab.params, - isFixed:tab.isFixed, - hasChanged: tab.hasChanged + isFixed: tab.isFixed, + hasChanged: tab.hasChanged, }); }); return tabs; @@ -117,10 +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 null; + if (existTabIndex !== -1) { + return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]); } - return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]); + return this.tabStorage.tabsByID.get(tabItem.uuid)||null; } getCurrentTab() { return this.tabOperate.getCurrentTab(); @@ -150,7 +152,9 @@ export class ApiTabComponent implements OnInit, OnDestroy { * Cache tab header/tabs content for restore when page close or component destroy */ cacheData() { - this.tabStorage.setPersistenceStorage(this.tabOperate.selectedIndex); + this.tabStorage.setPersistenceStorage(this.tabOperate.selectedIndex, { + handleDataBeforeCache: this.handleDataBeforeCache, + }); } /** * Tab Close Operate @@ -171,4 +175,10 @@ export class ApiTabComponent implements OnInit, OnDestroy { this.routerSubscribe?.unsubscribe(); this.cacheData(); } + private watchPageLeave() { + const that = this; + window.addEventListener('beforeunload', function(e) { + that.cacheData(); + }); + } } diff --git a/src/workbench/browser/src/app/pages/api/test/api-test-util.service.ts b/src/workbench/browser/src/app/pages/api/test/api-test-util.service.ts index 541e3e883..181c4afb8 100644 --- a/src/workbench/browser/src/app/pages/api/test/api-test-util.service.ts +++ b/src/workbench/browser/src/app/pages/api/test/api-test-util.service.ts @@ -265,14 +265,14 @@ export class ApiTestUtilService { * @returns apiData */ formatEditingApiData(formData): ApiTestData { - const result = formData; + const result = structuredClone(formData); ['requestBody', 'queryParams', 'restParams', 'requestHeaders'].forEach((tableName) => { if (whatType(result[tableName]) !== 'array') { return; } result[tableName] = (result[tableName] || []).filter((val) => val.name || val.value); }); - return formData; + return result; } /** * Transfer test data/test history to api data diff --git a/src/workbench/browser/src/app/pages/api/test/body/api-test-body.component.ts b/src/workbench/browser/src/app/pages/api/test/body/api-test-body.component.ts index d5c7cb790..a39b65e7a 100644 --- a/src/workbench/browser/src/app/pages/api/test/body/api-test-body.component.ts +++ b/src/workbench/browser/src/app/pages/api/test/body/api-test-body.component.ts @@ -218,6 +218,7 @@ export class ApiTestBodyComponent implements OnInit, OnChanges, AfterViewInit, O this.modelChange.emit(this.model); }, importFile: (inputArg) => { + console.log('importFile',inputArg); if (inputArg.file.length === 0) { return; } diff --git a/src/workbench/browser/src/app/pages/api/test/result-response/api-test-result-response.component.html b/src/workbench/browser/src/app/pages/api/test/result-response/api-test-result-response.component.html index 948f0e3c4..1ce4f8071 100644 --- a/src/workbench/browser/src/app/pages/api/test/result-response/api-test-result-response.component.html +++ b/src/workbench/browser/src/app/pages/api/test/result-response/api-test-result-response.component.html @@ -25,7 +25,7 @@ Unable to preview non-text type data, you can and open it with other programs.
@@ -34,7 +34,7 @@
    -
  • download back result
  • +
  • download response
@@ -42,7 +42,7 @@ The response result exceeds the previewable size, you can