fix: 接口测试文件上传失败

This commit is contained in:
chenjianxing 2021-01-18 11:12:28 +08:00
parent b024c5da54
commit c53687d37d
4 changed files with 58 additions and 72 deletions

View File

@ -24,6 +24,10 @@
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced==='Deleted'" type="danger">{{$t('api_test.automation.reference_deleted')}}</el-tag>
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</template>
<template v-slot:button>
@ -56,9 +60,6 @@
{{$t('commons.save')}}
</el-button>
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</api-base-component>
</template>

View File

@ -1,5 +1,5 @@
<template>
<div></div>
<span></span>
</template>
<script>
import {getUUID, getBodyUploadFiles} from "@/common/js/utils";

View File

@ -92,7 +92,7 @@
</template>
<script>
import {getCurrentProjectID, getUUID} from "../../../../../../common/js/utils";
import {_getBodyUploadFiles, getCurrentProjectID, getUUID} from "../../../../../../common/js/utils";
import {PRIORITY, RESULT_MAP} from "../../model/JsonData";
import MsTag from "../../../../common/components/MsTag";
import MsTipButton from "../../../../common/components/MsTipButton";
@ -223,6 +223,7 @@
if (this.validate(tmp)) {
return;
}
tmp.request.body = row.request.body;
let bodyFiles = this.getBodyUploadFiles(tmp);
tmp.projectId = getCurrentProjectID();
tmp.active = true;
@ -278,37 +279,7 @@
getBodyUploadFiles(row) {
let bodyUploadFiles = [];
row.bodyUploadIds = [];
let request = row.request;
if (request.body && request.body.kvs) {
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;
row.bodyUploadIds.push(fileId);
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.binary) {
request.body.binary.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;
row.bodyUploadIds.push(fileId);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
_getBodyUploadFiles(row.request, bodyUploadFiles, row);
return bodyUploadFiles;
},
}

View File

@ -303,42 +303,56 @@ export function getBodyUploadFiles(obj, runData) {
let bodyUploadFiles = [];
obj.bodyUploadIds = [];
if (runData) {
runData.forEach(request => {
if (request.body) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
});
if (runData instanceof Array) {
runData.forEach(request => {
_getBodyUploadFiles(request, bodyUploadFiles, obj);
});
} else {
_getBodyUploadFiles(runData, bodyUploadFiles, obj);
}
}
return bodyUploadFiles;
}
export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
let body = null;
if (request.hashTree && request.hashTree.length > 0 && request.hashTree[0].body) {
body = request.hashTree[0].body;
} else if (request.body) {
body = request.body;
}
if (body) {
body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
if (body.binary) {
body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
}