From 0fd72ce96d1856f8225829aaac4c7342d08c28a3 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 5 Feb 2021 14:49:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=85=A8=E9=80=89=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiDefinitionController.java | 4 +- .../api/dto/definition/ApiBatchRequest.java | 22 +-- .../ApiDefinitionBatchProcessingRequest.java | 42 ----- .../dto/definition/ApiDefinitionRequest.java | 14 +- .../api/service/ApiDefinitionService.java | 53 ++---- .../mapper/ext/ExtApiDefinitionMapper.java | 4 +- .../mapper/ext/ExtApiDefinitionMapper.xml | 169 ++++++++++-------- .../commons/utils/ServiceUtils.java | 12 +- .../controller/request/BaseQueryRequest.java | 9 + .../testcase/TestCaseBatchRequest.java | 3 +- .../track/service/TestCaseService.java | 27 ++- .../components/case/ApiCaseList.vue | 3 +- .../definition/components/list/ApiList.vue | 105 +++-------- .../track/case/components/TestCaseList.vue | 5 +- frontend/src/common/js/tableUtils.js | 5 + 15 files changed, 179 insertions(+), 298 deletions(-) delete mode 100644 backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchProcessingRequest.java diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index d5de0424a9..51b1468a9e 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -92,7 +92,7 @@ public class ApiDefinitionController { } @PostMapping("/deleteBatchByParams") - public void deleteBatchByParams(@RequestBody ApiDefinitionBatchProcessingRequest request) { + public void deleteBatchByParams(@RequestBody ApiBatchRequest request) { apiDefinitionService.deleteByParams(request); } @@ -104,7 +104,7 @@ public class ApiDefinitionController { @PostMapping("/removeToGcByParams") @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) - public void removeToGcByParams(@RequestBody ApiDefinitionBatchProcessingRequest request) { + public void removeToGcByParams(@RequestBody ApiBatchRequest request) { apiDefinitionService.removeToGcByParams(request); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiBatchRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiBatchRequest.java index 7566659b14..bab9c9d6e9 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiBatchRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiBatchRequest.java @@ -6,7 +6,6 @@ import lombok.Getter; import lombok.Setter; import java.util.List; -import java.util.Map; @Getter @Setter @@ -14,25 +13,8 @@ public class ApiBatchRequest extends ApiDefinitionWithBLOBs { private List ids; private List orders; private String projectId; - - /** - * isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据) - * filters: 数据状态 - * name:如果是全部数据,那么表格如果历经查询,查询参数是什么 - * moduleIds: 哪些模块的数据 - * unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。 - * filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。 - */ - private boolean isSelectAllDate; - - private Map> filters; - - private String name; - - private List moduleIds; - - private List unSelectIds; - private String moduleId; + private String protocol; + private ApiDefinitionRequest condition; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchProcessingRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchProcessingRequest.java deleted file mode 100644 index 44c3c2d774..0000000000 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchProcessingRequest.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.metersphere.api.dto.definition; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; -import java.util.Map; - -/** - * 接口定义模块-批量处理请求类 - * @author song.tianyang - * @Date 2020/12/29 4:13 下午 - * @Description - */ -@Getter -@Setter -public class ApiDefinitionBatchProcessingRequest { - /** - * isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据) - * filters: 数据状态 - * name:如果是全部数据,那么表格如果历经查询,查询参数是什么 - * moduleIds: 哪些模块的数据 - * unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。 - * filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。 - */ - private boolean isSelectAllDate; - - private Map> filters; - - private String name; - - private List moduleIds; - - private List unSelectIds; - - private String projectId; - - private List dataIds; - - private String protocol; - -} diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java index 0f40f3cc78..f8e4e186fa 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java @@ -1,31 +1,21 @@ package io.metersphere.api.dto.definition; -import io.metersphere.controller.request.OrderRequest; +import io.metersphere.controller.request.BaseQueryRequest; import lombok.Getter; import lombok.Setter; -import java.util.List; -import java.util.Map; - @Getter @Setter -public class ApiDefinitionRequest { +public class ApiDefinitionRequest extends BaseQueryRequest { private String id; private String excludeId; - private String projectId; private String moduleId; - private List moduleIds; private String protocol; private String name; - private String workspaceId; private String userId; private String planId; private boolean recent = false; - private List orders; - private Map> filters; - private Map combine; - private List ids; private boolean isSelectThisWeedData = false; private long createTime = 0; private String status; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 66143cb04d..75208d01bf 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -539,20 +539,12 @@ public class ApiDefinitionService { } public void editApiByParam(ApiBatchRequest request) { - List ids = request.getIds(); - if (request.isSelectAllDate()) { - ids = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol()); - } //name在这里只是查询参数 request.setName(null); - - ApiDefinitionExample definitionExample = new ApiDefinitionExample(); - definitionExample.createCriteria().andIdIn(ids); - ApiDefinitionWithBLOBs definitionWithBLOBs = new ApiDefinitionWithBLOBs(); BeanUtils.copyBean(definitionWithBLOBs, request); definitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); - apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, definitionExample); + apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, getBatchExample(request)); } public void testPlanRelevance(ApiCaseRelevanceRequest request) { @@ -602,39 +594,22 @@ public class ApiDefinitionService { return apiDefinitionMapper.selectByExample(example); } - public void deleteByParams(ApiDefinitionBatchProcessingRequest request) { - List apiIds = request.getDataIds(); - if (request.isSelectAllDate()) { - apiIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol()); - } + public void deleteByParams(ApiBatchRequest request) { + apiDefinitionMapper.deleteByExample(getBatchExample(request)); + } + + public ApiDefinitionExample getBatchExample(ApiBatchRequest request) { + ServiceUtils.getSelectAllIds(request, request.getCondition(), + (query) -> extApiDefinitionMapper.selectIds(query)); ApiDefinitionExample example = new ApiDefinitionExample(); - example.createCriteria().andIdIn(apiIds); - apiDefinitionMapper.deleteByExample(example); + example.createCriteria().andIdIn(request.getIds()); + return example; } - private List getAllApiIdsByFontedSelect(Map> filters, String name, List moduleIds, String projectId, List unSelectIds,String protocol) { - ApiDefinitionRequest request = new ApiDefinitionRequest(); - request.setFilters(filters); - request.setName(name); - request.setModuleIds(moduleIds); - request.setProjectId(projectId); - request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); - request.setProtocol(protocol); - List resList = extApiDefinitionMapper.list(request); - List ids = new ArrayList<>(0); - if (!resList.isEmpty()) { - List allIds = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); - ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(Collectors.toList()); - } - return ids; - } - - public void removeToGcByParams(ApiDefinitionBatchProcessingRequest request) { - List apiIds = request.getDataIds(); - if (request.isSelectAllDate()) { - apiIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol()); - } - extApiDefinitionMapper.removeToGc(apiIds); + public void removeToGcByParams(ApiBatchRequest request) { + ServiceUtils.getSelectAllIds(request, request.getCondition(), + (query) -> extApiDefinitionMapper.selectIds(query)); + extApiDefinitionMapper.removeToGc(request.getIds()); } public List listRelevance(ApiDefinitionRequest request) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java index d523317de7..d50d4fe3b0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java @@ -7,7 +7,7 @@ import io.metersphere.api.dto.definition.ApiDefinitionResult; import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO; import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiDefinitionExample; -import io.metersphere.base.domain.ApiModuleExample; +import io.metersphere.controller.request.BaseQueryRequest; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -36,4 +36,6 @@ public interface ExtApiDefinitionMapper { ApiDefinition getNextNum(@Param("projectId") String projectId); List listRelevance(@Param("request")ApiDefinitionRequest request); + + List selectIds(@Param("request") BaseQueryRequest query); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index 99ddcbffd6..838fb62263 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -210,85 +210,7 @@ from api_definition left join project on api_definition.project_id = project.id left join user on api_definition.user_id = user.id - - - - - - - - - and (api_definition.name like CONCAT('%', #{request.name},'%') - or api_definition.tags like CONCAT('%', #{request.name},'%') - or api_definition.num like CONCAT('%', #{request.name},'%')) - - - AND api_definition.protocol = #{request.protocol} - - - AND project.workspace_id = #{request.workspaceId} - - - AND project.id = #{request.projectId} - - - AND api_definition.id = #{request.id} - - - AND api_definition.user_id = #{request.userId} - - - AND api_definition.create_time >= #{request.createTime} - - - AND api_definition.module_id = #{request.moduleId} - - - AND api_definition.project_id = #{request.projectId} - - - AND api_definition.module_id in - - #{nodeId} - - - - - - - - and api_definition.status in - - #{value} - - - - and api_definition.method in - - #{value} - - - - and api_definition.user_id in - - #{value} - - - - - - - - and api_definition.id not in - (SELECT api_definition_id FROM api_test_case) - - - and api_definition.id in - (SELECT api_definition_id FROM api_test_case) - - - - + order by @@ -446,4 +368,93 @@ WHERE sch.`enable` = true AND apiScene.project_id = #{0,jdbcType=VARCHAR} + + + + + + + + + + + + and (api_definition.name like CONCAT('%', #{request.name},'%') + or api_definition.tags like CONCAT('%', #{request.name},'%') + or api_definition.num like CONCAT('%', #{request.name},'%')) + + + AND api_definition.protocol = #{request.protocol} + + + AND project.workspace_id = #{request.workspaceId} + + + AND project.id = #{request.projectId} + + + AND api_definition.id = #{request.id} + + + AND api_definition.user_id = #{request.userId} + + + AND api_definition.create_time >= #{request.createTime} + + + AND api_definition.module_id = #{request.moduleId} + + + AND api_definition.project_id = #{request.projectId} + + + AND api_definition.module_id in + + #{nodeId} + + + + + + + + and api_definition.status in + + #{value} + + + + and api_definition.method in + + #{value} + + + + and api_definition.user_id in + + #{value} + + + + + + + + and api_definition.id not in + (SELECT api_definition_id FROM api_test_case) + + + and api_definition.id in + (SELECT api_definition_id FROM api_test_case) + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 9bf213370e..1e79b2618f 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -1,8 +1,11 @@ package io.metersphere.commons.utils; +import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.OrderRequest; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -28,7 +31,7 @@ public class ServiceUtils { * @param func 查询id列表的数据库查询 * @return */ - public static void getSelectAllIds(BaseQueryRequest queryRequest, Function> func) { + public static void getSelectAllIds( T batchRequest, BaseQueryRequest queryRequest, Function> func) { if (queryRequest.isSelectAll()) { List ids = func.apply(queryRequest); if (!ids.isEmpty()) { @@ -37,6 +40,13 @@ public class ServiceUtils { .collect(Collectors.toList()); } queryRequest.setIds(ids); + try { + Method setIds = batchRequest.getClass().getDeclaredMethod("setIds", List.class); + setIds.invoke(batchRequest, ids); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + MSException.throwException("请求没有setIds方法"); + } } } } diff --git a/backend/src/main/java/io/metersphere/controller/request/BaseQueryRequest.java b/backend/src/main/java/io/metersphere/controller/request/BaseQueryRequest.java index b9a2297a59..439a407b6d 100644 --- a/backend/src/main/java/io/metersphere/controller/request/BaseQueryRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/BaseQueryRequest.java @@ -22,6 +22,15 @@ public class BaseQueryRequest { private List nodeIds; + /** + * selectAll:选择的数据是否是全部数据(全部数据是不受分页影响的数据) + * filters: 数据状态 + * name:如果是全部数据,那么表格如果历经查询,查询参数是什么 + * moduleIds: 哪些模块的数据 + * unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。 + * filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。 + */ + /** * 是否选中所有数据 */ diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java index 86c38dcd3e..7964b7f211 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java @@ -1,7 +1,6 @@ package io.metersphere.track.request.testcase; import io.metersphere.base.domain.TestCaseWithBLOBs; -import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.OrderRequest; import lombok.Getter; import lombok.Setter; @@ -15,5 +14,5 @@ public class TestCaseBatchRequest extends TestCaseWithBLOBs { private List orders; private String projectId; - private BaseQueryRequest condition; + private QueryTestCaseRequest condition; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 58f8bb5b9f..1f2c4eb981 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -5,6 +5,7 @@ import com.alibaba.excel.EasyExcelFactory; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageHelper; +import io.metersphere.api.dto.definition.ApiBatchRequest; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestCaseMapper; @@ -528,33 +529,25 @@ public class TestCaseService { public void editTestCaseBath(TestCaseBatchRequest request) { - getSelectAllIds(request); - TestCaseExample testCaseExample = new TestCaseExample(); - testCaseExample.createCriteria().andIdIn(request.getIds()); - + TestCaseExample example = this.getBatchExample(request); TestCaseWithBLOBs testCase = new TestCaseWithBLOBs(); BeanUtils.copyBean(testCase, request); testCase.setUpdateTime(System.currentTimeMillis()); - testCaseMapper.updateByExampleSelective( - testCase, - testCaseExample); - + testCaseMapper.updateByExampleSelective(testCase, example); } public void deleteTestCaseBath(TestCaseBatchRequest request) { - getSelectAllIds(request); + TestCaseExample example = this.getBatchExample(request); deleteTestPlanTestCaseBath(request.getIds()); - TestCaseExample example = new TestCaseExample(); - example.createCriteria().andIdIn(request.getIds()); testCaseMapper.deleteByExample(example); } - public void getSelectAllIds(TestCaseBatchRequest request) { - if (request.getCondition().isSelectAll()) { - ServiceUtils.getSelectAllIds(request.getCondition(), - (query) -> extTestCaseMapper.selectIds(query)); - request.setIds(request.getCondition().getIds()); - } + public TestCaseExample getBatchExample(TestCaseBatchRequest request) { + ServiceUtils.getSelectAllIds(request, request.getCondition(), + (query) -> extTestCaseMapper.selectIds(query)); + TestCaseExample example = new TestCaseExample(); + example.createCriteria().andIdIn(request.getIds()); + return example; } public void deleteTestPlanTestCaseBath(List caseIds) { diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index 214dd1f1ad..9346a098e3 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -54,8 +54,7 @@ import {CASE_ORDER} from "../../model/JsonData"; import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components"; import MsBatchEdit from "../basis/BatchEdit"; - // import {CASE_PRIORITY, REQ_METHOD} from "../../model/JsonData"; - import {CASE_PRIORITY,API_METHOD_COLOUR, API_STATUS, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData"; + import {CASE_PRIORITY, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData"; export default { name: 'ApiCaseList', diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index fe05a18b94..7b3aa0cd3d 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -197,7 +197,14 @@ import MsTableAdvSearchBar from "@/business/components/common/components/search/ import {API_DEFINITION_CONFIGS} from "@/business/components/common/components/search/search-components"; import MsTipButton from "@/business/components/common/components/MsTipButton"; import CaseBatchMove from "@/business/components/api/definition/components/basis/BatchMove"; -import {_filter, _sort} from "@/common/js/tableUtils"; +import { + _filter, + _handleSelect, + _handleSelectAll, + _sort, + getSelectDataCounts, initCondition, + setUnSelectIds, toggleAllSelection +} from "@/common/js/tableUtils"; export default { @@ -277,8 +284,6 @@ export default { total: 0, screenHeight: document.documentElement.clientHeight - 270,//屏幕高度, environmentId: undefined, - selectAll: false, - unSelection: [], selectDataCounts: 0, } }, @@ -352,8 +357,7 @@ export default { }, initTable() { this.selectRows = new Set(); - this.selectAll = false; - this.unSelection = []; + initCondition(this.condition); this.selectDataCounts = 0; this.condition.moduleIds = this.selectNodeIds; this.condition.projectId = getCurrentProjectID(); @@ -390,7 +394,6 @@ export default { this.genProtocalFilter(this.condition.protocol); this.total = response.data.itemCount; this.tableData = response.data.listObject; - this.unSelection = response.data.listObject.map(s => s.id); this.tableData.forEach(item => { if (item.tags && item.tags.length > 0) { item.tags = JSON.parse(item.tags); @@ -450,45 +453,21 @@ export default { }); }); }, - handleSelect(selection, row) { - row.hashTree = []; - 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", true); - } else if (this.selectRows.size === 2) { - arr.forEach(row => { - this.$set(row, "showMore", true); - }) - } - this.selectRowsCount(this.selectRows) - }, handleSelectAll(selection) { - if (selection.length > 0) { - if (selection.length === 1) { - selection.hashTree = []; - this.selectRows.add(selection[0]); - } else { - this.tableData.forEach(item => { - item.hashTree = []; - this.$set(item, "showMore", true); - this.selectRows.add(item); - }); - } - } else { - this.selectRows.clear(); - this.tableData.forEach(row => { - this.$set(row, "showMore", false); - }) - } - this.selectRowsCount(this.selectRows) + _handleSelectAll(this, selection, this.tableData, this.selectRows); + setUnSelectIds(this.tableData, this.condition, this.selectRows); + this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows); + }, + handleSelect(selection, row) { + _handleSelect(this, selection, row, this.selectRows); + setUnSelectIds(this.tableData, this.condition, this.selectRows); + this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows); + }, + isSelectDataAll(data) { + this.condition.selectAll = data; + setUnSelectIds(this.tableData, this.condition, this.selectRows); + this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows); + toggleAllSelection(this.$refs.apiDefinitionTable, this.tableData, this.selectRows); }, search() { this.changeSelectDataRangeAll(); @@ -524,9 +503,7 @@ export default { let ids = Array.from(this.selectRows).map(row => row.id); deleteParam.dataIds = ids; deleteParam.projectId = getCurrentProjectID(); - deleteParam.selectAllDate = this.isSelectAllDate; - deleteParam.unSelectIds = this.unSelection; - deleteParam = Object.assign(deleteParam, this.condition); + deleteParam.condition = this.condition; this.$post('/api/definition/deleteBatchByParams/', deleteParam, () => { this.selectRows.clear(); this.initTable(); @@ -544,9 +521,7 @@ export default { let deleteParam = {}; deleteParam.dataIds = ids; deleteParam.projectId = getCurrentProjectID(); - deleteParam.selectAllDate = this.isSelectAllDate; - deleteParam.unSelectIds = this.unSelection; - deleteParam = Object.assign(deleteParam, this.condition); + deleteParam.condition = this.condition; this.$post('/api/definition/removeToGcByParams/', deleteParam, () => { this.selectRows.clear(); this.initTable(); @@ -576,12 +551,8 @@ export default { let param = {}; param[form.type] = form.value; param.ids = ids; - param.projectId = getCurrentProjectID(); - param.selectAllDate = this.isSelectAllDate; - param.unSelectIds = this.unSelection; - param = Object.assign(param, this.condition); - + param.condition = this.condition; this.$post('/api/definition/batch/editByParams', param, () => { this.$success(this.$t('commons.save_success')); this.initTable(); @@ -592,10 +563,8 @@ export default { let ids = arr.map(row => row.id); param.ids = ids; param.projectId = getCurrentProjectID(); - param.selectAllDate = this.isSelectAllDate; - param.unSelectIds = this.unSelection; - param = Object.assign(param, this.condition); param.moduleId=param.nodeId; + param.condition = this.condition; this.$post('/api/definition/batch/editByParams', param, () => { this.$success(this.$t('commons.save_success')); this.$refs.testCaseBatchMove.close(); @@ -646,26 +615,6 @@ export default { showExecResult(row) { this.$emit('showExecResult', row); }, - selectRowsCount(selection) { - let selectedIDs = this.getIds(selection); - let allIDs = this.tableData.map(s => s.id); - this.unSelection = allIDs.filter(function (val) { - return selectedIDs.indexOf(val) === -1 - }); - if (this.isSelectAllDate) { - this.selectDataCounts = this.total - this.unSelection.length; - } else { - this.selectDataCounts = selection.size; - } - }, - isSelectDataAll(dataType) { - this.isSelectAllDate = dataType; - this.selectRowsCount(this.selectRows) - //如果已经全选,不需要再操作了 - if (this.selectRows.size != this.tableData.length) { - this.$refs.apiDefinitionTable.toggleAllSelection(true); - } - }, //判断是否只显示本周的数据。 从首页跳转过来的请求会带有相关参数 getSelectDataRange() { let dataRange = this.$route.params.dataSelectRange; diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 01457e1860..0ba9451af8 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -202,7 +202,7 @@ import { _handleSelect, _handleSelectAll, _sort, - getSelectDataCounts, + getSelectDataCounts, initCondition, setUnSelectIds, toggleAllSelection } from "@/common/js/tableUtils"; @@ -335,8 +335,7 @@ export default { this.projectId = getCurrentProjectID(); this.condition.planId = ""; this.condition.nodeIds = []; - this.condition.selectAll = false; - this.condition.unSelectIds = []; + initCondition(this.condition); this.selectDataCounts = 0; if (this.planId) { // param.planId = this.planId; diff --git a/frontend/src/common/js/tableUtils.js b/frontend/src/common/js/tableUtils.js index c52cc7ab71..550117519e 100644 --- a/frontend/src/common/js/tableUtils.js +++ b/frontend/src/common/js/tableUtils.js @@ -101,6 +101,11 @@ export function _sort(column, condition) { } } +export function initCondition(condition) { + condition.selectAll = false; + condition.unSelectIds = []; +} +