From 598bcadf94b2fb19c975d3d278c275f904362a93 Mon Sep 17 00:00:00 2001 From: baiqi Date: Fri, 13 Dec 2024 14:42:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3&=E7=94=A8=E4=BE=8B=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/management/api/index.vue | 6 ++++-- .../case/createAndEditCaseDrawer.vue | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/api-test/management/components/management/api/index.vue b/frontend/src/views/api-test/management/components/management/api/index.vue index e4c0853269..e926738e84 100644 --- a/frontend/src/views/api-test/management/components/management/api/index.vue +++ b/frontend/src/views/api-test/management/components/management/api/index.vue @@ -380,13 +380,15 @@ // 复制的步骤需要复制文件 let copyFilesMap: Record = {}; const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds; - if (fileIds.length > 0) { + if (fileIds.length > 0 && isCopy) { copyFilesMap = await definitionFileCopy({ resourceId: typeof apiInfo === 'string' ? apiInfo : apiInfo.id, fileIds, }); + parseRequestBodyFiles(res.request.body, res.response, [], [], copyFilesMap); // 替换请求的文件 id + } else { + parseRequestBodyResult = parseRequestBodyFiles(res.request.body, res.response, [], [], copyFilesMap); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 } - parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyFilesMap); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 } let { request } = res; if (isDebugMock) { diff --git a/frontend/src/views/api-test/management/components/management/case/createAndEditCaseDrawer.vue b/frontend/src/views/api-test/management/components/management/case/createAndEditCaseDrawer.vue index 81cfbc5d3b..bb8c81e3e5 100644 --- a/frontend/src/views/api-test/management/components/management/case/createAndEditCaseDrawer.vue +++ b/frontend/src/views/api-test/management/components/management/case/createAndEditCaseDrawer.vue @@ -118,6 +118,7 @@ addCase, caseFileCopy, debugCase, + definitionFileCopy, getDefinitionDetail, getTransferOptionsCase, runCase, @@ -221,6 +222,18 @@ } else { await getApiDetail(); } + if (!isCopy && !record) { + // 创建用例需要复制文件 + let copyFilesMap: Record = {}; + const fileIds = parseRequestBodyFiles(apiDetailInfo.value.request.body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + copyFilesMap = await definitionFileCopy({ + resourceId: apiDetailInfo.value.id as string, + fileIds, + }); + } + parseRequestBodyFiles(apiDetailInfo.value.request.body, [], [], [], copyFilesMap); // 替换请求文件 id + } // 创建的时候,请求参数为接口定义的请求参数 environmentId.value = appStore.currentEnvConfig?.id; detailForm.value = { @@ -238,11 +251,10 @@ : apiDetailInfo.value), children: apiDetailInfo.value.children ?? apiDetailInfo.value.request.children, }; - let parseRequestBodyResult; // 复制 if (isCopy) { if (record?.protocol === 'HTTP') { - // 复制的步骤需要复制文件 + // 复制的用例需要复制文件 let copyFilesMap: Record = {}; const fileIds = parseRequestBodyFiles(record.request.body, [], [], []).uploadFileIds; if (fileIds.length > 0) { @@ -251,10 +263,9 @@ fileIds, }); } - parseRequestBodyResult = parseRequestBodyFiles(record.request.body, [], [], [], copyFilesMap); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 + parseRequestBodyFiles(record.request.body, [], [], [], copyFilesMap); // 替换请求文件 id detailForm.value = { ...cloneDeep(record as RequestParam), - ...parseRequestBodyResult, }; } detailForm.value.name = `copy_${record?.name}`;