diff --git a/frontend/src/business/components/api/definition/components/ApiVariable.vue b/frontend/src/business/components/api/definition/components/ApiVariable.vue
index 02e24adaac..13f2d3b02e 100644
--- a/frontend/src/business/components/api/definition/components/ApiVariable.vue
+++ b/frontend/src/business/components/api/definition/components/ApiVariable.vue
@@ -24,6 +24,7 @@
@change="typeChange(item)">
+
@@ -90,6 +91,7 @@
+
@@ -101,6 +103,7 @@
import {KeyValue, Scenario} from "../model/ApiTestModel";
import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants";
import MsApiVariableAdvance from "./ApiVariableAdvance";
+ import MsApiVariableJson from "./ApiVariableJson";
import MsApiBodyFileUpload from "./body/ApiBodyFileUpload";
import {REQUIRED} from "../model/JsonData";
import Vue from 'vue';
@@ -108,7 +111,7 @@
export default {
name: "MsApiVariable",
- components: {ApiVariableSetting, MsApiBodyFileUpload, MsApiVariableAdvance},
+ components: {ApiVariableSetting, MsApiBodyFileUpload, MsApiVariableAdvance , MsApiVariableJson},
props: {
keyPlaceholder: String,
valuePlaceholder: String,
@@ -140,7 +143,7 @@
{name: this.$t('commons.selector.not_required'), id: false}
],
isSelectAll: true,
- isActive: true
+ isActive: true,
}
},
watch: {
@@ -237,14 +240,22 @@
return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
},
advanced(item) {
- this.$refs.variableAdvance.open();
- this.currentItem = item;
+ if (item.type === 'json'){
+ this.$refs.variableJson.open(item);
+ this.currentItem = item;
+ }else {
+ this.$refs.variableAdvance.open();
+ this.currentItem = item;
+ }
+
},
typeChange(item) {
if (item.type === 'file') {
item.contentType = 'application/octet-stream';
- } else {
+ } else if (item.type === 'text'){
item.contentType = 'text/plain';
+ } else {
+ item.contentType = 'application/json'
}
this.reload();
},
@@ -266,6 +277,9 @@
},
openApiVariableSetting(item) {
this.$refs.apiVariableSetting.open(item);
+ },
+ callback(item){
+ this.currentItem.value=item;
}
},
created() {
diff --git a/frontend/src/business/components/api/definition/components/ApiVariableJson.vue b/frontend/src/business/components/api/definition/components/ApiVariableJson.vue
new file mode 100644
index 0000000000..c78ee428c5
--- /dev/null
+++ b/frontend/src/business/components/api/definition/components/ApiVariableJson.vue
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/frontend/src/business/components/api/definition/components/body/ApiBody.vue b/frontend/src/business/components/api/definition/components/body/ApiBody.vue
index 2d86e275bf..bd00d8731c 100644
--- a/frontend/src/business/components/api/definition/components/body/ApiBody.vue
+++ b/frontend/src/business/components/api/definition/components/body/ApiBody.vue
@@ -208,6 +208,7 @@ export default {
},
formatChange() {
const MsConvert = new Convert();
+
if (this.body.format === 'JSON-SCHEMA') {
if (this.body.raw && !this.body.jsonSchema) {
this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw));
@@ -266,24 +267,48 @@ export default {
batchAdd() {
this.$refs.batchAddParameter.open();
},
+ format(array, obj) {
+ if (array) {
+ let isAdd = true;
+ for (let i in array) {
+ let item = array[i];
+ if (item.name === obj.name) {
+ item.value = obj.value;
+ isAdd = false;
+ }
+ }
+ if (isAdd) {
+ this.body.kvs.unshift(obj);
+ }
+ }
+ },
batchSave(data) {
if (data) {
let params = data.split("\n");
let keyValues = [];
params.forEach(item => {
- let line = item.split(/,|,/);
+ let line = [];
+ line[0] = item.substring(0,item.indexOf(":"));
+ line[1] = item.substring(item.indexOf(":")+1,item.length);
let required = false;
- if (line[1] === '必填' || line[1] === 'Required' || line[1] === 'true') {
- required = true;
- }
- keyValues.push(new KeyValue({name: line[0], required: required, value: line[2], description: line[3], type: "text", valid: false, file: false, encode: true, enable: true, contentType: "text/plain"}));
+ keyValues.unshift(new KeyValue({
+ name: line[0],
+ required: required,
+ value: line[1],
+ description: line[2],
+ type: "text",
+ valid: false,
+ file: false,
+ encode: true,
+ enable: true,
+ contentType: "text/plain"
+ }));
})
keyValues.forEach(item => {
- this.body.kvs.unshift(item);
+ this.format(this.body.kvs, item);
})
}
},
-
},
created() {
if (!this.body.type) {
@@ -296,6 +321,7 @@ export default {
}
});
}
+
}
}