From 5cc1b697642da16ef1d0f52c2307cbee103c5a8a Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 23 Aug 2021 10:55:01 +0800 Subject: [PATCH] =?UTF-8?q?fix=20(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=95=B0=E6=8D=AE=E7=BC=BA=E5=A4=B1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20#1005681=20--bug=3D1005681=20--user=3D=E8=B5=B5=E5=8B=87=20?= =?UTF-8?q?=E3=80=90=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8=E5=8C=96=E3=80=91?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8A=A5...=20https://www.tapd.cn/55049933/s?= =?UTF-8?q?/1037540?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/parse/MsScenarioParser.java | 15 ++++++++ .../automation/report/SysnApiReportDetail.vue | 38 ++++++++++--------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java index 2f82272546..9f16baa44c 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java @@ -65,6 +65,20 @@ public class MsScenarioParser extends MsAbstractParser { return scenarioWithBLOBs; } + private void formatHashTree(JSONArray hashTree) { + if (CollectionUtils.isNotEmpty(hashTree)) { + for (int i = 0; i < hashTree.size(); i++) { + JSONObject object = (JSONObject) hashTree.get(i); + object.put("index", i + 1); + object.put("resourceId", UUID.randomUUID().toString()); + hashTree.set(i, object); + if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) { + formatHashTree(object.getJSONArray("hashTree")); + } + } + } + } + private ScenarioImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) { ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class); List data = scenarioImport.getData(); @@ -88,6 +102,7 @@ public class MsScenarioParser extends MsAbstractParser { JSONObject scenarioDefinition = JSONObject.parseObject(scenarioDefinitionStr); if (scenarioDefinition != null) { JSONArray hashTree = scenarioDefinition.getJSONArray("hashTree"); + formatHashTree(hashTree); setCopy(hashTree); JSONObject environmentMap = scenarioDefinition.getJSONObject("environmentMap"); if (environmentMap != null) { diff --git a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue index 92517557e5..39c64f6946 100644 --- a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue @@ -107,7 +107,13 @@ export default { }, created() { if (this.scenarioId) { - this.getApiScenario(); + this.getApiScenario().then(() => { + this.initTree(); + this.initWebSocket(); + this.initMessageSocket(); + this.clearDebug(); + this.loading = false; + }); } else { if (this.scenario && this.scenario.scenarioDefinition) { this.content.scenarioStepTotal = this.scenario.scenarioDefinition.hashTree.length; @@ -129,24 +135,21 @@ export default { methods: { getApiScenario() { this.loading = true; - this.result = this.$get("/api/automation/getApiScenario/" + this.scenarioId, response => { - if (response.data) { - this.path = "/api/automation/update"; - if (response.data.scenarioDefinition != null) { - let obj = JSON.parse(response.data.scenarioDefinition); - this.scenario.scenarioDefinition = obj; - this.scenario.name = response.data.name; - this.content.scenarioStepTotal = obj.hashTree.length; - this.initTree(); - this.initWebSocket(); - this.initMessageSocket(); - this.clearDebug(); - if (this.scenario.scenarioDefinition && this.scenario.scenarioDefinition.hashTree) { - this.sort(this.scenario.scenarioDefinition.hashTree); + return new Promise((resolve) => { + this.result = this.$get("/api/automation/getApiScenario/" + this.scenarioId, response => { + if (response.data) { + if (response.data.scenarioDefinition != null) { + let obj = JSON.parse(response.data.scenarioDefinition); + this.scenario.scenarioDefinition = obj; + this.scenario.name = response.data.name; + this.content.scenarioStepTotal = obj.hashTree.length; + if (this.scenario.scenarioDefinition && this.scenario.scenarioDefinition.hashTree) { + this.sort(this.scenario.scenarioDefinition.hashTree); + } + resolve(); } - this.loading = false; } - } + }) }) }, sort(stepArray) { @@ -156,7 +159,6 @@ export default { stepArray[i].resourceId = getUUID(); } if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) { - this.stepSize += stepArray[i].hashTree.length; this.sort(stepArray[i].hashTree); } }