From 8a60a57102896ccbe4d7dd2bedcf5abda2c18b2a Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Tue, 25 Aug 2020 16:05:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E8=BF=90=E8=A1=8Cuuid=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/api/test/OneClickOperation.vue | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/frontend/src/business/components/api/test/OneClickOperation.vue b/frontend/src/business/components/api/test/OneClickOperation.vue index 427601e1ac..7a1b3285bd 100644 --- a/frontend/src/business/components/api/test/OneClickOperation.vue +++ b/frontend/src/business/components/api/test/OneClickOperation.vue @@ -26,6 +26,7 @@ import MsApiScenarioConfig from "./components/ApiScenarioConfig"; import MsApiReportStatus from "../report/ApiReportStatus"; import MsApiReportDialog from "./ApiReportDialog"; + import {getUUID} from "../../../../common/js/utils"; export default { @@ -116,7 +117,6 @@ let item = response.data; this.tests.push(item); let test = new Test({ - id: item.id, projectId: item.projectId, name: this.ruleForm.testName, scenarioDefinition: JSON.parse(item.scenarioDefinition), @@ -142,10 +142,36 @@ save(callback) { this.change = false; let url = "/api/create"; - this.result = this.$request(this.getOptions(url), () => { + let bodyFiles = this.getBodyUploadFiles(); + this.result = this.$request(this.getOptions(url, bodyFiles), () => { if (callback) callback(); }); }, + getBodyUploadFiles() { + let bodyUploadFiles = []; + this.test.bodyUploadIds = []; + this.test.scenarioDefinition.forEach(scenario => { + scenario.requests.forEach(request => { + if (request.body) { + request.body.kvs.forEach(param => { + if (param.files) { + param.files.forEach(item => { + if (item.file) { + let fileId = getUUID().substring(0, 8); + item.name = item.file.name; + item.id = fileId; + this.test.bodyUploadIds.push(fileId); + bodyUploadFiles.push(item.file); + // item.file = undefined; + } + }); + } + }); + } + }); + }); + return bodyUploadFiles; + }, runTest() { this.result = this.$post("/api/run", {id: this.test.id, triggerMode: 'MANUAL'}, (response) => { this.$success(this.$t('api_test.running')); @@ -155,12 +181,19 @@ this.test = "" }); }, - getOptions(url) { + getOptions(url, bodyFiles) { + let formData = new FormData(); + if (bodyFiles) { + bodyFiles.forEach(f => { + formData.append("files", f); + }) + } let requestJson = JSON.stringify(this.test); formData.append('request', new Blob([requestJson], { type: "application/json" })); + let jmx = this.test.toJMX(); let blob = new Blob([jmx.xml], {type: "application/octet-stream"}); formData.append("file", new File([blob], jmx.name));