diff --git a/src/workbench/browser/package.json b/src/workbench/browser/package.json index d0b48dfb..06140f42 100644 --- a/src/workbench/browser/package.json +++ b/src/workbench/browser/package.json @@ -20,7 +20,7 @@ "dependencies": { "@angular-cli/base-href-webpack": "1.0.16", "@angular/animations": "14.0.3", - "@angular/cdk": "13.3.9", + "@angular/cdk": "14.0.3", "@angular/common": "14.0.3", "@angular/compiler": "14.0.3", "@angular/core": "14.0.3", @@ -37,6 +37,7 @@ "angular": "1.8.2", "brace": "0.11.1", "js-beautify": "1.14.4", + "lodash-es": "4.17.21", "markdown-it": "13.0.1", "monaco-editor": "0.33.0", "ng-zorro-antd": "13.3.2", @@ -62,6 +63,7 @@ "@ngx-translate/http-loader": "7.0.0", "@types/jasmine": "4.0.3", "@types/jasminewd2": "2.0.10", + "@types/lodash-es": "4.17.6", "@types/markdown-it": "12.2.3", "@types/node": "18.0.0", "@typescript-eslint/eslint-plugin": "5.29.0", diff --git a/src/workbench/browser/src/app/pages/api/http/test/api-test.component.html b/src/workbench/browser/src/app/pages/api/http/test/api-test.component.html index 8da1a8b0..a0de7f0e 100644 --- a/src/workbench/browser/src/app/pages/api/http/test/api-test.component.html +++ b/src/workbench/browser/src/app/pages/api/http/test/api-test.component.html @@ -9,33 +9,15 @@ -
+
{{ env.hostUri }}
- - + + - - + Headers {{ model.request.requestHeaders | apiParamsNum - }} + }} - + Body - + "> - + + Query {{ model.request.queryParams | apiParamsNum - }} + }} - + REST {{ model.request.restParams | apiParamsNum - }} + }} - + Pre-request Script - + After-response Script - +
- + @@ -175,16 +117,21 @@
- + + +
+ + Download +
+
diff --git a/src/workbench/browser/src/app/pages/api/http/test/api-test.component.ts b/src/workbench/browser/src/app/pages/api/http/test/api-test.component.ts index d9796e2b..8d6afc8d 100644 --- a/src/workbench/browser/src/app/pages/api/http/test/api-test.component.ts +++ b/src/workbench/browser/src/app/pages/api/http/test/api-test.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, ChangeDetectorRef, Input, Output, EventEmitter } from '@angular/core'; +import { Component, OnInit, OnDestroy, ChangeDetectorRef, Input, Output, EventEmitter, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Select } from '@ngxs/store'; @@ -33,6 +33,8 @@ import { LanguageService } from 'eo/workbench/browser/src/app/core/services/lang import { ContentTypeByAbridge } from 'eo/workbench/browser/src/app/shared/services/api-test/api-test.model'; import { transferUrlAndQuery } from 'eo/workbench/browser/src/app/utils/api'; import { getGlobals, setGlobals } from 'eo/workbench/browser/src/app/shared/services/api-test/api-test.utils'; +import { ApiTestResultResponseComponent } from 'eo/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component'; +import { isEmpty } from 'lodash-es'; const API_TEST_DRAG_TOP_HEIGHT_KEY = 'API_TEST_DRAG_TOP_HEIGHT'; interface testViewModel { @@ -63,6 +65,7 @@ export class ApiTestComponent implements OnInit, OnDestroy { @Output() modelChange = new EventEmitter(); @Output() afterTested = new EventEmitter(); @Output() eoOnInit = new EventEmitter(); + @ViewChild(ApiTestResultResponseComponent) apiTestResultResponseComponent: ApiTestResultResponseComponent; // 通过组件类型获取 @Select(EnvState) env$: Observable; validateForm!: FormGroup; env: any = { @@ -83,6 +86,7 @@ export class ApiTestComponent implements OnInit, OnDestroy { REQUEST_METHOD = objectToArray(RequestMethod); REQUEST_PROTOCOL = objectToArray(RequestProtocol); MAX_TEST_SECONDS = 60; + isEmpty = isEmpty; private initTimes = 0; private status$: Subject = new Subject(); @@ -343,11 +347,11 @@ export class ApiTestComponent implements OnInit, OnDestroy { //* Other tab test finish,support multiple tab test same time this.afterTested.emit({ id: queryParams.pageID, - url:'/home/api/http/test', + url: '/home/api/http/test', model: { testStartTime: 0, testResult: tmpHistory, - } + }, }); } else { this.model.testResult = tmpHistory; @@ -384,6 +388,9 @@ export class ApiTestComponent implements OnInit, OnDestroy { }, }); } + downloadFile() { + this.apiTestResultResponseComponent.downloadResponseText(); + } /** * Change test status * diff --git a/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.html b/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.html index fb573fff..2f6e15b9 100644 --- a/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.html +++ b/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.html @@ -19,36 +19,38 @@ -
-
-
- Unable to preview non-text type data, you can - - and open it with other programs. -
-
- -
- -
    -
  • download response
  • -
-
-
-
- The response result exceeds the previewable size, you can - - -
- +
+ + + + + +
+ Unable to preview non-text type data, you can + + and open it with other programs. +
+
+
+ + +
+ The response result exceeds the previewable size, you can + + +
+
+
+ + +
-
diff --git a/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.ts b/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.ts index b39d126f..114ba05e 100644 --- a/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.ts +++ b/src/workbench/browser/src/app/pages/api/http/test/result-response/api-test-result-response.component.ts @@ -41,7 +41,11 @@ export class ApiTestResultResponseComponent implements OnInit, OnChanges { } } } - ngOnInit(): void {} + ngOnInit(): void { + setTimeout(() => { + console.log('this.model', this.model); + }, 5000); + } contextMenu($event: MouseEvent, menu: NzDropdownMenuComponent): void { this.nzContextMenuService.create($event, menu); diff --git a/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts b/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts index b16ff7c5..adcc0849 100644 --- a/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts +++ b/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts @@ -10,7 +10,7 @@ import { ElementRef, } from '@angular/core'; import { EoMessageService } from 'eo/workbench/browser/src/app/eoui/message/eo-message.service'; -import { debounce, whatTextType } from '../../../utils'; +import { debounce, isBase64, whatTextType } from '../../../utils'; import { ElectronService } from 'eo/workbench/browser/src/app/core/services/electron/electron.service'; import { editor } from 'monaco-editor'; import * as monaco from 'monaco-editor'; @@ -171,11 +171,14 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges if (val === this.$$code) { return; } - // console.log('val', val); let code = ''; try { - code = JSON.stringify(typeof val === 'string' ? JSON.parse(val) : val, null, 4); + if (isBase64(val)) { + code = window.atob(val); + } else { + code = JSON.stringify(typeof val === 'string' ? JSON.parse(val) : val, null, 4); + } } catch { code = String(val); } diff --git a/src/workbench/browser/src/app/shared/shared.module.ts b/src/workbench/browser/src/app/shared/shared.module.ts index b257094a..0a145ad0 100644 --- a/src/workbench/browser/src/app/shared/shared.module.ts +++ b/src/workbench/browser/src/app/shared/shared.module.ts @@ -27,6 +27,7 @@ import { NzResizableModule } from 'ng-zorro-antd/resizable'; import { NzDividerModule } from 'ng-zorro-antd/divider'; import { NzModalModule } from 'ng-zorro-antd/modal'; import { NzTypographyModule } from 'ng-zorro-antd/typography'; +import { NzIconModule } from 'ng-zorro-antd/icon'; import { NzNotificationModule } from 'ng-zorro-antd/notification'; import { NzMessageModule } from 'ng-zorro-antd/message'; @@ -93,6 +94,7 @@ const SHARED_MODULE = [ NzDividerModule, NzModalModule, NzTypographyModule, + NzIconModule, ] as const; @NgModule({ diff --git a/src/workbench/browser/src/app/utils/index.ts b/src/workbench/browser/src/app/utils/index.ts index 9f48b5a1..1df4bec0 100644 --- a/src/workbench/browser/src/app/utils/index.ts +++ b/src/workbench/browser/src/app/utils/index.ts @@ -166,7 +166,7 @@ export function debounce(fn, wait = 50) { let timer = null; // 将 debounce 处理结果当作函数返回 // 触发事件回调时执行这个返回函数 - return function(...args) { + return function (...args) { // this保存给context const context = this; // 如果已经设定过定时器就清空上一次的定时器 @@ -183,7 +183,7 @@ export function debounce(fn, wait = 50) { export function throttle(fn, gap) { let timerId = null; - return function(...rest) { + return function (...rest) { if (timerId === null) { fn(...rest); // 立即执行 timerId = setTimeout(() => { @@ -232,5 +232,16 @@ export const eoDeepCopy = (obj) => { return copy; } - throw new Error('Unable to copy obj! Its type isn\'t supported.'); + throw new Error("Unable to copy obj! Its type isn't supported."); }; + +export function isBase64(str) { + if (str === '' || str.trim() === '') { + return false; + } + try { + return window.btoa(window.atob(str)) === str; + } catch (err) { + return false; + } +} diff --git a/yarn.lock b/yarn.lock index f7ce63bf..52b0335f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -302,7 +302,16 @@ dependencies: tslib "^2.3.0" -"@angular/cdk@13.3.9", "@angular/cdk@^13.0.1": +"@angular/cdk@14.0.3": + version "14.0.3" + resolved "https://registry.npmmirror.com/@angular/cdk/-/cdk-14.0.3.tgz#eaa0b0736481bc9c1d24ad88e19dd20874506032" + integrity sha512-XN5+WVUFx13lW2x9gnzJprHGqcvSpKQaoXxFvlcn16i0P6Iy1jldVZm6q6chEhgX9rEi7P31nfE88OJzHmkEyw== + dependencies: + tslib "^2.3.0" + optionalDependencies: + parse5 "^5.0.0" + +"@angular/cdk@^13.0.1": version "13.3.9" resolved "https://registry.npmmirror.com/@angular/cdk/-/cdk-13.3.9.tgz#a177196e872e29be3f84d3a50f778d361c689ff7" integrity sha512-XCuCbeuxWFyo3EYrgEYx7eHzwl76vaWcxtWXl00ka8d+WAOtMQ6Tf1D98ybYT5uwF9889fFpXAPw98mVnlo3MA== @@ -417,9 +426,9 @@ tslib "^2.3.0" "@angular/upgrade@^14.0.3": - version "14.1.0" - resolved "https://registry.npmmirror.com/@angular/upgrade/-/upgrade-14.1.0.tgz#e2e4ba33b8dce009e96fc9ece5e4d36061c6ce73" - integrity sha512-EOFSpcdncQiQ7A5WktKe4r5uFkEDB325ddqZsuHesMbEQFeFu+93JwJWeRtU9gEyyuVCIDN6DyKaizUw/M4yGA== + version "14.2.1" + resolved "https://registry.npmmirror.com/@angular/upgrade/-/upgrade-14.2.1.tgz#7e154fb721a1764d0c226ac751fb04912725a78c" + integrity sha512-UxmqUBoaSFM28UBDA+heTQwNYrhq0mDdmcMt7Pg1gj0kPaQY3f6NgbrNH2UMnps+b4aZEbD/jnoJ3+I2F3VuhA== dependencies: tslib "^2.3.0" @@ -2300,6 +2309,18 @@ resolved "https://registry.npmmirror.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9" integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA== +"@types/lodash-es@4.17.6": + version "4.17.6" + resolved "https://registry.npmmirror.com/@types/lodash-es/-/lodash-es-4.17.6.tgz#c2ed4c8320ffa6f11b43eb89e9eaeec65966a0a0" + integrity sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.185" + resolved "https://registry.npmmirror.com/@types/lodash/-/lodash-4.14.185.tgz#c9843f5a40703a8f5edfd53358a58ae729816908" + integrity sha512-evMDG1bC4rgQg4ku9tKpuMh5iBNEwNa3tf9zRHdP1qlv+1WUg44xat4IxCE14gIpZRGUUWAx2VhItCZc25NfMA== + "@types/markdown-it@12.2.3": version "12.2.3" resolved "https://registry.npmmirror.com/@types/markdown-it/-/markdown-it-12.2.3.tgz#0d6f6e5e413f8daaa26522904597be3d6cd93b51" @@ -8542,6 +8563,11 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" +lodash-es@4.17.21: + version "4.17.21" + resolved "https://registry.npmmirror.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" + integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== + lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.npmmirror.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"