fix接口定义_请求体为form-data_的json参数的可以增加参数--story=1003216 --user=王孝刚 请求体为form-data 的json参数的可以增加参数说明填写 https://www.tapd.cn/55049933/s/1051283
This commit is contained in:
parent
ac546e04c1
commit
7f0bd60858
|
@ -24,6 +24,7 @@
|
|||
@change="typeChange(item)">
|
||||
<el-option value="text"/>
|
||||
<el-option value="file"/>
|
||||
<el-option value="json"/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-input>
|
||||
|
@ -90,6 +91,7 @@
|
|||
<ms-api-variable-advance ref="variableAdvance" :environment="environment" :scenario="scenario"
|
||||
:parameters="parameters"
|
||||
:current-item="currentItem"/>
|
||||
<ms-api-variable-json ref="variableJson" @callback="callback"/>
|
||||
|
||||
<api-variable-setting
|
||||
ref="apiVariableSetting"/>
|
||||
|
@ -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() {
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
<template>
|
||||
|
||||
<el-dialog
|
||||
:visible.sync="dialogVisible" destroy-on-close @close="close">
|
||||
<div style="padding: 10px">
|
||||
<el-switch active-text="JSON-SCHEMA" v-model="item.jsonType" @change="formatChange" active-value="JSON-SCHEMA"/>
|
||||
</div>
|
||||
<div v-if="codeEditActive">
|
||||
<ms-json-code-edit
|
||||
v-if="item.jsonType==='JSON-SCHEMA'"
|
||||
:body="item"
|
||||
ref="jsonCodeEdit"/>
|
||||
<ms-code-edit
|
||||
v-else
|
||||
:read-only="isReadOnly"
|
||||
:data.sync="item.value"
|
||||
:mode="'json'"
|
||||
height="400px"
|
||||
ref="codeEdit"/>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import MsCodeEdit from "../../../common/components/MsCodeEdit";
|
||||
import Convert from "@/business/components/common/json-schema/convert/convert";
|
||||
import MsJsonCodeEdit from "../../../common/json-schema/JsonSchemaEditor";
|
||||
|
||||
|
||||
export default {
|
||||
name: "MsApiVariableJson",
|
||||
components: {MsJsonCodeEdit, MsCodeEdit},
|
||||
props: {
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
jsonSchema: "JSON",
|
||||
codeEditActive: true,
|
||||
item: {}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'item.value'() {
|
||||
if (this.item.jsonType !== 'JSON-SCHEMA' && this.item.value) {
|
||||
try {
|
||||
const MsConvert = new Convert();
|
||||
let data = MsConvert.format(JSON.parse(this.item.value));
|
||||
if (this.item.jsonSchema) {
|
||||
this.item.jsonSchema = this.deepAssign(this.item.jsonSchema, data);
|
||||
}
|
||||
} catch (ex) {
|
||||
this.item.jsonSchema = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
open(item) {
|
||||
this.item.value = item.value;
|
||||
this.dialogVisible = true;
|
||||
this.reloadCodeEdit();
|
||||
},
|
||||
reloadCodeEdit() {
|
||||
this.codeEditActive = false;
|
||||
this.$nextTick(() => {
|
||||
this.codeEditActive = true;
|
||||
});
|
||||
},
|
||||
formatChange() {
|
||||
const MsConvert = new Convert();
|
||||
if (this.item.jsonType === 'JSON-SCHEMA') {
|
||||
if (this.item.value && !this.item.jsonSchema) {
|
||||
this.item.jsonSchema = MsConvert.format(JSON.parse(this.item.value));
|
||||
}
|
||||
} else {
|
||||
if (this.item.jsonSchema) {
|
||||
MsConvert.schemaToJsonStr(this.item.jsonSchema, (result) => {
|
||||
this.$set(this.item, 'value', result);
|
||||
this.$emit('callback', result);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
saveAdvanced() {
|
||||
this.dialogVisible = false;
|
||||
if (this.item.jsonType === 'JSON-SCHEMA') {
|
||||
this.item.jsonType = 'JSON';
|
||||
this.formatChange();
|
||||
} else {
|
||||
this.$emit('callback', this.item.value);
|
||||
}
|
||||
this.item = {};
|
||||
this.reloadCodeEdit();
|
||||
},
|
||||
close(){
|
||||
this.saveAdvanced();
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
|
@ -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 {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue