From 0457508be6239cd1ddde7dfd3bb5fa0439cec297 Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 10 Dec 2024 10:41:10 +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 --- .../src/api/modules/api-test/management.ts | 56 ++++++++++++------- .../src/api/requrls/api-test/management.ts | 12 ++-- frontend/src/models/apiTest/management.ts | 6 ++ .../components/management/api/index.vue | 12 +++- .../case/createAndEditCaseDrawer.vue | 20 ++++++- 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/frontend/src/api/modules/api-test/management.ts b/frontend/src/api/modules/api-test/management.ts index 46dcb22534..51e73f5d1b 100644 --- a/frontend/src/api/modules/api-test/management.ts +++ b/frontend/src/api/modules/api-test/management.ts @@ -22,6 +22,7 @@ import { BatchUpdateDefinitionUrl, CaseBatchExportLogUrl, CaseExportLogUrl, + CaseFileCopyUrl, CasePageUrl, CaseStatisticsUrl, caseTableBatchSyncUrl, @@ -32,6 +33,7 @@ import { CopyMockUrl, DebugCaseUrl, DebugDefinitionUrl, + DefinitionFileCopyUrl, DefinitionMockPageUrl, DefinitionPageUrl, DefinitionReferenceUrl, @@ -144,6 +146,7 @@ import { CheckScheduleParams, CheckSharePsdType, CreateImportApiDefinitionScheduleParams, + type DefinitionFileCopyParams, DefinitionHistoryItem, DefinitionHistoryPageParams, DefinitionReferencePageParams, @@ -364,25 +367,10 @@ export function convertJsonSchemaToJson(data: JsonSchema) { export function jsonSchemaAutoGenerate(data: JsonSchema) { return MSR.post({ url: JsonSchemaAutoGenerateUrl, data }); } -// 接口定义-用例接口对比-清除本次变更 -export function clearThisChange(id: string) { - return MSR.get({ url: `${clearThisChangeUrl}/${id}` }); -} -// 接口定义-用例接口对比-忽略每次变更 -export function ignoreEveryTimeChange(id: string, ignore: boolean) { - return MSR.get({ url: `${ignoreEveryTimeApiChangeUrl}/${id}`, params: { ignore } }); -} -// 接口测试-接口管理-接口用例-批量同步编辑 -export function caseTableBatchSync(data: TableQueryParams) { - return MSR.post({ url: caseTableBatchSyncUrl, data }); -} -// 接口测试-接口用例-定义对比用例 -export function diffDataRequest(id: string) { - return MSR.get({ url: `${diffDataUrl}/${id}` }); -} -// 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情 -export function getSyncedCaseDetail(data: diffSyncParams) { - return MSR.post({ url: getSyncedCaseDetailUrl, data }); + +// 接口定义-文件复制 +export function definitionFileCopy(data: DefinitionFileCopyParams) { + return MSR.post({ url: DefinitionFileCopyUrl, data }); } /** @@ -566,6 +554,36 @@ export function runCase(data: ExecuteRequestParams) { return MSR.post({ url: RunCaseUrl, data }); } +// 接口定义-用例接口对比-清除本次变更 +export function clearThisChange(id: string) { + return MSR.get({ url: `${clearThisChangeUrl}/${id}` }); +} + +// 接口定义-用例接口对比-忽略每次变更 +export function ignoreEveryTimeChange(id: string, ignore: boolean) { + return MSR.get({ url: `${ignoreEveryTimeApiChangeUrl}/${id}`, params: { ignore } }); +} + +// 接口测试-接口管理-接口用例-批量同步编辑 +export function caseTableBatchSync(data: TableQueryParams) { + return MSR.post({ url: caseTableBatchSyncUrl, data }); +} + +// 接口测试-接口用例-定义对比用例 +export function diffDataRequest(id: string) { + return MSR.get({ url: `${diffDataUrl}/${id}` }); +} + +// 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情 +export function getSyncedCaseDetail(data: diffSyncParams) { + return MSR.post({ url: getSyncedCaseDetailUrl, data }); +} + +// 接口用例-文件复制 +export function caseFileCopy(data: DefinitionFileCopyParams) { + return MSR.post({ url: CaseFileCopyUrl, data }); +} + /** * 接口用例回收站 */ diff --git a/frontend/src/api/requrls/api-test/management.ts b/frontend/src/api/requrls/api-test/management.ts index 742b64f277..a46a8f20dd 100644 --- a/frontend/src/api/requrls/api-test/management.ts +++ b/frontend/src/api/requrls/api-test/management.ts @@ -40,11 +40,7 @@ export const RecoverOperationHistoryUrl = '/api/definition/operation-history/rec export const DefinitionReferenceUrl = '/api/definition/get-reference'; // 获取接口引用关系 export const ConvertJsonSchemaToJsonUrl = '/api/definition/json-schema/preview'; // 将json-schema转换为 json 数据 export const JsonSchemaAutoGenerateUrl = '/api/definition/json-schema/auto-generate'; // 将json-schema转换为 json 数据 -export const clearThisChangeUrl = '/api/case/api-change/clear'; // 接口定义-变更对比-清除本次变更 -export const caseTableBatchSyncUrl = '/api/case/batch/api-change/sync'; // 接口测试-接口管理-接口用例-批量同步 -export const ignoreEveryTimeApiChangeUrl = '/api/case/api-change/ignore'; // 接口测试-接口用例-忽略每次接口变更 -export const diffDataUrl = '/api/case/api/compare'; // 接口测试-接口用例-定义对比用例 -export const getSyncedCaseDetailUrl = '/api/case/api-change/sync'; // 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情 +export const DefinitionFileCopyUrl = '/api/definition/file/copy'; // 接口文件复制 /** * Mock @@ -101,6 +97,12 @@ export const CaseExportLogUrl = '/api/report/case/export'; // 接口用例导出 export const CaseBatchExportLogUrl = '/api/report/case/batch-export'; // 接口用例批量导出报告日志记录 export const GetCaseBatchExportParamsUrl = '/api/report/case/batch-param'; // 接口用例批量导出报告id集合 export const CaseStatisticsUrl = '/api/case/statistics'; // 用例执行率统计 +export const getSyncedCaseDetailUrl = '/api/case/api-change/sync'; // 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情 +export const clearThisChangeUrl = '/api/case/api-change/clear'; // 接口定义-变更对比-清除本次变更 +export const caseTableBatchSyncUrl = '/api/case/batch/api-change/sync'; // 接口测试-接口管理-接口用例-批量同步 +export const ignoreEveryTimeApiChangeUrl = '/api/case/api-change/ignore'; // 接口测试-接口用例-忽略每次接口变更 +export const diffDataUrl = '/api/case/api/compare'; // 接口测试-接口用例-定义对比用例 +export const CaseFileCopyUrl = '/api/case/file/copy'; // 接口用例文件复制 /** * 接口用例回收站 diff --git a/frontend/src/models/apiTest/management.ts b/frontend/src/models/apiTest/management.ts index 3891a7f5d7..28f2328106 100644 --- a/frontend/src/models/apiTest/management.ts +++ b/frontend/src/models/apiTest/management.ts @@ -288,6 +288,12 @@ export interface DefinitionReferencePageParams extends TableQueryParams { resourceId: string; } +// 定义-复制文件参数 +export interface DefinitionFileCopyParams { + resourceId: string; + fileIds: string[]; +} + // 回收站-恢复接口定义参数 export interface ApiDefinitionDeleteParams { id: string; 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 5dbafdcca4..e4c0853269 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 @@ -123,6 +123,7 @@ import { addDefinition, debugDefinition, + definitionFileCopy, deleteDefinition, getDefinitionDetail, getTransferOptions, @@ -376,7 +377,16 @@ } let parseRequestBodyResult; if (res.protocol === 'HTTP') { - parseRequestBodyResult = parseRequestBodyFiles(res.request.body, res.response); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 + // 复制的步骤需要复制文件 + let copyFilesMap: Record = {}; + const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + copyFilesMap = await definitionFileCopy({ + resourceId: typeof apiInfo === 'string' ? apiInfo : apiInfo.id, + fileIds, + }); + } + 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 e990f45a3d..81cfbc5d3b 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 @@ -116,6 +116,7 @@ import { localExecuteApiDebug } from '@/api/modules/api-test/common'; import { addCase, + caseFileCopy, debugCase, getDefinitionDetail, getTransferOptionsCase, @@ -134,6 +135,7 @@ import { RequestCaseStatus, RequestMethods } from '@/enums/apiEnum'; import { casePriorityOptions, defaultResponse } from '@/views/api-test/components/config'; + import { parseRequestBodyFiles } from '@/views/api-test/components/utils'; const props = defineProps<{ apiDetail?: RequestParam | ApiDefinitionDetail; @@ -236,9 +238,25 @@ : apiDetailInfo.value), children: apiDetailInfo.value.children ?? apiDetailInfo.value.request.children, }; + let parseRequestBodyResult; // 复制 if (isCopy) { - detailForm.value = cloneDeep(record as RequestParam); + if (record?.protocol === 'HTTP') { + // 复制的步骤需要复制文件 + let copyFilesMap: Record = {}; + const fileIds = parseRequestBodyFiles(record.request.body, [], [], []).uploadFileIds; + if (fileIds.length > 0) { + copyFilesMap = await caseFileCopy({ + resourceId: record.id as string, + fileIds, + }); + } + parseRequestBodyResult = parseRequestBodyFiles(record.request.body, [], [], [], copyFilesMap); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 + detailForm.value = { + ...cloneDeep(record as RequestParam), + ...parseRequestBodyResult, + }; + } detailForm.value.name = `copy_${record?.name}`; detailForm.value.isCopy = true; environmentId.value = record?.environmentId ?? environmentId.value;