diff --git a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue index a3bbcaff76..69831e6bc1 100644 --- a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue +++ b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue @@ -1218,14 +1218,17 @@ if (res.protocol === 'HTTP') { if ((props.step?.copyFromStepId || props.step?.refType === ScenarioStepRefType.COPY) && props.step?.isNew) { // 复制的步骤需要复制文件 - copyStepFileIdsMap.value = await scenarioCopyStepFiles({ - copyFromStepId: props.step?.copyFromStepId, - resourceId: props.step?.resourceId, - stepType: props.step?.stepType, - refType: props.step?.refType, - isTempFile: false, // 复制未保存的步骤时 true - fileIds: parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds, - }); + const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + copyStepFileIdsMap.value = await scenarioCopyStepFiles({ + copyFromStepId: props.step?.copyFromStepId, + resourceId: props.step?.resourceId, + stepType: props.step?.stepType, + refType: props.step?.refType, + isTempFile: false, // 复制未保存的步骤时 true + fileIds, + }); + } parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); } else { parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 diff --git a/frontend/src/views/api-test/scenario/components/common/customCaseDrawer.vue b/frontend/src/views/api-test/scenario/components/common/customCaseDrawer.vue index e4a93e24eb..a609032ed6 100644 --- a/frontend/src/views/api-test/scenario/components/common/customCaseDrawer.vue +++ b/frontend/src/views/api-test/scenario/components/common/customCaseDrawer.vue @@ -269,7 +269,12 @@ import { getPluginScript, getProtocolList } from '@/api/modules/api-test/common'; 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 { characterLimit } from '@/utils'; import { scrollIntoView } from '@/utils/dom'; @@ -400,6 +405,7 @@ errorMessageInfo: {}, }; const requestVModel = ref(defaultApiParams); + const copyStepFileIdsMap = ref>({}); const _stepType = computed(() => { if (activeStep.value) { return getStepType(activeStep.value); @@ -799,7 +805,8 @@ requestVModel.value.body, undefined, 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 = { @@ -989,7 +996,26 @@ const res = await getCaseDetail(activeStep.value?.resourceId || ''); let parseRequestBodyResult; 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 = { responseActiveTab: ResponseComposition.BODY, diff --git a/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue b/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue index 37e0541f93..d54cee9bda 100644 --- a/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue +++ b/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue @@ -289,6 +289,7 @@ originProjectId: node.projectId, id: node.isQuoteScenarioStep ? node.id : id, // 引用场景下的步骤 id 不变,其他情况的步骤生成新的 id uniqueId: id, + isNew: true, }; }); } else { diff --git a/frontend/src/views/api-test/scenario/components/step/stepTree.vue b/frontend/src/views/api-test/scenario/components/step/stepTree.vue index 8aeb53e63e..b932702498 100644 --- a/frontend/src/views/api-test/scenario/components/step/stepTree.vue +++ b/frontend/src/views/api-test/scenario/components/step/stepTree.vue @@ -943,14 +943,17 @@ if (node.config.protocol === 'HTTP' && (stepDetail as RequestParam)?.body) { if (node.copyFromStepId || node.refType === ScenarioStepRefType.COPY) { // 复制的步骤需要复制文件 - newFileRes = await scenarioCopyStepFiles({ - copyFromStepId, - resourceId: node.resourceId, - stepType: node.stepType, - refType: node.refType, - isTempFile: !!stepDetail, // 复制未保存的步骤时 true - fileIds: parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds, - }); + const fileIds = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + newFileRes = await scenarioCopyStepFiles({ + copyFromStepId, + resourceId: node.resourceId, + stepType: node.stepType, + refType: node.refType, + isTempFile: !!stepDetail, // 复制未保存的步骤时 true + fileIds, + }); + } parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); } else { parseRequestBodyResult = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 diff --git a/frontend/src/views/api-test/scenario/components/step/useStepOperation.ts b/frontend/src/views/api-test/scenario/components/step/useStepOperation.ts index 502fb5beaf..af495144b2 100644 --- a/frontend/src/views/api-test/scenario/components/step/useStepOperation.ts +++ b/frontend/src/views/api-test/scenario/components/step/useStepOperation.ts @@ -68,14 +68,17 @@ export default function useStepOperation({ if (step.config.protocol === 'HTTP' && res.body) { if ((step.copyFromStepId || step.refType === ScenarioStepRefType.COPY) && step.isNew) { // 复制的步骤需要复制文件 - newFileRes = await scenarioCopyStepFiles({ - copyFromStepId: step.copyFromStepId, - resourceId: step.resourceId, - stepType: step.stepType, - refType: step.refType, - isTempFile: false, // 复制未保存的步骤时 true - fileIds: parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds, - }); + const fileIds = parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + newFileRes = await scenarioCopyStepFiles({ + copyFromStepId: step.copyFromStepId, + resourceId: step.resourceId, + stepType: step.stepType, + refType: step.refType, + isTempFile: false, // 复制未保存的步骤时 true + fileIds, + }); + } parseRequestBodyFiles(res.body, [], [], [], newFileRes); } else { parseRequestBodyResult = parseRequestBodyFiles(res.body, [], [], [], newFileRes); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件