From 4203707ef5048b9bed0b028aada1dea0ef4f18d1 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 31 Aug 2020 17:18:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/APIReportController.java | 5 ++ .../api/dto/DeleteAPIReportRequest.java | 3 + .../api/service/APIReportService.java | 9 +++ .../components/api/report/ApiReportList.vue | 72 ++++++++++++++++++- frontend/src/i18n/en-US.js | 2 + frontend/src/i18n/zh-CN.js | 2 + frontend/src/i18n/zh-TW.js | 2 + 7 files changed, 94 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/APIReportController.java b/backend/src/main/java/io/metersphere/api/controller/APIReportController.java index 1cd877b4f4..caa7374ebf 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APIReportController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APIReportController.java @@ -62,5 +62,10 @@ public class APIReportController { return apiReportService.dashboardTests(SessionUtils.getCurrentWorkspaceId()); } + @PostMapping("/batch/delete") + public void deleteAPIReportBatch(@RequestBody DeleteAPIReportRequest reportRequest) { + apiReportService.deleteAPIReportBatch(reportRequest); + } + } diff --git a/backend/src/main/java/io/metersphere/api/dto/DeleteAPIReportRequest.java b/backend/src/main/java/io/metersphere/api/dto/DeleteAPIReportRequest.java index 208eee4450..3d47125869 100644 --- a/backend/src/main/java/io/metersphere/api/dto/DeleteAPIReportRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/DeleteAPIReportRequest.java @@ -3,9 +3,12 @@ package io.metersphere.api.dto; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Setter @Getter public class DeleteAPIReportRequest { private String id; + private List ids; } diff --git a/backend/src/main/java/io/metersphere/api/service/APIReportService.java b/backend/src/main/java/io/metersphere/api/service/APIReportService.java index afb2e12c15..cc4367eb8b 100644 --- a/backend/src/main/java/io/metersphere/api/service/APIReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/APIReportService.java @@ -147,4 +147,13 @@ public class APIReportService { } + public void deleteAPIReportBatch(DeleteAPIReportRequest reportRequest) { + ApiTestReportDetailExample apiTestReportDetailExample = new ApiTestReportDetailExample(); + apiTestReportDetailExample.createCriteria().andReportIdIn(reportRequest.getIds()); + apiTestReportDetailMapper.deleteByExample(apiTestReportDetailExample); + + ApiTestReportExample apiTestReportExample = new ApiTestReportExample(); + apiTestReportExample.createCriteria().andIdIn(reportRequest.getIds()); + apiTestReportMapper.deleteByExample(apiTestReportExample); + } } diff --git a/frontend/src/business/components/api/report/ApiReportList.vue b/frontend/src/business/components/api/report/ApiReportList.vue index 66dcb20cc7..3cd7f688ee 100644 --- a/frontend/src/business/components/api/report/ApiReportList.vue +++ b/frontend/src/business/components/api/report/ApiReportList.vue @@ -8,7 +8,16 @@ :show-create="false"/> + + + + @@ -59,12 +68,13 @@ import MsTableOperatorButton from "../../common/components/MsTableOperatorButton import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem"; import {REPORT_CONFIGS} from "../../common/components/search/search-components"; import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent"; +import ShowMoreBtn from "../../track/case/components/ShowMoreBtn"; export default { components: { ReportTriggerModeItem, MsTableOperatorButton, - MsApiReportStatus, MsMainContainer, MsContainer, MsTableHeader, MsTablePagination + MsApiReportStatus, MsMainContainer, MsContainer, MsTableHeader, MsTablePagination, ShowMoreBtn }, data() { return { @@ -92,6 +102,12 @@ export default { {text: this.$t('commons.trigger_mode.schedule'), value: 'SCHEDULE'}, {text: this.$t('commons.trigger_mode.api'), value: 'API'} ], + buttons: [ + { + name: this.$t('api_report.batch_delete'), handleClick: this.handleBatchDelete + } + ], + selectRows: new Set(), } }, @@ -147,6 +163,60 @@ export default { _filter(filters, this.condition); this.init(); }, + handleSelect(selection, row) { + if (this.selectRows.has(row)) { + this.$set(row, "showMore", false); + this.selectRows.delete(row); + } else { + this.$set(row, "showMore", true); + this.selectRows.add(row); + } + + let arr = Array.from(this.selectRows); + + // 选中1个以上的用例时显示更多操作 + if (this.selectRows.size === 1) { + this.$set(arr[0], "showMore", false); + } else if (this.selectRows.size === 2) { + arr.forEach(row => { + this.$set(row, "showMore", true); + }) + } + }, + handleSelectAll(selection) { + if (selection.length > 0) { + if (selection.length === 1) { + this.selectRows.add(selection[0]); + } else { + this.tableData.forEach(item => { + this.$set(item, "showMore", true); + this.selectRows.add(item); + }); + } + } else { + this.selectRows.clear(); + this.tableData.forEach(row => { + this.$set(row, "showMore", false); + }) + } + }, + handleBatchDelete() { + this.$alert(this.$t('api_report.delete_batch_confirm') + "?", '', { + confirmButtonText: this.$t('commons.confirm'), + callback: (action) => { + if (action === 'confirm') { + let ids = Array.from(this.selectRows).map(row => row.id); + this.$post('/api/report/batch/delete', {ids: ids}, () => { + this.selectRows.clear(); + this.$success(this.$t('commons.delete_success')); + this.search(); + // 发送广播,刷新 head 上的最新列表 + ApiEvent.$emit(LIST_CHANGE); + }); + } + } + }); + } }, diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 0ec14010a0..7697a0511e 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -520,6 +520,7 @@ export default { request_cookie: "Cookie", response: "Response", delete_confirm: 'Confirm delete : ', + delete_batch_confirm: 'Confirm batch delete report', scenario_name: "Scenario name", response_time: "Response time(ms)", latency: "Latency", @@ -542,6 +543,7 @@ export default { sub_result: "Sub Result", detail: "Report detail", delete: "Delete report", + batch_delete: "Delete reports in bulk", running: "The test is running", not_exist: "Test report does not exist", }, diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 974ac9d8ab..e6d308be49 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -522,6 +522,7 @@ export default { request_cookie: "Cookie", response: "响应", delete_confirm: '确认删除报告: ', + delete_batch_confirm: '确认批量删除报告', scenario_name: "场景名称", response_time: "响应时间(ms)", latency: "网络延迟", @@ -544,6 +545,7 @@ export default { sub_result: "子请求", detail: "报告详情", delete: "删除报告", + batch_delete: "批量删除报告", running: "测试执行中", not_exist: "测试报告不存在", }, diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 681aa06395..13f807c3b0 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -520,6 +520,7 @@ export default { request_cookie: "Cookie", response: "響應", delete_confirm: '確認删除報告:', + delete_batch_confirm: '確認批量刪除報告', scenario_name: "場景名稱", response_time: "回應時間(ms)", latency: "網路延遲", @@ -542,6 +543,7 @@ export default { sub_result: "子請求", detail: "報告詳情", delete: "刪除報告", + batch_delete: "批量刪除報告", running: "測試執行中", not_exist: "測試報告不存在", },