From e512957cd614e85eb10c91f6c129fc7c4e1afe04 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Wed, 12 Aug 2020 12:14:53 +0800 Subject: [PATCH 1/9] =?UTF-8?q?refactor:=20=E8=AF=B7=E6=B1=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/test/components/ApiKeyValue.vue | 149 ++++++++++++++---- 1 file changed, 118 insertions(+), 31 deletions(-) diff --git a/frontend/src/business/components/api/test/components/ApiKeyValue.vue b/frontend/src/business/components/api/test/components/ApiKeyValue.vue index d3632a17d2..a2480c6da9 100644 --- a/frontend/src/business/components/api/test/components/ApiKeyValue.vue +++ b/frontend/src/business/components/api/test/components/ApiKeyValue.vue @@ -39,13 +39,88 @@ :visible.sync="itemValueVisible" class="advanced-item-value" width="50%"> - - - - - -
+ + + + + + + + + + +
+ + {{ func.name }} + + + + +
+
+
+ +
+
+ +
+ +
@@ -60,32 +135,13 @@
- -
-
-

{{ $t('api_test.request.parameters_filter') }}: - - {{ func }} - -

-
-
- {{ $t('api_test.request.parameters_filter_desc') }}: - http://mockjs.com/examples.html - -

{{ $t('api_test.request.parameters_filter_example') }}:@string(10) | md5 | substr: 1, 3

-

{{ $t('api_test.request.parameters_filter_example') }}:@integer(1, 5) | concat:_metersphere

-

{{ $t('api_test.request.parameters_filter_tips') }}

-
-
diff --git a/frontend/src/business/components/api/test/components/ApiVariable.vue b/frontend/src/business/components/api/test/components/ApiVariable.vue new file mode 100644 index 0000000000..14bd18fa56 --- /dev/null +++ b/frontend/src/business/components/api/test/components/ApiVariable.vue @@ -0,0 +1,341 @@ + + + + + diff --git a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue index c85e6213ce..32dddae2b6 100644 --- a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue @@ -26,9 +26,10 @@ - {{request.environment ? request.environment.name + ': ' : ''}} - {{displayUrl}} - {{$t('api_test.request.please_configure_environment_in_scenario')}} + {{ request.environment ? request.environment.name + ': ' : '' }} + {{ displayUrl }} + {{ $t('api_test.request.please_configure_environment_in_scenario') }} @@ -39,12 +40,14 @@ - {{$t('load_test.save_and_run')}} + {{ $t('load_test.save_and_run') }} + - + @@ -70,10 +73,11 @@ import {HttpRequest, KeyValue} from "../../model/ScenarioModel"; import MsApiExtract from "../extract/ApiExtract"; import ApiRequestMethodSelect from "../collapse/ApiRequestMethodSelect"; import {REQUEST_HEADERS} from "@/common/js/constants"; +import MsApiVariable from "@/business/components/api/test/components/ApiVariable"; export default { name: "MsApiHttpRequestForm", - components: {ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue}, + components: {MsApiVariable, ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue}, props: { request: HttpRequest, isReadOnly: { @@ -91,109 +95,109 @@ export default { } }; return { - activeName: "parameters", - rules: { - name: [ - {max: 300, message: this.$t('commons.input_limit', [1, 300]), trigger: 'blur'} - ], - url: [ - {max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'}, - {validator: validateURL, trigger: 'blur'} - ], - path: [ - {max: 500, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'}, - ] - }, - headerSuggestions: REQUEST_HEADERS + activeName: "parameters", + rules: { + name: [ + {max: 300, message: this.$t('commons.input_limit', [1, 300]), trigger: 'blur'} + ], + url: [ + {max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'}, + {validator: validateURL, trigger: 'blur'} + ], + path: [ + {max: 500, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'}, + ] + }, + headerSuggestions: REQUEST_HEADERS + } + }, + + methods: { + urlChange() { + if (!this.request.url) return; + let url = this.getURL(this.addProtocol(this.request.url)); + if (url) { + this.request.url = decodeURIComponent(url.origin + url.pathname); } }, - - methods: { - urlChange() { - if (!this.request.url) return; - let url = this.getURL(this.addProtocol(this.request.url)); - if (url) { - this.request.url = decodeURIComponent(url.origin + url.pathname); - } - }, - pathChange() { - if (!this.request.path) return; - let url = this.getURL(this.displayUrl); - let urlStr = url.origin + url.pathname; - let envUrl = this.request.environment.protocol + '://' + this.request.environment.socket; - this.request.path = decodeURIComponent(urlStr.substring(envUrl.length, urlStr.length)); - }, - getURL(urlStr) { - try { - let url = new URL(urlStr); - url.searchParams.forEach((value, key) => { - if (key && value) { - this.request.parameters.splice(0, 0, new KeyValue(key, value)); - } - }); - return url; - } catch (e) { - this.$error(this.$t('api_test.request.url_invalid'), 2000); - } - }, - methodChange(value) { - if (value === 'GET' && this.activeName === 'body') { - this.activeName = 'parameters'; - } - }, - useEnvironmentChange(value) { - if (value && !this.request.environment) { - this.$error(this.$t('api_test.request.please_add_environment_to_scenario'), 2000); - this.request.useEnvironment = false; - } - this.$refs["request"].clearValidate(); - }, - addProtocol(url) { - if (url) { - if (!url.toLowerCase().startsWith("https") && !url.toLowerCase().startsWith("http")) { - return "https://" + url; + pathChange() { + if (!this.request.path) return; + let url = this.getURL(this.displayUrl); + let urlStr = url.origin + url.pathname; + let envUrl = this.request.environment.protocol + '://' + this.request.environment.socket; + this.request.path = decodeURIComponent(urlStr.substring(envUrl.length, urlStr.length)); + }, + getURL(urlStr) { + try { + let url = new URL(urlStr); + url.searchParams.forEach((value, key) => { + if (key && value) { + this.request.parameters.splice(0, 0, new KeyValue(key, value)); } - } + }); return url; - }, - runDebug() { - this.$emit('runDebug'); + } catch (e) { + this.$error(this.$t('api_test.request.url_invalid'), 2000); } }, - - computed: { - isNotGet() { - return this.request.method !== "GET"; - }, - displayUrl() { - return this.request.environment ? this.request.environment.protocol + '://' + this.request.environment.socket + (this.request.path ? this.request.path : '') : ''; + methodChange(value) { + if (value === 'GET' && this.activeName === 'body') { + this.activeName = 'parameters'; } + }, + useEnvironmentChange(value) { + if (value && !this.request.environment) { + this.$error(this.$t('api_test.request.please_add_environment_to_scenario'), 2000); + this.request.useEnvironment = false; + } + this.$refs["request"].clearValidate(); + }, + addProtocol(url) { + if (url) { + if (!url.toLowerCase().startsWith("https") && !url.toLowerCase().startsWith("http")) { + return "https://" + url; + } + } + return url; + }, + runDebug() { + this.$emit('runDebug'); + } + }, + + computed: { + isNotGet() { + return this.request.method !== "GET"; + }, + displayUrl() { + return this.request.environment ? this.request.environment.protocol + '://' + this.request.environment.socket + (this.request.path ? this.request.path : '') : ''; } } +} From 01e22c9f1af5386c1ce3bad6613ed0ab4dab3095 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 13 Aug 2020 15:26:11 +0800 Subject: [PATCH 7/9] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A4=84=E7=90=86=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/test/components/ApiScenarioConfig.vue | 37 ++++++++++--------- .../api/test/components/ApiVariable.vue | 32 ++++++++-------- .../components/request/ApiHttpRequestForm.vue | 4 +- .../components/request/ApiRequestForm.vue | 31 ++++++++-------- .../api/test/model/ScenarioModel.js | 6 --- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue b/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue index 8bd4b8d08f..1e9dee1661 100644 --- a/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue +++ b/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue @@ -36,7 +36,8 @@
- +
@@ -44,25 +45,25 @@