feat(接口测试): 导入场景请求时场景子步骤复制文件

This commit is contained in:
baiqi 2024-12-09 18:02:00 +08:00 committed by Craftsman
parent 3f476afcdc
commit 06cd4cc317
5 changed files with 63 additions and 27 deletions

View File

@ -1218,14 +1218,17 @@
if (res.protocol === 'HTTP') { if (res.protocol === 'HTTP') {
if ((props.step?.copyFromStepId || props.step?.refType === ScenarioStepRefType.COPY) && props.step?.isNew) { if ((props.step?.copyFromStepId || props.step?.refType === ScenarioStepRefType.COPY) && props.step?.isNew) {
// //
copyStepFileIdsMap.value = await scenarioCopyStepFiles({ const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds;
copyFromStepId: props.step?.copyFromStepId, if (fileIds.length > 0) {
resourceId: props.step?.resourceId, copyStepFileIdsMap.value = await scenarioCopyStepFiles({
stepType: props.step?.stepType, copyFromStepId: props.step?.copyFromStepId,
refType: props.step?.refType, resourceId: props.step?.resourceId,
isTempFile: false, // true stepType: props.step?.stepType,
fileIds: parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds, refType: props.step?.refType,
}); isTempFile: false, // true
fileIds,
});
}
parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value);
} else { } else {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // id parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // id

View File

@ -269,7 +269,12 @@
import { getPluginScript, getProtocolList } from '@/api/modules/api-test/common'; import { getPluginScript, getProtocolList } from '@/api/modules/api-test/common';
import { getCaseDetail } from '@/api/modules/api-test/management'; import { getCaseDetail } from '@/api/modules/api-test/management';
import { getTransferOptions, stepTransferFile, uploadTempFile } from '@/api/modules/api-test/scenario'; import {
getTransferOptions,
scenarioCopyStepFiles,
stepTransferFile,
uploadTempFile,
} from '@/api/modules/api-test/scenario';
import { useAppStore } from '@/store'; import { useAppStore } from '@/store';
import { characterLimit } from '@/utils'; import { characterLimit } from '@/utils';
import { scrollIntoView } from '@/utils/dom'; import { scrollIntoView } from '@/utils/dom';
@ -400,6 +405,7 @@
errorMessageInfo: {}, errorMessageInfo: {},
}; };
const requestVModel = ref<RequestParam>(defaultApiParams); const requestVModel = ref<RequestParam>(defaultApiParams);
const copyStepFileIdsMap = ref<Record<string, any>>({});
const _stepType = computed(() => { const _stepType = computed(() => {
if (activeStep.value) { if (activeStep.value) {
return getStepType(activeStep.value); return getStepType(activeStep.value);
@ -799,7 +805,8 @@
requestVModel.value.body, requestVModel.value.body,
undefined, undefined,
props.fileParams?.uploadFileIds || requestVModel.value.uploadFileIds, // case requestVModel props.fileParams?.uploadFileIds || requestVModel.value.uploadFileIds, // case requestVModel
props.fileParams?.linkFileIds || requestVModel.value.linkFileIds // case requestVModel props.fileParams?.linkFileIds || requestVModel.value.linkFileIds, // case requestVModel
copyStepFileIdsMap.value
); );
} }
requestParams = { requestParams = {
@ -989,7 +996,26 @@
const res = await getCaseDetail(activeStep.value?.resourceId || ''); const res = await getCaseDetail(activeStep.value?.resourceId || '');
let parseRequestBodyResult; let parseRequestBodyResult;
if (res.protocol === 'HTTP') { if (res.protocol === 'HTTP') {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body); // id if (
(activeStep.value?.copyFromStepId || activeStep.value?.refType === ScenarioStepRefType.COPY) &&
activeStep.value?.isNew
) {
//
const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
copyStepFileIdsMap.value = await scenarioCopyStepFiles({
copyFromStepId: activeStep.value?.copyFromStepId,
resourceId: activeStep.value?.resourceId,
stepType: activeStep.value?.stepType,
refType: activeStep.value?.refType,
isTempFile: false, // true
fileIds,
});
}
parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value);
} else {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // id
}
} }
requestVModel.value = { requestVModel.value = {
responseActiveTab: ResponseComposition.BODY, responseActiveTab: ResponseComposition.BODY,

View File

@ -289,6 +289,7 @@
originProjectId: node.projectId, originProjectId: node.projectId,
id: node.isQuoteScenarioStep ? node.id : id, // id id id: node.isQuoteScenarioStep ? node.id : id, // id id
uniqueId: id, uniqueId: id,
isNew: true,
}; };
}); });
} else { } else {

View File

@ -943,14 +943,17 @@
if (node.config.protocol === 'HTTP' && (stepDetail as RequestParam)?.body) { if (node.config.protocol === 'HTTP' && (stepDetail as RequestParam)?.body) {
if (node.copyFromStepId || node.refType === ScenarioStepRefType.COPY) { if (node.copyFromStepId || node.refType === ScenarioStepRefType.COPY) {
// //
newFileRes = await scenarioCopyStepFiles({ const fileIds = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds;
copyFromStepId, if (fileIds.length > 0) {
resourceId: node.resourceId, newFileRes = await scenarioCopyStepFiles({
stepType: node.stepType, copyFromStepId,
refType: node.refType, resourceId: node.resourceId,
isTempFile: !!stepDetail, // true stepType: node.stepType,
fileIds: parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds, refType: node.refType,
}); isTempFile: !!stepDetail, // true
fileIds,
});
}
parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes);
} else { } else {
parseRequestBodyResult = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); // id parseRequestBodyResult = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); // id

View File

@ -68,14 +68,17 @@ export default function useStepOperation({
if (step.config.protocol === 'HTTP' && res.body) { if (step.config.protocol === 'HTTP' && res.body) {
if ((step.copyFromStepId || step.refType === ScenarioStepRefType.COPY) && step.isNew) { if ((step.copyFromStepId || step.refType === ScenarioStepRefType.COPY) && step.isNew) {
// 复制的步骤需要复制文件 // 复制的步骤需要复制文件
newFileRes = await scenarioCopyStepFiles({ const fileIds = parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds;
copyFromStepId: step.copyFromStepId, if (fileIds.length > 0) {
resourceId: step.resourceId, newFileRes = await scenarioCopyStepFiles({
stepType: step.stepType, copyFromStepId: step.copyFromStepId,
refType: step.refType, resourceId: step.resourceId,
isTempFile: false, // 复制未保存的步骤时 true stepType: step.stepType,
fileIds: parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds, refType: step.refType,
}); isTempFile: false, // 复制未保存的步骤时 true
fileIds,
});
}
parseRequestBodyFiles(res.body, [], [], [], newFileRes); parseRequestBodyFiles(res.body, [], [], [], newFileRes);
} else { } else {
parseRequestBodyResult = parseRequestBodyFiles(res.body, [], [], [], newFileRes); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 parseRequestBodyResult = parseRequestBodyFiles(res.body, [], [], [], newFileRes); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件