From f66fcbb6fca6f10c0b8fffb6c542952cfbd713eb Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 15 Apr 2024 17:18:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039354 --user=王孝刚 【项目设置】github#29986,在环境设置中,当恰好是第二页或者第三页的第一条,填写的变量名跟原有变量重复时,再删除该新增变量,此时,会导致所有的变量都展示不出来,包括第一页的所有变量,也无法进行变量的添加 https://www.tapd.cn/55049933/s/1497208 --- .../request/controller/MsLoopController.java | 28 +------------------ .../commons/ApiScenarioVariables.vue | 12 +++++--- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java index 3c6756c785..63e1afbad3 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java @@ -5,7 +5,6 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.controller.loop.CountController; import io.metersphere.api.dto.definition.request.controller.loop.MsForEachController; import io.metersphere.api.dto.definition.request.controller.loop.MsWhileController; -import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.dto.shell.filter.ScriptFilter; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.LoopConstants; @@ -14,7 +13,6 @@ import io.metersphere.plugin.core.MsTestElement; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.control.*; import org.apache.jmeter.modifiers.CounterConfig; @@ -26,11 +24,8 @@ import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.timers.ConstantTimer; import org.apache.jorphan.collections.HashTree; -import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; @Data @EqualsAndHashCode(callSuper = true) @@ -53,32 +48,11 @@ public class MsLoopController extends MsTestElement { final HashTree groupTree = controller(tree); // 自身场景 - if (CollectionUtils.isNotEmpty(config.getVariables())) { + if (CollectionUtils.isNotEmpty(config.getVariables()) || CollectionUtils.isNotEmpty(config.getTransferVariables())) { ElementUtil.addCsvDataSet(groupTree, config.getVariables(), config, "shareMode.thread"); ElementUtil.addCounter(groupTree, config.getVariables()); ElementUtil.addRandom(groupTree, config.getVariables()); } - // 当前引用场景 - if (CollectionUtils.isNotEmpty(config.getTransferVariables())) { - final List variables = new LinkedList<>(); - if (CollectionUtils.isEmpty(config.getVariables())) { - variables.addAll(config.getTransferVariables()); - } else { - // 合并处理 - Map variableMap = config.getVariables().stream().collect(Collectors.toMap(ScenarioVariable::getId, a -> a, (k1, k2) -> k1)); - config.getTransferVariables().forEach(item -> { - if (!variableMap.containsKey(item.getId())) { - variables.add(item); - } - }); - } - - if (CollectionUtils.isNotEmpty(variables)) { - ElementUtil.addCsvDataSet(groupTree, variables, config, "shareMode.thread"); - ElementUtil.addCounter(groupTree, variables); - ElementUtil.addRandom(groupTree, variables); - } - } // 循环下都增加一个计数器,用于结果统计 groupTree.add(addCounterConfig()); // 不打开执行成功后轮询功能,则成功后就停止循环 diff --git a/framework/sdk-parent/frontend/src/components/environment/commons/ApiScenarioVariables.vue b/framework/sdk-parent/frontend/src/components/environment/commons/ApiScenarioVariables.vue index 101ef96a17..500723e9fe 100644 --- a/framework/sdk-parent/frontend/src/components/environment/commons/ApiScenarioVariables.vue +++ b/framework/sdk-parent/frontend/src/components/environment/commons/ApiScenarioVariables.vue @@ -351,16 +351,20 @@ export default { return true; }, remove: function (index) { - const dataIndex = this.pageData.findIndex((d) => d.name === index.name); + const dataIndex = this.pageData.findIndex((d) => d.name === index.name && d.id === index.id); + //如果是最后一个数据 删除后需要添加一个空行 + if (dataIndex === this.pageData.length -1) { + index.name = ''; + return; + } if (dataIndex !== -1) { this.pageData.splice(dataIndex, 1); } - - const allDataIndex = this.allData.findIndex((d) => d.name === index.name); + const allDataIndex = this.allData.findIndex((d) => d.name === index.name && d.id === index.id); if (allDataIndex !== -1) { this.allData.splice(allDataIndex, 1); } - const itemsIndex = this.items.findIndex((d) => d.name === index.name); + const itemsIndex = this.items.findIndex((d) => d.name === index.name && d.id === index.id); if (itemsIndex !== -1) { this.items.splice(itemsIndex, 1); }