diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java index d72c4085c1..b6ccfc2d6b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java @@ -70,12 +70,16 @@ public class ApiDefinitionImportUtil { private static void createNodeTree(NodeTree nodeTree, String pid, String projectId, ApiModuleService apiModuleService, String path, int baseLevel) { + ApiModule apiModule = apiModuleService.get(pid); ApiModule module = new ApiModule(); BeanUtils.copyBean(module, nodeTree); apiModuleService.buildNewModule(module); module.setProjectId(projectId); module.setParentId(pid); module.setLevel(module.getLevel() + baseLevel); + if (apiModule != null) { + module.setProtocol(apiModule.getProtocol()); + } createModule(module, SessionUtils.getUserId()); nodeTree.setNewId(module.getId()); path = path + nodeTree.getName(); @@ -91,6 +95,7 @@ public class ApiDefinitionImportUtil { /** * 根据导出的模块树,创建新的模块树 + * * @param nodeTree * @param projectId */ @@ -124,12 +129,14 @@ public class ApiDefinitionImportUtil { } public static void createModule(ApiModule module) { - createModule(module, null); + createModule(module, null); } public static void createModule(ApiModule module, String userId) { ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class); - module.setProtocol(RequestType.HTTP); + if (StringUtils.isEmpty(module.getProtocol())) { + module.setProtocol(RequestType.HTTP); + } if (module.getName().length() > 64) { module.setName(module.getName().substring(0, 64)); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index 325608cede..5aae6559d6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -60,6 +60,9 @@ public class ApiModuleService extends NodeTreeService { super(ApiModuleDTO.class); } + public ApiModule get(String id) { + return apiModuleMapper.selectByPrimaryKey(id); + } public List getNodeTreeByProjectId(String projectId, String protocol) { // 判断当前项目下是否有默认模块,没有添加默认模块 this.getDefaultNode(projectId,protocol); diff --git a/frontend/src/business/components/api/automation/api-automation.js b/frontend/src/business/components/api/automation/api-automation.js index 126fc368f0..36a33ee048 100644 --- a/frontend/src/business/components/api/automation/api-automation.js +++ b/frontend/src/business/components/api/automation/api-automation.js @@ -70,9 +70,9 @@ function getScenarioFiles(obj) { return scenarioFiles; } -export function saveScenario(url, scenario, scenarioDefinition, _this,success) { +export function saveScenario(url, scenario, scenarioDefinition, _this, success) { let bodyFiles = getBodyUploadFiles(scenario, scenarioDefinition); - if (_this.$store.state.pluginFiles && _this.$store.state.pluginFiles.length > 0) { + if (_this && _this.$store && _this.$store.state && _this.$store.state.pluginFiles && _this.$store.state.pluginFiles.length > 0) { _this.$store.state.pluginFiles.forEach(fileItem => { if (fileItem.file) { scenario.bodyFileRequestIds.push(fileItem.file.uid); diff --git a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue index f449caf460..019aa564b7 100644 --- a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue @@ -101,7 +101,8 @@ this.$emit('saveAsEdit', this.scenarioForm); this.visible = false; } else { - saveScenario(path, this.scenarioForm, [], () => { + saveScenario(path, this.scenarioForm, [], this,(response) => { + this.$success(this.$t('commons.save_success')); this.visible = false; this.$emit('refresh'); });