feat: post 请求支持参数格式化
This commit is contained in:
parent
d513ae4403
commit
e181a4867c
|
@ -8,5 +8,6 @@ import java.util.List;
|
||||||
public class Body {
|
public class Body {
|
||||||
private String type;
|
private String type;
|
||||||
private String raw;
|
private String raw;
|
||||||
|
private String format;
|
||||||
private List<KeyValue> kvs;
|
private List<KeyValue> kvs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<el-collapse-transition>
|
<el-collapse-transition>
|
||||||
<el-tabs v-model="activeName" v-show="isActive">
|
<el-tabs v-model="activeName" v-show="isActive">
|
||||||
<el-tab-pane label="Body" name="body" class="pane">
|
<el-tab-pane label="Body" name="body" class="pane">
|
||||||
<ms-code-edit :read-only="true" :data="response.body" :modes="modes" ref="codeEdit"/>
|
<ms-code-edit :mode="mode" :read-only="true" :data="response.body" :modes="modes" ref="codeEdit"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="Headers" name="headers" class="pane">
|
<el-tab-pane label="Headers" name="headers" class="pane">
|
||||||
<pre>{{response.headers}}</pre>
|
<pre>{{response.headers}}</pre>
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
import MsAssertionResults from "./AssertionResults";
|
import MsAssertionResults from "./AssertionResults";
|
||||||
import MsCodeEdit from "../../../common/components/MsCodeEdit";
|
import MsCodeEdit from "../../../common/components/MsCodeEdit";
|
||||||
import MsDropdown from "../../../common/components/MsDropdown";
|
import MsDropdown from "../../../common/components/MsDropdown";
|
||||||
|
import {BODY_FORMAT} from "../../test/model/ScenarioModel";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsResponseText",
|
name: "MsResponseText",
|
||||||
|
@ -50,6 +51,7 @@
|
||||||
isActive: false,
|
isActive: false,
|
||||||
activeName: "body",
|
activeName: "body",
|
||||||
modes: ['text', 'json', 'xml', 'html'],
|
modes: ['text', 'json', 'xml', 'html'],
|
||||||
|
mode: BODY_FORMAT.TEXT
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@
|
||||||
this.isActive = !this.isActive;
|
this.isActive = !this.isActive;
|
||||||
},
|
},
|
||||||
modeChange(mode) {
|
modeChange(mode) {
|
||||||
this.$refs.codeEdit.setMode(mode);
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,20 +9,26 @@
|
||||||
</el-radio-button>
|
</el-radio-button>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
|
||||||
|
<ms-dropdown :default-command="body.format" v-if="body.type == 'Raw'" :commands="modes" @command="modeChange"/>
|
||||||
|
|
||||||
<ms-api-key-value :is-read-only="isReadOnly" :items="body.kvs" v-if="body.isKV()"/>
|
<ms-api-key-value :is-read-only="isReadOnly" :items="body.kvs" v-if="body.isKV()"/>
|
||||||
|
|
||||||
<el-input :disabled="isReadOnly" class="textarea" type="textarea" v-model="body.raw" :autosize="{ minRows: 10, maxRows: 25}" resize="none"
|
<div class="body-raw" v-if="body.type == 'Raw'">
|
||||||
v-else/>
|
<ms-code-edit :mode="body.format" :read-only="isReadOnly" :data.sync="body.raw" :modes="modes" ref="codeEdit"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MsApiKeyValue from "./ApiKeyValue";
|
import MsApiKeyValue from "./ApiKeyValue";
|
||||||
import {Body, BODY_TYPE} from "../model/ScenarioModel";
|
import {Body, BODY_FORMAT, BODY_TYPE} from "../model/ScenarioModel";
|
||||||
|
import MsCodeEdit from "../../../common/components/MsCodeEdit";
|
||||||
|
import MsDropdown from "../../../common/components/MsDropdown";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsApiBody",
|
name: "MsApiBody",
|
||||||
components: {MsApiKeyValue},
|
components: {MsDropdown, MsCodeEdit, MsApiKeyValue},
|
||||||
props: {
|
props: {
|
||||||
body: Body,
|
body: Body,
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
|
@ -33,16 +39,24 @@
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
type: BODY_TYPE
|
type: BODY_TYPE,
|
||||||
|
modes: ['text', 'json', 'xml', 'html']
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {},
|
methods: {
|
||||||
|
modeChange(mode) {
|
||||||
|
this.body.format = mode;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
if (this.body.type === null) {
|
if (!this.body.type) {
|
||||||
this.body.type = BODY_TYPE.KV;
|
this.body.type = BODY_TYPE.KV;
|
||||||
}
|
}
|
||||||
|
if (!this.body.format) {
|
||||||
|
this.body.format = BODY_FORMAT.TEXT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -51,4 +65,19 @@
|
||||||
.textarea {
|
.textarea {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.body-raw {
|
||||||
|
padding: 15px 0;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dropdown {
|
||||||
|
margin-left: 20px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ace_editor {
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -37,6 +37,13 @@ export const BODY_TYPE = {
|
||||||
RAW: "Raw"
|
RAW: "Raw"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const BODY_FORMAT = {
|
||||||
|
TEXT: "text",
|
||||||
|
JSON: "json",
|
||||||
|
XML: "xml",
|
||||||
|
HTML: "html",
|
||||||
|
}
|
||||||
|
|
||||||
export const ASSERTION_TYPE = {
|
export const ASSERTION_TYPE = {
|
||||||
TEXT: "Text",
|
TEXT: "Text",
|
||||||
REGEX: "Regex",
|
REGEX: "Regex",
|
||||||
|
@ -820,12 +827,42 @@ class JMXGenerator {
|
||||||
|
|
||||||
addRequestHeader(httpSamplerProxy, request) {
|
addRequestHeader(httpSamplerProxy, request) {
|
||||||
let name = request.name + " Headers";
|
let name = request.name + " Headers";
|
||||||
|
this.addBodyFormat(request);
|
||||||
let headers = this.filterKV(request.headers);
|
let headers = this.filterKV(request.headers);
|
||||||
if (headers.length > 0) {
|
if (headers.length > 0) {
|
||||||
httpSamplerProxy.put(new HeaderManager(name, headers));
|
httpSamplerProxy.put(new HeaderManager(name, headers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addBodyFormat(request) {
|
||||||
|
let bodyFormat = request.body.format;
|
||||||
|
if (bodyFormat) {
|
||||||
|
switch (bodyFormat) {
|
||||||
|
case BODY_FORMAT.JSON:
|
||||||
|
this.addContentType(request, 'application/json');
|
||||||
|
break;
|
||||||
|
case BODY_FORMAT.HTML:
|
||||||
|
this.addContentType(request, 'text/html');
|
||||||
|
break;
|
||||||
|
case BODY_FORMAT.XML:
|
||||||
|
this.addContentType(request, 'text/xml');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addContentType(request, type) {
|
||||||
|
for (let index in request.headers) {
|
||||||
|
if (request.headers[index].name == 'Content-Type') {
|
||||||
|
request.headers.splice(index, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.headers.push(new KeyValue('Content-Type', type));
|
||||||
|
}
|
||||||
|
|
||||||
addRequestArguments(httpSamplerProxy, request) {
|
addRequestArguments(httpSamplerProxy, request) {
|
||||||
let args = this.filterKV(request.parameters);
|
let args = this.filterKV(request.parameters);
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
components: { editor: require('vue2-ace-editor')},
|
components: { editor: require('vue2-ace-editor')},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
mode: 'text',
|
|
||||||
formatData: ''
|
formatData: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -25,6 +24,12 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default() {
|
||||||
|
return 'text';
|
||||||
|
}
|
||||||
|
},
|
||||||
modes: {
|
modes: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default() {
|
default() {
|
||||||
|
@ -35,6 +40,14 @@
|
||||||
mounted() {
|
mounted() {
|
||||||
this.format();
|
this.format();
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
formatData() {
|
||||||
|
this.$emit('update:data', this.formatData);
|
||||||
|
},
|
||||||
|
mode() {
|
||||||
|
this.format();
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
editorInit: function (editor) {
|
editorInit: function (editor) {
|
||||||
require('brace/ext/language_tools') //language extension prerequsite...
|
require('brace/ext/language_tools') //language extension prerequsite...
|
||||||
|
@ -51,19 +64,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
format() {
|
format() {
|
||||||
if (this.mode === 'json') {
|
if (this.mode === 'json' && this.readOnly) {
|
||||||
try {
|
try {
|
||||||
this.formatData = JSON.stringify(JSON.parse(this.data), null, '\t');
|
this.formatData = JSON.stringify(JSON.parse(this.data), null, '\t');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.data) {
|
||||||
this.formatData = this.data;
|
this.formatData = this.data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (this.data) {
|
||||||
this.formatData = this.data;
|
this.formatData = this.data;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
setMode(mode) {
|
|
||||||
this.mode = mode;
|
|
||||||
this.format();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,15 @@
|
||||||
props: {
|
props: {
|
||||||
commands: {
|
commands: {
|
||||||
type: Array
|
type: Array
|
||||||
|
},
|
||||||
|
defaultCommand: {
|
||||||
|
type: String
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.commands && this.commands.length > 0) {
|
if (this.defaultCommand) {
|
||||||
|
this.currentCommand = this.defaultCommand;
|
||||||
|
} else if (this.commands && this.commands.length > 0) {
|
||||||
this.currentCommand = this.commands [0];
|
this.currentCommand = this.commands [0];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue