diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java index b32bf2d04d..869a6f85b9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java @@ -647,13 +647,16 @@ public class ApiScenarioDataTransferService { } } }); - List apiTestCaseWithBlobs = extApiTestCaseMapper.selectAllDetailByApiIds(apiCaseIdList); + List apiTestCaseWithBlobs = null; if (CollectionUtils.isNotEmpty(apiCaseIdList)) { - apiTestCaseWithBlobs.forEach(item -> { - if (!apiDefinitionIdList.contains(item.getApiDefinitionId())) { - apiDefinitionIdList.add(item.getApiDefinitionId()); - } - }); + apiTestCaseWithBlobs = extApiTestCaseMapper.selectAllDetailByApiIds(apiCaseIdList); + if (CollectionUtils.isNotEmpty(apiCaseIdList)) { + apiTestCaseWithBlobs.forEach(item -> { + if (!apiDefinitionIdList.contains(item.getApiDefinitionId())) { + apiDefinitionIdList.add(item.getApiDefinitionId()); + } + }); + } } Map> projectApiModuleIdMap = new HashMap<>(); diff --git a/frontend/src/api/modules/api-test/scenario.ts b/frontend/src/api/modules/api-test/scenario.ts index 3a6d9e8aad..8077a1ec60 100644 --- a/frontend/src/api/modules/api-test/scenario.ts +++ b/frontend/src/api/modules/api-test/scenario.ts @@ -1,6 +1,7 @@ import type { CaseLevel } from '@/components/business/ms-case-associate/types'; import MSR from '@/api/http/index'; +import { ExportDefinitionUrl, StopApiExportUrl } from '@/api/requrls/api-test/management'; import { AddModuleUrl, AddScenarioUrl, @@ -19,6 +20,7 @@ import { ExecuteScenarioUrl, ExportScenarioUrl, FollowScenarioUrl, + GetExportScenarioFileUrl, GetModuleCountUrl, GetModuleTreeUrl, GetScenarioBatchExportParamsUrl, @@ -44,6 +46,7 @@ import { ScenarioTransferModuleOptionsUrl, ScenarioTrashPageUrl, ScenarioUploadTempFileUrl, + StopExportScenarioUrl, UpdateModuleUrl, UpdateScenarioPriorityUrl, UpdateScenarioStatusUrl, @@ -51,6 +54,7 @@ import { } from '@/api/requrls/api-test/scenario'; import { ExecuteConditionProcessor } from '@/models/apiTest/common'; +import type { ApiDefinitionBatchExportParams } from '@/models/apiTest/management'; import { ApiScenarioBatchDeleteParams, ApiScenarioBatchEditParams, @@ -341,6 +345,22 @@ export function importScenario(params: ImportScenarioParams) { } // 导出场景 -export function exportScenario(data: ExportScenarioParams) { - return MSR.post({ url: ExportScenarioUrl, data }); +export function exportScenario(data: ExportScenarioParams, type: string) { + return MSR.post({ url: `${ExportScenarioUrl}/${type}`, data }); +} + +// 停止导出场景 +export function stopScenarioExport(taskId: string) { + return MSR.get({ url: `${StopExportScenarioUrl}/${taskId}` }); +} + +// 获取导出的文件 +export function getScenarioDownloadFile(projectId: string, fileId: string) { + return MSR.get( + { + url: `${GetExportScenarioFileUrl}/${projectId}/${fileId}`, + responseType: 'blob', + }, + { isTransformResponse: false } + ); } diff --git a/frontend/src/api/requrls/api-test/scenario.ts b/frontend/src/api/requrls/api-test/scenario.ts index 74a669d21d..950089f6ca 100644 --- a/frontend/src/api/requrls/api-test/scenario.ts +++ b/frontend/src/api/requrls/api-test/scenario.ts @@ -28,9 +28,11 @@ export const BatchEditScenarioUrl = '/api/scenario/batch-operation/edit'; // 批 export const BatchRunScenarioUrl = '/api/scenario/batch-operation/run'; // 批量执行接口场景 export const UpdateScenarioPriorityUrl = '/api/scenario/update-priority'; // 场景更新等级 export const UpdateScenarioStatusUrl = '/api/scenario/update-status'; // 场景更新状态 +// 场景导入导出相关 export const ImportScenarioUrl = '/api/scenario/import'; // 导入场景 -export const ExportScenarioUrl = '/api/scenario/export'; // 导入场景 - +export const ExportScenarioUrl = '/api/scenario/export'; // 导出场景 +export const StopExportScenarioUrl = '/api/scenario/stop'; +export const GetExportScenarioFileUrl = '/api/scenario/download/file'; // 场景拖拽排序 export const dragSortUrl = '/api/scenario/edit/pos'; // 回收站相关 diff --git a/frontend/src/enums/apiEnum.ts b/frontend/src/enums/apiEnum.ts index c7c7683925..a31e21d345 100644 --- a/frontend/src/enums/apiEnum.ts +++ b/frontend/src/enums/apiEnum.ts @@ -256,6 +256,12 @@ export enum ScenarioExecuteStatus { UN_EXECUTE = 'UN_EXECUTE', FAKE_ERROR = 'FAKE_ERROR', } + +// 场景导出配置 +export enum ScenarioExportType { + SIMPLE = 'METERSPHERE_SIMPLE', + ALL = 'METERSPHERE_ALL_DATA', +} // 场景步骤类型 export enum ScenarioStepType { API_CASE = 'API_CASE', // 接口用例 diff --git a/frontend/src/views/api-test/management/components/management/api/apiExportModal.vue b/frontend/src/views/api-test/management/components/management/api/apiExportModal.vue index bff03b04d6..a96239aea8 100644 --- a/frontend/src/views/api-test/management/components/management/api/apiExportModal.vue +++ b/frontend/src/views/api-test/management/components/management/api/apiExportModal.vue @@ -108,7 +108,7 @@ async function downloadFile(id: string) { try { const response = await getApiDownload.value(appStore.currentProjectId, id); - downloadByteFile(response, 'metersphere-export.json'); + downloadByteFile(response, 'metersphere-definition.zip'); } catch (error) { // eslint-disable-next-line no-console console.log(error); diff --git a/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue b/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue new file mode 100644 index 0000000000..d9b4981b94 --- /dev/null +++ b/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue @@ -0,0 +1,221 @@ + + + + + diff --git a/frontend/src/views/api-test/scenario/components/scenarioTable.vue b/frontend/src/views/api-test/scenario/components/scenarioTable.vue index cd118055d3..a7f3cf3ca8 100644 --- a/frontend/src/views/api-test/scenario/components/scenarioTable.vue +++ b/frontend/src/views/api-test/scenario/components/scenarioTable.vue @@ -465,6 +465,13 @@ is-scenario :report-id="tableRecord?.lastReportId || ''" /> + +