diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index 0b9b7ea4aa..1bb9bb43d8 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -272,8 +272,7 @@ public class ApiDefinitionController { @GetMapping("/getMockEnvironment/{projectId}") public ApiTestEnvironmentWithBLOBs getMockEnvironment(@PathVariable String projectId, HttpServletRequest request) { - System.out.println(request.getRequestURL()); - String requestUrl = request.getRequestURI(); + String requestUrl = request.getRequestURL().toString(); String baseUrl = ""; if (requestUrl.contains("/api/definition")) { baseUrl = requestUrl.split("/api/definition")[0]; 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 e5a0b2899b..b87e1721a4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -194,7 +194,11 @@ public class ApiDefinitionService { } public void reduction(ApiBatchRequest request) { - extApiDefinitionMapper.reduction(request.getIds()); + ServiceUtils.getSelectAllIds(request, request.getCondition(), + (query) -> extApiDefinitionMapper.selectIds(query)); + if (request.getIds() != null || !request.getIds().isEmpty()) { + extApiDefinitionMapper.reduction(request.getIds()); + } } public void deleteBodyFiles(String apiId) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java index 2eb1858d77..499af412a5 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java @@ -94,6 +94,7 @@ public class ApiTestEnvironmentService { private ApiTestEnvironmentWithBLOBs genHttpApiTestEnvironmentByUrl(String projectId, String name, String url) { String protocol = ""; + String socket = ""; if (url.startsWith("http://")) { protocol = "http"; url = url.substring(7); @@ -101,6 +102,7 @@ public class ApiTestEnvironmentService { protocol = "https"; url = url.substring(8); } + socket = url; String portStr = ""; String ipStr = protocol; @@ -127,13 +129,42 @@ public class ApiTestEnvironmentService { commonConfigObj.put("hosts", new String[]{}); JSONObject httpConfig = new JSONObject(); - httpConfig.put("socket", url); - httpConfig.put("domain", ipStr); - httpConfig.put("headers", variablesArr); - httpConfig.put("protocol", protocol); +// httpConfig.put("socket", url); +// httpConfig.put("domain", ipStr); +// httpConfig.put("headers", variablesArr); +// httpConfig.put("protocol", protocol); +// if (StringUtils.isNotEmpty(portStr)) { +// httpConfig.put("port", portStr); +// } + httpConfig.put("socket", null); + httpConfig.put("domain", null); + httpConfig.put("headers", new JSONArray(variablesArr)); + httpConfig.put("protocol", null); + httpConfig.put("port", null); + JSONArray httpItemArr = new JSONArray(); + JSONObject httpItem = new JSONObject(); + httpItem.put("id", UUID.randomUUID().toString()); + httpItem.put("type", "NONE"); + httpItem.put("socket", socket); + httpItem.put("protocol", protocol); + httpItem.put("headers", new JSONArray(variablesArr)); + httpItem.put("domain", ipStr); if (StringUtils.isNotEmpty(portStr)) { - httpConfig.put("port", portStr); + httpItem.put("port", portStr); + } else { + httpItem.put("port", ""); } + JSONArray detailArr = new JSONArray(); + JSONObject detailObj = new JSONObject(); + detailObj.put("name", ""); + detailObj.put("value", "contains"); + detailObj.put("enable", true); + detailArr.add(detailObj); + httpItem.put("details", detailArr); + + httpItemArr.add(httpItem); + httpConfig.put("conditions", httpItemArr); + httpConfig.put("defaultCondition", "NONE"); JSONArray databaseConfigObj = new JSONArray(); diff --git a/backend/src/main/java/io/metersphere/base/domain/MockConfig.java b/backend/src/main/java/io/metersphere/base/domain/MockConfig.java index 2cb178a08d..4264034bfa 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MockConfig.java +++ b/backend/src/main/java/io/metersphere/base/domain/MockConfig.java @@ -1,9 +1,9 @@ package io.metersphere.base.domain; -import java.io.Serializable; - import lombok.Data; +import java.io.Serializable; + @Data public class MockConfig implements Serializable { private String id; @@ -23,4 +23,5 @@ public class MockConfig implements Serializable { private String createUserId; private static final long serialVersionUID = 1L; + } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/ProjectController.java b/backend/src/main/java/io/metersphere/controller/ProjectController.java index 9f4321d986..c94015f275 100644 --- a/backend/src/main/java/io/metersphere/controller/ProjectController.java +++ b/backend/src/main/java/io/metersphere/controller/ProjectController.java @@ -2,6 +2,7 @@ package io.metersphere.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.Project; import io.metersphere.commons.constants.RoleConstants; @@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.List; @RestController @@ -27,6 +29,8 @@ public class ProjectController { private ProjectService projectService; @Resource private CheckPermissionService checkPermissionService; + @Resource + private ApiTestEnvironmentService apiTestEnvironmentService; @GetMapping("/listAll") public List listAll() { @@ -62,8 +66,18 @@ public class ProjectController { @PostMapping("/add") @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER,}, logical = Logical.OR) - public Project addProject(@RequestBody Project project) { - return projectService.addProject(project); + public Project addProject(@RequestBody Project project, HttpServletRequest request) { + Project returnModel = projectService.addProject(project); + + //创建项目的时候默认增加Mock环境 + String requestUrl = request.getRequestURL().toString(); + String baseUrl = ""; + if (requestUrl.contains("/project/add")) { + baseUrl = requestUrl.split("/project/add")[0]; + } + apiTestEnvironmentService.getMockEnvironmentByProjectId(returnModel.getId(), baseUrl); + + return returnModel; } @PostMapping("/list/{goPage}/{pageSize}") diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index ac8b91ab54..bfb23fdb4a 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -8,38 +8,20 @@ @keyup.enter.native="search" v-model="condition.name"/> - - - - - - - - + > - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -218,9 +356,11 @@ import MsTableOperator from "../../../../common/components/MsTableOperator"; import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton"; import MsTableButton from "../../../../common/components/MsTableButton"; import MsTablePagination from "../../../../common/pagination/TablePagination"; +import MsTable from "@/business/components/common/components/table/MsTable"; import MsTag from "../../../../common/components/MsTag"; import MsApiCaseList from "../case/ApiCaseList"; import MsContainer from "../../../../common/components/MsContainer"; +import MsTableColumn from "@/business/components/common/components/table/Ms-table-column"; import MsBottomContainer from "../BottomContainer"; import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn"; import MsBatchEdit from "../basis/BatchEdit"; @@ -272,7 +412,9 @@ export default { ShowMoreBtn, MsBatchEdit, MsTipButton, - MsTableAdvSearchBar + MsTableAdvSearchBar, + MsTable, + MsTableColumn }, data() { return { @@ -301,6 +443,17 @@ export default { name: "批量恢复", handleClick: this.handleBatchRestore }, ], + tableOperatorButtons: [], + tableUsualOperatorButtons: [ + {tip: this.$t('api_test.automation.execute'), icon: "el-icon-video-play", exec: this.runApi}, + {tip: this.$t('commons.edit'), icon: "el-icon-edit", exec: this.editApi}, + {tip: "CASE", exec: this.handleTestCase, isDivButton: true, type: "primary"}, + {tip: this.$t('commons.delete'), exec: this.handleDelete, icon: "el-icon-delete", type: "danger"}, + ], + tableTrashOperatorButtons: [ + {tip: this.$t('api_test.automation.execute'), icon: "el-icon-video-play", exec: this.runApi}, + {tip: this.$t('commons.reduction'), icon: "el-icon-refresh-left", exec: this.reductionApi}, + ], typeArr: [ {id: 'status', name: this.$t('api_test.definition.api_status')}, {id: 'method', name: this.$t('api_test.definition.api_type')}, @@ -383,8 +536,10 @@ export default { }, created: function () { if (this.trashEnable) { + this.tableOperatorButtons = this.tableTrashOperatorButtons; this.condition.filters = {status: ["Trash"]}; } else { + this.tableOperatorButtons = this.tableUsualOperatorButtons; this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; } this.initTable(); @@ -393,6 +548,8 @@ export default { watch: { selectNodeIds() { initCondition(this.condition, false); + this.condition.moduleIds = []; + this.condition.moduleIds.push(this.selectNodeIds); this.initTable(); }, currentProtocol() { @@ -401,9 +558,11 @@ export default { }, trashEnable() { if (this.trashEnable) { + this.tableOperatorButtons = this.tableTrashOperatorButtons; this.condition.filters = {status: ["Trash"]}; this.condition.moduleIds = []; } else { + this.tableOperatorButtons = this.tableUsualOperatorButtons; this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; } initCondition(this.condition, false); @@ -465,37 +624,14 @@ export default { // nexttick:表格加载完成之后触发。判断是否需要勾选行 this.$nextTick(function () { if (this.$refs.apiDefinitionTable) { - setTimeout(this.$refs.apiDefinitionTable.doLayout, 200); + this.$refs.apiDefinitionTable.checkTableRowIsSelect(); + setTimeout(this.$refs.apiDefinitionTable.doLayout(), 200); } - this.checkTableRowIsSelect(); }) }); } getLabel(this, API_LIST); }, - checkTableRowIsSelect() { - //如果默认全选的话,则选中应该选中的行 - if (this.condition.selectAll) { - let unSelectIds = this.condition.unSelectIds; - this.tableData.forEach(row => { - if (unSelectIds.indexOf(row.id) < 0) { - this.$refs.apiDefinitionTable.toggleRowSelection(row, true); - - //默认全选,需要把选中对行添加到selectRows中。不然会影响到勾选函数统计 - if (!this.selectRows.has(row)) { - this.$set(row, "showMore", true); - this.selectRows.add(row); - } - } else { - //不勾选的行,也要判断是否被加入了selectRow中。加入了的话就去除。 - if (this.selectRows.has(row)) { - this.$set(row, "showMore", false); - this.selectRows.delete(row); - } - } - }) - } - }, genProtocalFilter(protocalType) { if (protocalType === "HTTP") { this.methodFilters = [ diff --git a/frontend/src/business/components/common/components/MsTableOperatorButton.vue b/frontend/src/business/components/common/components/MsTableOperatorButton.vue index aa395faa2f..5723046459 100644 --- a/frontend/src/business/components/common/components/MsTableOperatorButton.vue +++ b/frontend/src/business/components/common/components/MsTableOperatorButton.vue @@ -1,11 +1,26 @@ diff --git a/frontend/src/business/components/common/components/MsTableOperators.vue b/frontend/src/business/components/common/components/MsTableOperators.vue index 65d924fdec..212a092bfd 100644 --- a/frontend/src/business/components/common/components/MsTableOperators.vue +++ b/frontend/src/business/components/common/components/MsTableOperators.vue @@ -2,7 +2,7 @@ diff --git a/frontend/src/business/components/common/components/table/Ms-table-column.vue b/frontend/src/business/components/common/components/table/Ms-table-column.vue index 83c3463174..b120712df0 100644 --- a/frontend/src/business/components/common/components/table/Ms-table-column.vue +++ b/frontend/src/business/components/common/components/table/Ms-table-column.vue @@ -1,14 +1,14 @@