refactor: 接口列表全选重构

This commit is contained in:
chenjianxing 2021-02-05 14:49:48 +08:00
parent 21678d4a77
commit 0fd72ce96d
15 changed files with 179 additions and 298 deletions

View File

@ -92,7 +92,7 @@ public class ApiDefinitionController {
} }
@PostMapping("/deleteBatchByParams") @PostMapping("/deleteBatchByParams")
public void deleteBatchByParams(@RequestBody ApiDefinitionBatchProcessingRequest request) { public void deleteBatchByParams(@RequestBody ApiBatchRequest request) {
apiDefinitionService.deleteByParams(request); apiDefinitionService.deleteByParams(request);
} }
@ -104,7 +104,7 @@ public class ApiDefinitionController {
@PostMapping("/removeToGcByParams") @PostMapping("/removeToGcByParams")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) @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); apiDefinitionService.removeToGcByParams(request);
} }

View File

@ -6,7 +6,6 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.Map;
@Getter @Getter
@Setter @Setter
@ -14,25 +13,8 @@ public class ApiBatchRequest extends ApiDefinitionWithBLOBs {
private List<String> ids; private List<String> ids;
private List<OrderRequest> orders; private List<OrderRequest> orders;
private String projectId; private String projectId;
/**
* isSelectAllDate选择的数据是否是全部数据全部数据是不受分页影响的数据
* filters: 数据状态
* name如果是全部数据那么表格如果历经查询查询参数是什么
* moduleIds 哪些模块的数据
* unSelectIds是否在页面上有未勾选的数据有的话他们的ID是哪些
* filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要为了让程序能明确批量的范围
*/
private boolean isSelectAllDate;
private Map<String, List<String>> filters;
private String name;
private List<String> moduleIds;
private List<String> unSelectIds;
private String moduleId; private String moduleId;
private String protocol;
private ApiDefinitionRequest condition;
} }

View File

@ -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<String, List<String>> filters;
private String name;
private List<String> moduleIds;
private List<String> unSelectIds;
private String projectId;
private List<String> dataIds;
private String protocol;
}

View File

@ -1,31 +1,21 @@
package io.metersphere.api.dto.definition; package io.metersphere.api.dto.definition;
import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.BaseQueryRequest;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List;
import java.util.Map;
@Getter @Getter
@Setter @Setter
public class ApiDefinitionRequest { public class ApiDefinitionRequest extends BaseQueryRequest {
private String id; private String id;
private String excludeId; private String excludeId;
private String projectId;
private String moduleId; private String moduleId;
private List<String> moduleIds;
private String protocol; private String protocol;
private String name; private String name;
private String workspaceId;
private String userId; private String userId;
private String planId; private String planId;
private boolean recent = false; private boolean recent = false;
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
private Map<String, Object> combine;
private List<String> ids;
private boolean isSelectThisWeedData = false; private boolean isSelectThisWeedData = false;
private long createTime = 0; private long createTime = 0;
private String status; private String status;

View File

@ -539,20 +539,12 @@ public class ApiDefinitionService {
} }
public void editApiByParam(ApiBatchRequest request) { public void editApiByParam(ApiBatchRequest request) {
List<String> ids = request.getIds();
if (request.isSelectAllDate()) {
ids = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol());
}
//name在这里只是查询参数 //name在这里只是查询参数
request.setName(null); request.setName(null);
ApiDefinitionExample definitionExample = new ApiDefinitionExample();
definitionExample.createCriteria().andIdIn(ids);
ApiDefinitionWithBLOBs definitionWithBLOBs = new ApiDefinitionWithBLOBs(); ApiDefinitionWithBLOBs definitionWithBLOBs = new ApiDefinitionWithBLOBs();
BeanUtils.copyBean(definitionWithBLOBs, request); BeanUtils.copyBean(definitionWithBLOBs, request);
definitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); definitionWithBLOBs.setUpdateTime(System.currentTimeMillis());
apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, definitionExample); apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, getBatchExample(request));
} }
public void testPlanRelevance(ApiCaseRelevanceRequest request) { public void testPlanRelevance(ApiCaseRelevanceRequest request) {
@ -602,39 +594,22 @@ public class ApiDefinitionService {
return apiDefinitionMapper.selectByExample(example); return apiDefinitionMapper.selectByExample(example);
} }
public void deleteByParams(ApiDefinitionBatchProcessingRequest request) { public void deleteByParams(ApiBatchRequest request) {
List<String> apiIds = request.getDataIds(); apiDefinitionMapper.deleteByExample(getBatchExample(request));
if (request.isSelectAllDate()) { }
apiIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol());
} public ApiDefinitionExample getBatchExample(ApiBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiDefinitionMapper.selectIds(query));
ApiDefinitionExample example = new ApiDefinitionExample(); ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andIdIn(apiIds); example.createCriteria().andIdIn(request.getIds());
apiDefinitionMapper.deleteByExample(example); return example;
} }
private List<String> getAllApiIdsByFontedSelect(Map<String, List<String>> filters, String name, List<String> moduleIds, String projectId, List<String> unSelectIds,String protocol) { public void removeToGcByParams(ApiBatchRequest request) {
ApiDefinitionRequest request = new ApiDefinitionRequest(); ServiceUtils.getSelectAllIds(request, request.getCondition(),
request.setFilters(filters); (query) -> extApiDefinitionMapper.selectIds(query));
request.setName(name); extApiDefinitionMapper.removeToGc(request.getIds());
request.setModuleIds(moduleIds);
request.setProjectId(projectId);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProtocol(protocol);
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
List<String> ids = new ArrayList<>(0);
if (!resList.isEmpty()) {
List<String> 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<String> 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 List<ApiDefinitionResult> listRelevance(ApiDefinitionRequest request) { public List<ApiDefinitionResult> listRelevance(ApiDefinitionRequest request) {

View File

@ -7,7 +7,7 @@ import io.metersphere.api.dto.definition.ApiDefinitionResult;
import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO; import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO;
import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.ApiDefinitionExample; 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 org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -36,4 +36,6 @@ public interface ExtApiDefinitionMapper {
ApiDefinition getNextNum(@Param("projectId") String projectId); ApiDefinition getNextNum(@Param("projectId") String projectId);
List<ApiDefinitionResult> listRelevance(@Param("request")ApiDefinitionRequest request); List<ApiDefinitionResult> listRelevance(@Param("request")ApiDefinitionRequest request);
List<String> selectIds(@Param("request") BaseQueryRequest query);
} }

View File

@ -210,85 +210,7 @@
from api_definition from api_definition
left join project on api_definition.project_id = project.id left join project on api_definition.project_id = project.id
left join user on api_definition.user_id = user.id left join user on api_definition.user_id = user.id
<where> <include refid="queryWhereCondition"/>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
</include>
</if>
<if test="request.name != null">
and (api_definition.name like CONCAT('%', #{request.name},'%')
or api_definition.tags like CONCAT('%', #{request.name},'%')
or api_definition.num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.protocol != null">
AND api_definition.protocol = #{request.protocol}
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
</if>
<if test="request.projectId != null">
AND project.id = #{request.projectId}
</if>
<if test="request.id != null">
AND api_definition.id = #{request.id}
</if>
<if test="request.userId != null">
AND api_definition.user_id = #{request.userId}
</if>
<if test="request.createTime >0">
AND api_definition.create_time >= #{request.createTime}
</if>
<if test="request.moduleId != null">
AND api_definition.module_id = #{request.moduleId}
</if>
<if test="request.projectId != null">
AND api_definition.project_id = #{request.projectId}
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
AND api_definition.module_id in
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_definition.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='method'">
and api_definition.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_definition.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
<if test="request.apiCaseCoverage == 'uncoverage' ">
and api_definition.id not in
(SELECT api_definition_id FROM api_test_case)
</if>
<if test="request.apiCaseCoverage == 'coverage' ">
and api_definition.id in
(SELECT api_definition_id FROM api_test_case)
</if>
</where>
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by
<foreach collection="request.orders" separator="," item="order"> <foreach collection="request.orders" separator="," item="order">
@ -446,4 +368,93 @@
WHERE sch.`enable` = true WHERE sch.`enable` = true
AND apiScene.project_id = #{0,jdbcType=VARCHAR} AND apiScene.project_id = #{0,jdbcType=VARCHAR}
</select> </select>
<select id="selectIds" resultType="java.lang.String">
select api_definition.id
from api_definition
left join project on api_definition.project_id = project.id
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<sql id="queryWhereCondition">
<where>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
</include>
</if>
<if test="request.name != null">
and (api_definition.name like CONCAT('%', #{request.name},'%')
or api_definition.tags like CONCAT('%', #{request.name},'%')
or api_definition.num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.protocol != null">
AND api_definition.protocol = #{request.protocol}
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
</if>
<if test="request.projectId != null">
AND project.id = #{request.projectId}
</if>
<if test="request.id != null">
AND api_definition.id = #{request.id}
</if>
<if test="request.userId != null">
AND api_definition.user_id = #{request.userId}
</if>
<if test="request.createTime >0">
AND api_definition.create_time >= #{request.createTime}
</if>
<if test="request.moduleId != null">
AND api_definition.module_id = #{request.moduleId}
</if>
<if test="request.projectId != null">
AND api_definition.project_id = #{request.projectId}
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
AND api_definition.module_id in
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_definition.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='method'">
and api_definition.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_definition.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
<if test="request.apiCaseCoverage == 'uncoverage' ">
and api_definition.id not in
(SELECT api_definition_id FROM api_test_case)
</if>
<if test="request.apiCaseCoverage == 'coverage' ">
and api_definition.id in
(SELECT api_definition_id FROM api_test_case)
</if>
</where>
</sql>
</mapper> </mapper>

View File

@ -1,8 +1,11 @@
package io.metersphere.commons.utils; package io.metersphere.commons.utils;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.BaseQueryRequest;
import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.OrderRequest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@ -28,7 +31,7 @@ public class ServiceUtils {
* @param func 查询id列表的数据库查询 * @param func 查询id列表的数据库查询
* @return * @return
*/ */
public static void getSelectAllIds(BaseQueryRequest queryRequest, Function<BaseQueryRequest, List<String>> func) { public static<T> void getSelectAllIds( T batchRequest, BaseQueryRequest queryRequest, Function<BaseQueryRequest, List<String>> func) {
if (queryRequest.isSelectAll()) { if (queryRequest.isSelectAll()) {
List<String> ids = func.apply(queryRequest); List<String> ids = func.apply(queryRequest);
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
@ -37,6 +40,13 @@ public class ServiceUtils {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
queryRequest.setIds(ids); 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方法");
}
} }
} }
} }

View File

@ -22,6 +22,15 @@ public class BaseQueryRequest {
private List<String> nodeIds; private List<String> nodeIds;
/**
* selectAll选择的数据是否是全部数据全部数据是不受分页影响的数据
* filters: 数据状态
* name如果是全部数据那么表格如果历经查询查询参数是什么
* moduleIds 哪些模块的数据
* unSelectIds是否在页面上有未勾选的数据有的话他们的ID是哪些
* filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要为了让程序能明确批量的范围
*/
/** /**
* 是否选中所有数据 * 是否选中所有数据
*/ */

View File

@ -1,7 +1,6 @@
package io.metersphere.track.request.testcase; package io.metersphere.track.request.testcase;
import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.controller.request.BaseQueryRequest;
import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.OrderRequest;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -15,5 +14,5 @@ public class TestCaseBatchRequest extends TestCaseWithBLOBs {
private List<OrderRequest> orders; private List<OrderRequest> orders;
private String projectId; private String projectId;
private BaseQueryRequest condition; private QueryTestCaseRequest condition;
} }

View File

@ -5,6 +5,7 @@ import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.definition.ApiBatchRequest;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
@ -528,33 +529,25 @@ public class TestCaseService {
public void editTestCaseBath(TestCaseBatchRequest request) { public void editTestCaseBath(TestCaseBatchRequest request) {
getSelectAllIds(request); TestCaseExample example = this.getBatchExample(request);
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andIdIn(request.getIds());
TestCaseWithBLOBs testCase = new TestCaseWithBLOBs(); TestCaseWithBLOBs testCase = new TestCaseWithBLOBs();
BeanUtils.copyBean(testCase, request); BeanUtils.copyBean(testCase, request);
testCase.setUpdateTime(System.currentTimeMillis()); testCase.setUpdateTime(System.currentTimeMillis());
testCaseMapper.updateByExampleSelective( testCaseMapper.updateByExampleSelective(testCase, example);
testCase,
testCaseExample);
} }
public void deleteTestCaseBath(TestCaseBatchRequest request) { public void deleteTestCaseBath(TestCaseBatchRequest request) {
getSelectAllIds(request); TestCaseExample example = this.getBatchExample(request);
deleteTestPlanTestCaseBath(request.getIds()); deleteTestPlanTestCaseBath(request.getIds());
TestCaseExample example = new TestCaseExample();
example.createCriteria().andIdIn(request.getIds());
testCaseMapper.deleteByExample(example); testCaseMapper.deleteByExample(example);
} }
public void getSelectAllIds(TestCaseBatchRequest request) { public TestCaseExample getBatchExample(TestCaseBatchRequest request) {
if (request.getCondition().isSelectAll()) { ServiceUtils.getSelectAllIds(request, request.getCondition(),
ServiceUtils.getSelectAllIds(request.getCondition(), (query) -> extTestCaseMapper.selectIds(query));
(query) -> extTestCaseMapper.selectIds(query)); TestCaseExample example = new TestCaseExample();
request.setIds(request.getCondition().getIds()); example.createCriteria().andIdIn(request.getIds());
} return example;
} }
public void deleteTestPlanTestCaseBath(List<String> caseIds) { public void deleteTestPlanTestCaseBath(List<String> caseIds) {

View File

@ -54,8 +54,7 @@
import {CASE_ORDER} from "../../model/JsonData"; import {CASE_ORDER} from "../../model/JsonData";
import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components"; import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components";
import MsBatchEdit from "../basis/BatchEdit"; import MsBatchEdit from "../basis/BatchEdit";
// import {CASE_PRIORITY, REQ_METHOD} from "../../model/JsonData"; import {CASE_PRIORITY, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData";
import {CASE_PRIORITY,API_METHOD_COLOUR, API_STATUS, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData";
export default { export default {
name: 'ApiCaseList', name: 'ApiCaseList',

View File

@ -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 {API_DEFINITION_CONFIGS} from "@/business/components/common/components/search/search-components";
import MsTipButton from "@/business/components/common/components/MsTipButton"; import MsTipButton from "@/business/components/common/components/MsTipButton";
import CaseBatchMove from "@/business/components/api/definition/components/basis/BatchMove"; 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 { export default {
@ -277,8 +284,6 @@ export default {
total: 0, total: 0,
screenHeight: document.documentElement.clientHeight - 270,//, screenHeight: document.documentElement.clientHeight - 270,//,
environmentId: undefined, environmentId: undefined,
selectAll: false,
unSelection: [],
selectDataCounts: 0, selectDataCounts: 0,
} }
}, },
@ -352,8 +357,7 @@ export default {
}, },
initTable() { initTable() {
this.selectRows = new Set(); this.selectRows = new Set();
this.selectAll = false; initCondition(this.condition);
this.unSelection = [];
this.selectDataCounts = 0; this.selectDataCounts = 0;
this.condition.moduleIds = this.selectNodeIds; this.condition.moduleIds = this.selectNodeIds;
this.condition.projectId = getCurrentProjectID(); this.condition.projectId = getCurrentProjectID();
@ -390,7 +394,6 @@ export default {
this.genProtocalFilter(this.condition.protocol); this.genProtocalFilter(this.condition.protocol);
this.total = response.data.itemCount; this.total = response.data.itemCount;
this.tableData = response.data.listObject; this.tableData = response.data.listObject;
this.unSelection = response.data.listObject.map(s => s.id);
this.tableData.forEach(item => { this.tableData.forEach(item => {
if (item.tags && item.tags.length > 0) { if (item.tags && item.tags.length > 0) {
item.tags = JSON.parse(item.tags); 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) { handleSelectAll(selection) {
if (selection.length > 0) { _handleSelectAll(this, selection, this.tableData, this.selectRows);
if (selection.length === 1) { setUnSelectIds(this.tableData, this.condition, this.selectRows);
selection.hashTree = []; this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
this.selectRows.add(selection[0]); },
} else { handleSelect(selection, row) {
this.tableData.forEach(item => { _handleSelect(this, selection, row, this.selectRows);
item.hashTree = []; setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.$set(item, "showMore", true); this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
this.selectRows.add(item); },
}); isSelectDataAll(data) {
} this.condition.selectAll = data;
} else { setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectRows.clear(); this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
this.tableData.forEach(row => { toggleAllSelection(this.$refs.apiDefinitionTable, this.tableData, this.selectRows);
this.$set(row, "showMore", false);
})
}
this.selectRowsCount(this.selectRows)
}, },
search() { search() {
this.changeSelectDataRangeAll(); this.changeSelectDataRangeAll();
@ -524,9 +503,7 @@ export default {
let ids = Array.from(this.selectRows).map(row => row.id); let ids = Array.from(this.selectRows).map(row => row.id);
deleteParam.dataIds = ids; deleteParam.dataIds = ids;
deleteParam.projectId = getCurrentProjectID(); deleteParam.projectId = getCurrentProjectID();
deleteParam.selectAllDate = this.isSelectAllDate; deleteParam.condition = this.condition;
deleteParam.unSelectIds = this.unSelection;
deleteParam = Object.assign(deleteParam, this.condition);
this.$post('/api/definition/deleteBatchByParams/', deleteParam, () => { this.$post('/api/definition/deleteBatchByParams/', deleteParam, () => {
this.selectRows.clear(); this.selectRows.clear();
this.initTable(); this.initTable();
@ -544,9 +521,7 @@ export default {
let deleteParam = {}; let deleteParam = {};
deleteParam.dataIds = ids; deleteParam.dataIds = ids;
deleteParam.projectId = getCurrentProjectID(); deleteParam.projectId = getCurrentProjectID();
deleteParam.selectAllDate = this.isSelectAllDate; deleteParam.condition = this.condition;
deleteParam.unSelectIds = this.unSelection;
deleteParam = Object.assign(deleteParam, this.condition);
this.$post('/api/definition/removeToGcByParams/', deleteParam, () => { this.$post('/api/definition/removeToGcByParams/', deleteParam, () => {
this.selectRows.clear(); this.selectRows.clear();
this.initTable(); this.initTable();
@ -576,12 +551,8 @@ export default {
let param = {}; let param = {};
param[form.type] = form.value; param[form.type] = form.value;
param.ids = ids; param.ids = ids;
param.projectId = getCurrentProjectID(); param.projectId = getCurrentProjectID();
param.selectAllDate = this.isSelectAllDate; param.condition = this.condition;
param.unSelectIds = this.unSelection;
param = Object.assign(param, this.condition);
this.$post('/api/definition/batch/editByParams', param, () => { this.$post('/api/definition/batch/editByParams', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.initTable(); this.initTable();
@ -592,10 +563,8 @@ export default {
let ids = arr.map(row => row.id); let ids = arr.map(row => row.id);
param.ids = ids; param.ids = ids;
param.projectId = getCurrentProjectID(); param.projectId = getCurrentProjectID();
param.selectAllDate = this.isSelectAllDate;
param.unSelectIds = this.unSelection;
param = Object.assign(param, this.condition);
param.moduleId=param.nodeId; param.moduleId=param.nodeId;
param.condition = this.condition;
this.$post('/api/definition/batch/editByParams', param, () => { this.$post('/api/definition/batch/editByParams', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.$refs.testCaseBatchMove.close(); this.$refs.testCaseBatchMove.close();
@ -646,26 +615,6 @@ export default {
showExecResult(row) { showExecResult(row) {
this.$emit('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() { getSelectDataRange() {
let dataRange = this.$route.params.dataSelectRange; let dataRange = this.$route.params.dataSelectRange;

View File

@ -202,7 +202,7 @@ import {
_handleSelect, _handleSelect,
_handleSelectAll, _handleSelectAll,
_sort, _sort,
getSelectDataCounts, getSelectDataCounts, initCondition,
setUnSelectIds, setUnSelectIds,
toggleAllSelection toggleAllSelection
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
@ -335,8 +335,7 @@ export default {
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();
this.condition.planId = ""; this.condition.planId = "";
this.condition.nodeIds = []; this.condition.nodeIds = [];
this.condition.selectAll = false; initCondition(this.condition);
this.condition.unSelectIds = [];
this.selectDataCounts = 0; this.selectDataCounts = 0;
if (this.planId) { if (this.planId) {
// param.planId = this.planId; // param.planId = this.planId;

View File

@ -101,6 +101,11 @@ export function _sort(column, condition) {
} }
} }
export function initCondition(condition) {
condition.selectAll = false;
condition.unSelectIds = [];
}