From e181a4867c6608879f3ffb63037d5359624dd07c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 28 Jul 2020 19:16:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20post=20=E8=AF=B7=E6=B1=82=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=82=E6=95=B0=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/dto/scenario/Body.java | 1 + .../api/report/components/ResponseText.vue | 6 ++- .../api/test/components/ApiBody.vue | 43 ++++++++++++++++--- .../api/test/model/ScenarioModel.js | 37 ++++++++++++++++ .../common/components/MsCodeEdit.vue | 29 +++++++++---- .../common/components/MsDropdown.vue | 7 ++- 6 files changed, 105 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java index 63db961c19..5073eeefbf 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java @@ -8,5 +8,6 @@ import java.util.List; public class Body { private String type; private String raw; + private String format; private List kvs; } diff --git a/frontend/src/business/components/api/report/components/ResponseText.vue b/frontend/src/business/components/api/report/components/ResponseText.vue index 66430091f1..50d49ded36 100644 --- a/frontend/src/business/components/api/report/components/ResponseText.vue +++ b/frontend/src/business/components/api/report/components/ResponseText.vue @@ -7,7 +7,7 @@ - +
{{response.headers}}
@@ -31,6 +31,7 @@ import MsAssertionResults from "./AssertionResults"; import MsCodeEdit from "../../../common/components/MsCodeEdit"; import MsDropdown from "../../../common/components/MsDropdown"; + import {BODY_FORMAT} from "../../test/model/ScenarioModel"; export default { name: "MsResponseText", @@ -50,6 +51,7 @@ isActive: false, activeName: "body", modes: ['text', 'json', 'xml', 'html'], + mode: BODY_FORMAT.TEXT } }, @@ -58,7 +60,7 @@ this.isActive = !this.isActive; }, modeChange(mode) { - this.$refs.codeEdit.setMode(mode); + this.mode = mode; } }, } diff --git a/frontend/src/business/components/api/test/components/ApiBody.vue b/frontend/src/business/components/api/test/components/ApiBody.vue index 6a5a2a4764..64dad3d17a 100644 --- a/frontend/src/business/components/api/test/components/ApiBody.vue +++ b/frontend/src/business/components/api/test/components/ApiBody.vue @@ -9,20 +9,26 @@ + + - +
+ +
+ @@ -51,4 +65,19 @@ .textarea { margin-top: 10px; } + + .body-raw { + padding: 15px 0; + height: 300px; + } + + .el-dropdown { + margin-left: 20px; + line-height: 30px; + } + + .ace_editor { + border-radius: 5px; + } + diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 95fae6b585..5d18b5b69b 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -37,6 +37,13 @@ export const BODY_TYPE = { RAW: "Raw" } +export const BODY_FORMAT = { + TEXT: "text", + JSON: "json", + XML: "xml", + HTML: "html", +} + export const ASSERTION_TYPE = { TEXT: "Text", REGEX: "Regex", @@ -820,12 +827,42 @@ class JMXGenerator { addRequestHeader(httpSamplerProxy, request) { let name = request.name + " Headers"; + this.addBodyFormat(request); let headers = this.filterKV(request.headers); if (headers.length > 0) { 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) { let args = this.filterKV(request.parameters); if (args.length > 0) { diff --git a/frontend/src/business/components/common/components/MsCodeEdit.vue b/frontend/src/business/components/common/components/MsCodeEdit.vue index 72d241925d..23b5516cf9 100644 --- a/frontend/src/business/components/common/components/MsCodeEdit.vue +++ b/frontend/src/business/components/common/components/MsCodeEdit.vue @@ -8,7 +8,6 @@ components: { editor: require('vue2-ace-editor')}, data() { return { - mode: 'text', formatData: '' } }, @@ -25,6 +24,12 @@ return false; } }, + mode: { + type: String, + default() { + return 'text'; + } + }, modes: { type: Array, default() { @@ -35,6 +40,14 @@ mounted() { this.format(); }, + watch: { + formatData() { + this.$emit('update:data', this.formatData); + }, + mode() { + this.format(); + } + }, methods: { editorInit: function (editor) { require('brace/ext/language_tools') //language extension prerequsite... @@ -51,19 +64,19 @@ } }, format() { - if (this.mode === 'json') { + if (this.mode === 'json' && this.readOnly) { try { this.formatData = JSON.stringify(JSON.parse(this.data), null, '\t'); } catch (e) { - this.formatData = this.data; + if (this.data) { + this.formatData = this.data; + } } } else { - this.formatData = this.data; + if (this.data) { + this.formatData = this.data; + } } - }, - setMode(mode) { - this.mode = mode; - this.format(); } } } diff --git a/frontend/src/business/components/common/components/MsDropdown.vue b/frontend/src/business/components/common/components/MsDropdown.vue index 89ff33d490..202ae36c94 100644 --- a/frontend/src/business/components/common/components/MsDropdown.vue +++ b/frontend/src/business/components/common/components/MsDropdown.vue @@ -25,10 +25,15 @@ props: { commands: { type: Array + }, + defaultCommand: { + type: String } }, 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]; } },