diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index f739b7de51..fd7706dff5 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -133,7 +133,7 @@ public class ApiAutomationController { } @PostMapping("/file/download") - public ResponseEntity downloadJmx(@RequestBody FileOperationRequest fileOperationRequest) { + public ResponseEntity download(@RequestBody FileOperationRequest fileOperationRequest) { byte[] bytes = apiAutomationService.loadFileAsBytes(fileOperationRequest); return ResponseEntity.ok() .contentType(MediaType.parseMediaType("application/octet-stream")) 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 48934297bc..bfe437de64 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -234,7 +234,7 @@ public class ApiDefinitionService { test.setResponse(JSONObject.toJSONString(request.getResponse())); test.setEnvironmentId(request.getEnvironmentId()); test.setUserId(request.getUserId()); - test.setTags(JSON.toJSONString(new HashSet<>(request.getTags()))); + test.setTags(request.getTags()); apiDefinitionMapper.updateByPrimaryKeySelective(test); return test; @@ -265,7 +265,7 @@ public class ApiDefinitionService { test.setUserId(request.getUserId()); } test.setDescription(request.getDescription()); - test.setTags(JSON.toJSONString(new HashSet<>(request.getTags()))); + test.setTags(request.getTags()); apiDefinitionMapper.insert(test); return test; } @@ -341,10 +341,11 @@ public class ApiDefinitionService { /** * 内部构建HashTree 定时任务发起的执行 + * * @param request * @return */ - public String run(RunDefinitionRequest request,ApiTestCaseWithBLOBs item) { + public String run(RunDefinitionRequest request, ApiTestCaseWithBLOBs item) { MsTestPlan testPlan = new MsTestPlan(); testPlan.setHashTree(new LinkedList<>()); HashTree jmeterHashTree = new ListedHashTree(); @@ -361,12 +362,14 @@ public class ApiDefinitionService { // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { LinkedList elements = mapper.readValue(element.getString("hashTree"), - new TypeReference>() {}); + new TypeReference>() { + }); scenario.setHashTree(elements); } if (StringUtils.isNotEmpty(element.getString("variables"))) { - LinkedList variables = mapper.readValue(element.getString("variables"), - new TypeReference>() {}); + LinkedList variables = mapper.readValue(element.getString("variables"), + new TypeReference>() { + }); scenario.setVariables(variables); } group.setEnableCookieShare(scenario.isEnableCookieShare()); @@ -571,9 +574,9 @@ public class ApiDefinitionService { apiDefinitionMapper.deleteByExample(example); } - private List getAllApiIdsByFontedSelect(List filter, String name, List moduleIds, String projectId, List unSelectIds) { + private List getAllApiIdsByFontedSelect(Map> filters, String name, List moduleIds, String projectId, List unSelectIds) { ApiDefinitionRequest request = new ApiDefinitionRequest(); - request.setFilters(filter); + request.setFilters(filters); request.setName(name); request.setModuleIds(moduleIds); request.setProjectId(projectId); @@ -621,4 +624,4 @@ public class ApiDefinitionService { } } } -} +} \ No newline at end of file diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index fd5ab5369b..269b51f1ad 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -6,7 +6,7 @@
- {{$t('commons.save')}} + {{$t('commons.save')}}
@@ -220,7 +220,7 @@ - + @@ -456,6 +456,10 @@ }, setVariables(v) { this.currentScenario.variables = v; + if (this.path.endsWith("/update")) { + // 直接更新场景防止编辑内容丢失 + this.editScenario(); + } }, showButton(...names) { for (const name of names) { @@ -677,12 +681,17 @@ this.$error(this.$t('api_test.environment.select_environment')); return; } - this.debugData = { - id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", - variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, - environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition - }; - this.reportId = getUUID().substring(0, 8); + this.$refs['currentScenario'].validate((valid) => { + if (valid) { + this.editScenario(); + this.debugData = { + id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", + variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, + environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition + }; + this.reportId = getUUID().substring(0, 8); + } + }) }, getEnvironments() { if (this.projectId) { @@ -821,13 +830,15 @@ }) return bodyUploadFiles; }, - editScenario() { + editScenario(showMessage) { this.$refs['currentScenario'].validate((valid) => { if (valid) { this.setParameter(); let bodyFiles = this.getBodyUploadFiles(this.currentScenario); this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, response => { - this.$success(this.$t('commons.save_success')); + if (showMessage) { + this.$success(this.$t('commons.save_success')); + } this.path = "/api/automation/update"; if (response.data) { this.currentScenario.id = response.data.id; diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue b/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue index 3dcc73dd4a..092979f24c 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue @@ -1,81 +1,30 @@ diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditCounter.vue b/frontend/src/business/components/api/automation/scenario/variable/EditCounter.vue index 2ba19cf61b..866ca7a900 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditCounter.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditCounter.vue @@ -1,89 +1,38 @@ - diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditCsv.vue b/frontend/src/business/components/api/automation/scenario/variable/EditCsv.vue index b56d068aa9..269022f9a2 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditCsv.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditCsv.vue @@ -1,89 +1,79 @@ diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditListValue.vue b/frontend/src/business/components/api/automation/scenario/variable/EditListValue.vue index a1123e53b8..7dcdf99c62 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditListValue.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditListValue.vue @@ -1,81 +1,30 @@ diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditRandom.vue b/frontend/src/business/components/api/automation/scenario/variable/EditRandom.vue index d55c8e6c0a..7f80648514 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditRandom.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditRandom.vue @@ -1,87 +1,37 @@ diff --git a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue index 9bf6ec9ef2..271b815c87 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue @@ -1,27 +1,36 @@ @@ -87,48 +91,19 @@ selection: [], loading: false, currentPage: 1, + editData: {}, pageSize: 10, total: 0, } }, methods: { handleClick(command) { - switch (command) { - case "CONSTANT": - this.$refs.parameters.open(); - break; - case "LIST": - this.$refs.listValue.open(); - break; - case "CSV": - this.$refs.csv.open(); - break; - case "COUNTER": - this.$refs.counter.open(); - break; - case "RANDOM": - this.$refs.random.open(); - break; - } + this.editData = {}; + this.editData.type = command; + this.addParameters(this.editData); }, edit(row) { - switch (row.type) { - case "CONSTANT": - this.$refs.parameters.open(row); - break; - case "LIST": - this.$refs.listValue.open(row); - break; - case "CSV": - this.$refs.csv.open(row); - break; - case "COUNTER": - this.$refs.counter.open(row); - break; - case "RANDOM": - this.$refs.random.open(row); - break; - } + this.editData = row; }, addParameters(v) { v.id = getUUID(); @@ -148,9 +123,17 @@ open: function (variables) { this.variables = variables; this.visible = true; + this.editData = {type: "CONSTANT"}; + this.addParameters(this.editData); }, close() { this.visible = false; + this.variables.forEach(item => { + if (item.name === undefined || item.name === "") { + const index = this.variables.findIndex(d => d.id === item.id); + this.variables.splice(index, 1); + } + }) this.$emit('setVariables', this.variables); }, deleteVariable() {