diff --git a/frontend/src/api/modules/test-plan/testPlan.ts b/frontend/src/api/modules/test-plan/testPlan.ts index 86c0945ef0..324752b052 100644 --- a/frontend/src/api/modules/test-plan/testPlan.ts +++ b/frontend/src/api/modules/test-plan/testPlan.ts @@ -90,6 +90,7 @@ import { import { ApiCaseDetail, ApiDefinitionDetail } from '@/models/apiTest/management'; import type { ReportDetail, ReportStepDetail } from '@/models/apiTest/report'; +import { BugEditFormObject } from '@/models/bug-management'; import { ReviewUserItem } from '@/models/caseManagement/caseReview'; import type { CaseManagementTable, CreateOrUpdateModule, UpdateModule } from '@/models/caseManagement/featureCase'; import type { CommonList, MoveModules, TableQueryParams } from '@/models/common'; @@ -480,6 +481,6 @@ export function batchAssociatedBugToCase(data: TableQueryParams) { return MSR.post({ url: BatchAssociatedBugToCaseUrl, data }); } // 测试计划-详情-批量新建缺陷 -export function batchAddBugToCase(data: TableQueryParams) { - return MSR.post({ url: BatchAddBugToCaseUrl, data }); +export function batchAddBugToCase(data: { request: BugEditFormObject; fileList: File[] }) { + return MSR.uploadFile({ url: BatchAddBugToCaseUrl }, data, '', true); } diff --git a/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabBug/addDefectDrawer.vue b/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabBug/addDefectDrawer.vue index 85266f8f88..16091684a2 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabBug/addDefectDrawer.vue +++ b/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabBug/addDefectDrawer.vue @@ -49,6 +49,7 @@ import BugDetail from '@/views/bug-management/edit.vue'; import { createOrUpdateBug, getTemplateOption } from '@/api/modules/bug-management'; + import { batchAddBugToCase } from '@/api/modules/test-plan/testPlan'; import { useI18n } from '@/hooks/useI18n'; import { useAppStore } from '@/store'; @@ -64,11 +65,13 @@ const props = defineProps<{ bugId?: string; - extraParams?: Record; + extraParams?: Record | (() => Record); + isBatch?: boolean; }>(); const emit = defineEmits<{ (e: 'success'): void; + (e: 'save', params: { request: BugEditFormObject; fileList: File[] }): void; }>(); const showBugDrawer = defineModel('visible', { @@ -104,7 +107,6 @@ drawerLoading.value = false; } }; - function handleDrawerCancel() { bugDetailRef.value?.resetForm(); showBugDrawer.value = false; @@ -114,7 +116,13 @@ try { drawerLoading.value = true; const { request, fileList } = params; - await createOrUpdateBug({ request: { ...request, ...props.extraParams }, fileList }); + if (props.isBatch) { + const extraParam = + props.extraParams && typeof props.extraParams === 'function' ? await props.extraParams() : props.extraParams; + await batchAddBugToCase({ request: { ...request, ...extraParam }, fileList }); + } else { + await createOrUpdateBug({ request: { ...request, ...props.extraParams }, fileList }); + } Message.success(props.bugId ? t('common.updateSuccess') : t('common.createSuccess')); diff --git a/frontend/src/views/test-plan/testPlan/detail/apiCase/components/caseTable.vue b/frontend/src/views/test-plan/testPlan/detail/apiCase/components/caseTable.vue index 90e6505067..b1a19eb050 100644 --- a/frontend/src/views/test-plan/testPlan/detail/apiCase/components/caseTable.vue +++ b/frontend/src/views/test-plan/testPlan/detail/apiCase/components/caseTable.vue @@ -109,20 +109,20 @@ :batch-move="batchMoveApiCase" @load-list="resetCaseList" /> - + - @@ -672,10 +672,10 @@ const testPlanCaseId = ref(); const existedDefect = inject>('existedDefect', ref(0)); const showCreateBugDrawer = ref(false); - const isBatchAssociate = ref(false); + const isBatchAssociateOrCreate = ref(false); // 关联缺陷 function associateAndCreateDefect(isAssociate: boolean, isBatch: boolean, record?: PlanDetailApiCaseItem) { - isBatchAssociate.value = isBatch; + isBatchAssociateOrCreate.value = isBatch; if (record) { const { id, apiTestCaseId } = record; associatedCaseId.value = apiTestCaseId; @@ -695,7 +695,7 @@ try { drawerLoading.value = true; const tableParams = await getTableParams(true); - if (isBatchAssociate.value) { + if (isBatchAssociateOrCreate.value) { await batchAssociatedBugToCase({ selectIds: tableSelected.value as string[], selectAll: batchParams.value.selectAll, @@ -726,6 +726,21 @@ } } + async function getApiBugParams() { + if (isBatchAssociateOrCreate.value) { + const tableParams = await getTableParams(true); + return { + ...tableParams, + projectId: appStore.currentProjectId, + selectIds: tableSelected.value as string[], + selectAll: batchParams.value.selectAll, + excludeIds: batchParams.value?.excludeIds || [], + testPlanId: props.planId, + }; + } + return { caseId: associatedCaseId.value, testPlanId: props.planId, testPlanCaseId: testPlanCaseId.value }; + } + // 批量批量移动 const batchUpdateParams = ref(); const batchMoveModalVisible = ref(false); diff --git a/frontend/src/views/test-plan/testPlan/detail/apiScenario/components/scenarioTable.vue b/frontend/src/views/test-plan/testPlan/detail/apiScenario/components/scenarioTable.vue index 4a1c0749c1..72d9264a3b 100644 --- a/frontend/src/views/test-plan/testPlan/detail/apiScenario/components/scenarioTable.vue +++ b/frontend/src/views/test-plan/testPlan/detail/apiScenario/components/scenarioTable.vue @@ -109,20 +109,20 @@ @load-list="resetCaseList" /> - + - @@ -657,7 +657,7 @@ const batchMoveModalVisible = ref(false); const existedDefect = inject>('existedDefect', ref(0)); - const isBatchAssociate = ref(false); + const isBatchAssociateOrCreate = ref(false); const showLinkBugDrawer = ref(false); const associatedCaseId = ref(); const testPlanCaseId = ref(); @@ -666,7 +666,7 @@ const drawerLoading = ref(false); // 关联缺陷 function associateAndCreateDefect(isAssociate: boolean, isBatch: boolean, record?: PlanDetailApiScenarioItem) { - isBatchAssociate.value = isBatch; + isBatchAssociateOrCreate.value = isBatch; if (record) { const { id, apiScenarioId } = record; associatedCaseId.value = apiScenarioId; @@ -684,7 +684,7 @@ try { drawerLoading.value = true; const tableParams = await getTableParams(true); - if (isBatchAssociate.value) { + if (isBatchAssociateOrCreate.value) { await batchAssociatedBugToCase({ selectIds: tableSelected.value as string[], selectAll: batchParams.value.selectAll, @@ -715,6 +715,21 @@ } } + async function getScenarioBugParams() { + if (isBatchAssociateOrCreate.value) { + const tableParams = await getTableParams(true); + return { + ...tableParams, + projectId: appStore.currentProjectId, + selectIds: tableSelected.value as string[], + selectAll: batchParams.value.selectAll, + excludeIds: batchParams.value?.excludeIds || [], + testPlanId: props.planId, + }; + } + return { caseId: associatedCaseId.value, testPlanId: props.planId, testPlanCaseId: testPlanCaseId.value }; + } + // 处理表格选中后批量操作 async function handleTableBatch(event: BatchActionParams, params: BatchActionQueryParams) { tableSelected.value = params?.selectedIds || []; diff --git a/frontend/src/views/test-plan/testPlan/detail/featureCase/components/caseTable.vue b/frontend/src/views/test-plan/testPlan/detail/featureCase/components/caseTable.vue index 3e515c7191..354c341b88 100644 --- a/frontend/src/views/test-plan/testPlan/detail/featureCase/components/caseTable.vue +++ b/frontend/src/views/test-plan/testPlan/detail/featureCase/components/caseTable.vue @@ -174,21 +174,21 @@ :batch-move="batchMoveFeatureCase" @load-list="resetCaseList" /> + - - @@ -775,7 +775,6 @@ const batchLoading = ref(false); const batchExecuteModalVisible = ref(false); const batchExecuteForm = ref({ ...defaultExecuteForm }); - async function handleBatchExecute() { try { batchLoading.value = true; @@ -807,14 +806,29 @@ const associatedCaseId = ref(); const testPlanCaseId = ref(); const drawerLoading = ref(false); - const isBatchAssociate = ref(false); + const isBatchAssociateOrCreate = ref(false); + + async function getBugParams() { + if (isBatchAssociateOrCreate.value) { + const tableParams = await getTableParams(true); + return { + ...tableParams, + projectId: appStore.currentProjectId, + selectIds: tableSelected.value as string[], + selectAll: batchParams.value.selectAll, + excludeIds: batchParams.value?.excludeIds || [], + testPlanId: props.planId, + }; + } + return { caseId: associatedCaseId.value, testPlanId: props.planId, testPlanCaseId: testPlanCaseId.value }; + } // 功能用例关联缺陷 async function saveFunctionBugHandler(params: TableQueryParams) { try { drawerLoading.value = true; const tableParams = await getTableParams(true); - if (isBatchAssociate.value) { + if (isBatchAssociateOrCreate.value) { await batchAssociatedBugToCase({ selectIds: tableSelected.value as string[], selectAll: batchParams.value.selectAll, @@ -854,7 +868,7 @@ // 关联/关联缺陷 function associateAndCreateDefect(isAssociate: boolean, isBatch: boolean, record?: PlanDetailFeatureCaseItem) { - isBatchAssociate.value = isBatch; + isBatchAssociateOrCreate.value = isBatch; if (record) { const { id, caseId } = record; associatedCaseId.value = caseId;