@@ -40,7 +40,7 @@
components: {draggable},
props: {
- requests: Array,
+ scenario: Object,
open: Function,
isReadOnly: {
type: Boolean,
@@ -65,15 +65,15 @@
methods: {
createRequest: function () {
let request = new Request();
- this.requests.push(request);
+ this.scenario.requests.push(request);
},
copyRequest: function (index) {
- let request = this.requests[index];
- this.requests.push(new Request(request));
+ let request = this.scenario.requests[index];
+ this.scenario.requests.push(new Request(request));
},
deleteRequest: function (index) {
- this.requests.splice(index, 1);
- if (this.requests.length === 0) {
+ this.scenario.requests.splice(index, 1);
+ if (this.scenario.requests.length === 0) {
this.createRequest();
}
},
@@ -88,13 +88,17 @@
}
},
select: function (request) {
+ request.environment = this.scenario.environment;
+ if (!request.useEnvironment) {
+ request.useEnvironment = false;
+ }
this.selected = request;
this.open(request);
}
},
created() {
- this.select(this.requests[0]);
+ this.select(this.scenario.requests[0]);
}
}
diff --git a/frontend/src/business/components/api/test/components/ApiRequestForm.vue b/frontend/src/business/components/api/test/components/ApiRequestForm.vue
index 83184a8476..0dd42b9a21 100644
--- a/frontend/src/business/components/api/test/components/ApiRequestForm.vue
+++ b/frontend/src/business/components/api/test/components/ApiRequestForm.vue
@@ -1,30 +1,47 @@
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{request.environment ? request.environment.name + ': ' : ''}}
+ {{displayUrl}}
+ {{$t('api_test.request.please_configure_environment_in_scenario')}}
+
+
+
+
+
+
+
+
+ :description="$t('api_test.request.parameters_desc')"/>
@@ -48,10 +65,11 @@
import MsApiAssertions from "./assertion/ApiAssertions";
import {KeyValue, Request} from "../model/ScenarioModel";
import MsApiExtract from "./extract/ApiExtract";
+ import ApiRequestMethodSelect from "./collapse/ApiRequestMethodSelect";
export default {
name: "MsApiRequestForm",
- components: {MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue},
+ components: {ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue},
props: {
request: Request,
isReadOnly: {
@@ -77,6 +95,9 @@
url: [
{max: 500, required: true, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'},
{validator: validateURL, trigger: 'blur'}
+ ],
+ path: [
+ {max: 500, required: true, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'},
]
}
}
@@ -85,39 +106,43 @@
methods: {
urlChange() {
if (!this.request.url) return;
-
- let parameters = [];
+ 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;
+ if (!this.request.path.startsWith('/')) {
+ this.request.path = '/' + this.request.path;
+ }
+ let url = this.getURL(this.displayUrl);
+ this.request.path = decodeURIComponent(url.pathname);
+ this.request.urlWirhEnv = decodeURIComponent(url.origin + url.pathname);
+ },
+ getURL(urlStr) {
try {
- let url = new URL(this.addProtocol(this.request.url));
+ let url = new URL(urlStr);
url.searchParams.forEach((value, key) => {
if (key && value) {
- parameters.push(new KeyValue(key, value));
+ this.request.parameters.splice(0, 0, new KeyValue(key, value));
}
});
- // 添加一个空的,用于填写
- parameters.push(new KeyValue());
- this.request.parameters = parameters;
- this.request.url = this.getURL(url);
+ return url;
} catch (e) {
- this.$error(this.$t('api_test.request.url_invalid'), 2000)
+ this.$error(this.$t('api_test.request.url_invalid'), 2000);
}
-
},
methodChange(value) {
if (value === 'GET' && this.activeName === 'body') {
this.activeName = 'parameters';
}
},
- parametersChange(parameters) {
- if (!this.request.url) return;
- let url = new URL(this.addProtocol(this.request.url));
- url.search = "";
- parameters.forEach(function (parameter) {
- if (parameter.name && parameter.value) {
- url.searchParams.append(parameter.name, parameter.value);
- }
- })
- this.request.url = this.getURL(url);
+ useEnvironmentChange(value) {
+ if (value && !this.request.environment) {
+ this.$error(this.$t('api_test.request.please_add_environment_to_scenario'), 2000);
+ this.request.useEnvironment = false;
+ }
},
addProtocol(url) {
if (url) {
@@ -126,15 +151,15 @@
}
}
return url;
- },
- getURL(url) {
- return decodeURIComponent(url.origin + url.pathname) + "?" + url.searchParams.toString();
}
},
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 : '') : '';
}
}
}
@@ -144,4 +169,28 @@
.request-method-select {
width: 110px;
}
+
+ .el-tag {
+ width: 100%;
+ height: 40px;
+ line-height: 40px;
+ }
+
+ .environment-display {
+ font-size: 14px;
+ }
+
+ .environment-name {
+ font-weight: bold;
+ font-style: italic;
+ }
+
+ .adjust-margin-bottom {
+ margin-bottom: 10px;
+ }
+
+ .environment-url-tip {
+ color: #F56C6C;
+ }
+
diff --git a/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue b/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue
index 4f23a49b9c..ac4c55851f 100644
--- a/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue
+++ b/frontend/src/business/components/api/test/components/ApiScenarioConfig.vue
@@ -25,7 +25,7 @@
-
+
@@ -35,8 +35,8 @@
-
-
+
+
@@ -66,6 +66,7 @@
props: {
scenarios: Array,
+ projectId: String,
isReadOnly: {
type: Boolean,
default: false
diff --git a/frontend/src/business/components/api/test/components/ApiScenarioForm.vue b/frontend/src/business/components/api/test/components/ApiScenarioForm.vue
index 32522275ea..a447a2ec8e 100644
--- a/frontend/src/business/components/api/test/components/ApiScenarioForm.vue
+++ b/frontend/src/business/components/api/test/components/ApiScenarioForm.vue
@@ -1,12 +1,19 @@
-
+
-
-
-
+
+
+
+ {{$t('api_test.environment.environment_config')}}
+
+
+
+
+
+
@@ -16,28 +23,38 @@
+
+
+
+
diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue
index b992735f0b..c2de8c0adf 100644
--- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue
+++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue
@@ -7,7 +7,7 @@
-
+ Add
diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue
index 758dea2ec4..ddd19f0d28 100644
--- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue
+++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue
@@ -15,7 +15,7 @@