fix(系统设置): 修复导入postman 文件后 场景步骤删除错乱问题

This commit is contained in:
fit2-zhao 2021-05-26 11:26:15 +08:00 committed by fit2-zhao
parent 6245d93ae5
commit b5760ccbc3
4 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package io.metersphere.log.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
@ -59,7 +60,7 @@ public class ReflexObjectUtil {
column.setDepthDff(true);
if (val != null) {
try {
if (f.getName().equals("loadConfiguration")) {
if (ReflexObjectUtil.isJsonArray(val.toString())) {
val = "{\"" + "压力配置" + "\":" + val.toString() + "}";
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
@ -82,6 +83,18 @@ public class ReflexObjectUtil {
return columnList;
}
public static boolean isJsonArray(String content) {
try {
JSONArray array = JSON.parseArray(content);
if (array != null && array.size() > 0) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
}
public static void order(List<String> orderRegulation, List<DetailColumn> targetList) {
Collections.sort(targetList, ((o1, o2) -> {
int io1 = orderRegulation.indexOf(o1.getColumnName());
@ -98,6 +111,15 @@ public class ReflexObjectUtil {
List<DetailColumn> newColumns = newObj.getColumns();
for (int i = 0; i < originalColumns.size(); i++) {
if (!StringUtils.equals(JSON.toJSONString(originalColumns.get(i).getOriginalValue()), JSON.toJSONString(newColumns.get(i).getOriginalValue()))) {
if (originalColumns.get(i).getColumnName().equals("tags")) {
if ((originalColumns.get(i).getOriginalValue() == null || StringUtils.isEmpty(originalColumns.get(i).getOriginalValue().toString()))
&& StringUtils.equals("[]", newColumns.get(i).getOriginalValue().toString())) {
continue;
} else if ((newColumns.get(i).getOriginalValue() == null || StringUtils.isEmpty(newColumns.get(i).getOriginalValue().toString()))
&& StringUtils.equals("[]", originalColumns.get(i).getOriginalValue().toString())) {
continue;
}
}
// 深度对比
if (originalColumns.get(i).isDepthDff() && originalColumns.get(i).getOriginalValue() != null && newColumns.get(i).getOriginalValue() != null) {
ObjectMapper mapper = new ObjectMapper();
@ -123,13 +145,13 @@ public class ReflexObjectUtil {
}
StringBuilder newValue = new StringBuilder();
if (addBuff != null && addBuff.toString().length() > 0) {
newValue.append("添加:").append(addBuff).append("\n");
newValue.append("添加:\n").append(addBuff).append("\n");
}
if (removeBuff != null && removeBuff.toString().length() > 0) {
newValue.append("移除:").append(removeBuff).append("\n");
newValue.append("移除:\n").append(removeBuff).append("\n");
}
if (repBuff != null && repBuff.toString().length() > 0) {
newValue.append("修改:").append(repBuff).append("\n");
newValue.append("修改:\n").append(repBuff).append("\n");
}
DetailColumn column = new DetailColumn();
BeanUtils.copyBean(column, originalColumns.get(i));

View File

@ -651,6 +651,9 @@
recursiveSorting(arr, scenarioProjectId) {
for (let i in arr) {
arr[i].index = Number(i) + 1;
if (!arr[i].resourceId) {
arr[i].resourceId = getUUID();
}
if (arr[i].type === ELEMENT_TYPE.LoopController && arr[i].loopType === "LOOP_COUNT" && arr[i].hashTree && arr[i].hashTree.length > 1) {
arr[i].countController.proceed = true;
}
@ -677,6 +680,9 @@
for (let i in this.scenarioDefinition) {
//
this.scenarioDefinition[i].index = Number(i) + 1;
if (!this.scenarioDefinition[i].resourceId) {
this.scenarioDefinition[i].resourceId = getUUID();
}
//
if (this.scenarioDefinition[i].type === ELEMENT_TYPE.LoopController && this.scenarioDefinition[i].hashTree
&& this.scenarioDefinition[i].hashTree.length > 1) {

View File

@ -310,6 +310,9 @@
for (let i in arr) {
arr[i].disabled = true;
arr[i].index = Number(i) + 1;
if (!arr[i].resourceId) {
arr[i].resourceId = getUUID();
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
@ -317,6 +320,9 @@
},
sort() {
for (let i in this.request.hashTree) {
if (!this.request.hashTree[i].resourceId) {
this.request.hashTree[i].resourceId = getUUID();
}
this.request.hashTree[i].disabled = true;
this.request.hashTree[i].index = Number(i) + 1;
if (this.request.hashTree[i].hashTree != undefined && this.request.hashTree[i].hashTree.length > 0) {
@ -368,7 +374,7 @@
/*触发执行操作*/
this.reportId = getUUID();
},
errorRefresh(){
errorRefresh() {
this.loading = false;
},
runRefresh(data) {

View File

@ -44,7 +44,6 @@
show-word-limit>
<i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced"></i>
</el-autocomplete>
<ms-api-variable-advance ref="variableAdvance"/>
</div>
</el-col>
<el-col class="item kv-delete">
@ -53,6 +52,7 @@
</el-col>
</el-row>
</div>
<ms-api-variable-advance ref="variableAdvance"/>
</div>
</template>