From d3fccb25d6812452cb4f1a180b0025d514cb53ea Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 29 Mar 2021 14:43:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?):=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=81=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=9A=E4=B9=89=E3=80=81=E5=9C=BA=E6=99=AF=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=20=E5=A2=9E=E5=8A=A0=E2=80=9C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A8=A1=E5=9D=97=E2=80=9D=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E3=80=81=E5=9C=BA=E6=99=AF=E6=97=B6=20?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E6=A8=A1=E5=9D=97=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E4=B8=BA=E2=80=9C=E9=BB=98=E8=AE=A4=E6=A8=A1=E5=9D=97=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 4 ++ .../api/automation/ApiAutomation.vue | 2 +- .../automation/scenario/ApiScenarioModule.vue | 23 ++++++--- .../automation/scenario/EditApiScenario.vue | 26 +++++----- .../automation/scenario/api/AddBasisApi.vue | 23 ++++++--- .../scenario/common/ScenarioImport.vue | 23 ++++++--- .../components/case/ApiCaseItem.vue | 2 +- .../components/module/ApiModule.vue | 3 +- .../common/select-tree/SelectTree.vue | 6 ++- .../track/case/components/TestCaseEdit.vue | 50 +++++++++---------- .../components/track/common/NodeTree.vue | 2 +- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 14 files changed, 98 insertions(+), 69 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 1f4992379..3fdb6bd2a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -234,6 +234,10 @@ public class ApiAutomationService { } else { scenario.setUserId(request.getUserId()); } + if (StringUtils.isEmpty(request.getApiScenarioModuleId()) || StringUtils.isEmpty(request.getModulePath())) { + scenario.setApiScenarioModuleId("root"); + scenario.setModulePath("/默认模块"); + } return scenario; } diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 4548ab4f3..18d4becb3 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -189,7 +189,7 @@ let label = this.$t('api_test.automation.add_scenario'); let name = getUUID().substring(0, 8); this.activeName = name; - this.tabs.push({label: label, name: name, currentScenario: {apiScenarioModuleId: "", id: getUUID()}}); + this.tabs.push({label: label, name: name, currentScenario: {apiScenarioModuleId: "root", id: getUUID()}}); } if (tab.name === 'edit') { let label = this.$t('api_test.automation.add_scenario'); diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue index 320886156..fc3266b5b 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue @@ -29,7 +29,7 @@ @refresh="refresh" ref="basisScenario"/> - + @@ -38,7 +38,7 @@ import SelectMenu from "../../../track/common/SelectMenu"; import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario"; import MsNodeTree from "../../../track/common/NodeTree"; - import {buildNodePath} from "../../definition/model/NodeTree"; + import {buildNodePath, buildTree} from "../../definition/model/NodeTree"; import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton"; import ApiImport from "./common/ScenarioImport"; import MsSearchBar from "@/business/components/common/components/search/MsSearchBar"; @@ -82,9 +82,10 @@ trashEnable: false }, data: [], + extendTreeNodes: [], currentModule: undefined, moduleOptions: [], - operators: [ + operators: [ { label: this.$t('api_test.automation.add_scenario'), callback: this.addScenario @@ -97,7 +98,7 @@ label: this.$t('report.export'), children: [ { - label: this.$t('report.export_to_ms_format') , + label: this.$t('report.export_to_ms_format'), callback: () => { this.$emit('exportAPI'); } @@ -187,11 +188,17 @@ this.result = this.$get(url, response => { if (response.data != undefined && response.data != null) { this.data = response.data; - let moduleOptions = []; - this.data.forEach(node => { - buildNodePath(node, {path: ''}, moduleOptions); + this.extendTreeNodes = []; + this.extendTreeNodes.unshift({ + "id": "root", + "name": this.$t('commons.module_title'), + "level": 0, + "children": this.data, }); - this.$emit('setModuleOptions', moduleOptions); + this.extendTreeNodes.forEach(node => { + buildTree(node, {path: ''}); + }); + this.$emit('setModuleOptions', this.extendTreeNodes); this.$emit('setNodeTree', this.data); if (this.$refs.nodeTree) { this.$refs.nodeTree.filter(this.condition.filterText); diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index ffdc9e430..67f1a0fc0 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -22,9 +22,7 @@ - - - + @@ -244,6 +242,7 @@ import MaximizeScenario from "./maximize/MaximizeScenario"; import ScenarioHeader from "./maximize/ScenarioHeader"; import MsDrawer from "../../../common/components/MsDrawer"; + import MsSelectTree from "../../../common/select-tree/SelectTree"; let jsonPath = require('jsonpath'); export default { @@ -266,7 +265,8 @@ EnvPopover, MaximizeScenario, ScenarioHeader, - MsDrawer + MsDrawer, + MsSelectTree }, data() { return { @@ -274,6 +274,10 @@ label: "label", children: "hashTree" }, + moduleObj: { + id: 'id', + label: 'name', + }, rules: { name: [ {required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'}, @@ -450,6 +454,10 @@ }, }, methods: { + setModule(id,data) { + this.currentScenario.apiScenarioModuleId = id; + this.currentScenario.modulePath = data.path; + }, setHideBtn() { this.isBtnHide = false; }, @@ -905,15 +913,6 @@ this.expandedNode.splice(this.expandedNode.indexOf(data.resourceId), 1); } }, - getPath(id) { - if (id === null) { - return null; - } - let path = this.moduleOptions.filter(function (item) { - return item.id === id ? item.path : ""; - }); - return path[0].path; - }, setFiles(item, bodyUploadFiles, obj) { if (item.body) { if (item.body.kvs) { @@ -1071,7 +1070,6 @@ setParameter() { this.currentScenario.stepTotal = this.scenarioDefinition.length; this.currentScenario.projectId = this.projectId; - this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId); // 构建一个场景对象 方便引用处理 let scenario = { id: this.currentScenario.id, diff --git a/frontend/src/business/components/api/automation/scenario/api/AddBasisApi.vue b/frontend/src/business/components/api/automation/scenario/api/AddBasisApi.vue index efc4474c9..31f10c779 100644 --- a/frontend/src/business/components/api/automation/scenario/api/AddBasisApi.vue +++ b/frontend/src/business/components/api/automation/scenario/api/AddBasisApi.vue @@ -31,7 +31,7 @@ - + @@ -64,6 +64,7 @@ import {createComponent, Request} from "../../../definition/components/jmeter/components"; import {getUUID} from "@/common/js/utils"; import MsSelectTree from "@/business/components/common/select-tree/SelectTree"; + import {buildTree} from "../../../definition/model/NodeTree"; export default { @@ -83,7 +84,7 @@ callback(); }; return { - httpForm: {environmentId: ""}, + httpForm: {environmentId: "", moduleId: "root"}, moduleOptions: [], httpVisible: false, currentModule: {}, @@ -250,13 +251,23 @@ let url = "/api/module/list/" + getCurrentProjectID() + "/" + data.protocol; this.result = this.$get(url, response => { if (response.data != undefined && response.data != null) { - this.moduleOptions = response.data; + let data = response.data; + this.moduleOptions = []; + this.moduleOptions.unshift({ + "id": "root", + "name": this.$t('commons.module_title'), + "level": 0, + "children": data, + }); + this.moduleOptions.forEach(node => { + buildTree(node, {path: ''}); + }); } }); }, - setModule(id) { + setModule(id, data) { this.httpForm.moduleId = id; - //this.reload(); + this.httpForm.modulePath = data.path; }, reload() { this.loading = true @@ -271,7 +282,7 @@ data.protocol = "DUBBO"; } data.id = getUUID(); - this.httpForm = {id: data.id, name: data.name, protocol: data.protocol, path: data.path, method: api.method, userId: getCurrentUser().id, request: data}; + this.httpForm = {id: data.id, name: data.name, protocol: data.protocol, path: data.path, method: api.method, userId: getCurrentUser().id, request: data, moduleId: "root"}; this.getMaintainerOptions(); this.list(data); this.httpVisible = true; diff --git a/frontend/src/business/components/api/automation/scenario/common/ScenarioImport.vue b/frontend/src/business/components/api/automation/scenario/common/ScenarioImport.vue index c9a403c7e..2c80c66d8 100644 --- a/frontend/src/business/components/api/automation/scenario/common/ScenarioImport.vue +++ b/frontend/src/business/components/api/automation/scenario/common/ScenarioImport.vue @@ -22,11 +22,9 @@ - - - + - + @@ -70,16 +68,17 @@ diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue index 58229c045..59e5afaa6 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue @@ -281,7 +281,7 @@ let data = this.api; data.name = this.apiCase.name; data.moduleId = module; - data.modulePath = '/默认模块'; + data.modulePath ="/"+ this.$t('commons.module_title'); this.setParameters(data); let bodyFiles = this.getBodyUploadFiles(data); this.$fileUpload("/api/definition/create", null, bodyFiles, data, () => { diff --git a/frontend/src/business/components/api/definition/components/module/ApiModule.vue b/frontend/src/business/components/api/definition/components/module/ApiModule.vue index 5e71e5268..d5b90d1b4 100644 --- a/frontend/src/business/components/api/definition/components/module/ApiModule.vue +++ b/frontend/src/business/components/api/definition/components/module/ApiModule.vue @@ -7,7 +7,6 @@ v-loading="result.loading" :tree-nodes="data" :type="isReadOnly ? 'view' : 'edit'" - :allLabel="'默认模块'" @add="add" @edit="edit" @drag="drag" @@ -135,7 +134,7 @@ this.extendTreeNodes = []; this.extendTreeNodes.unshift({ "id": "root", - "name": "默认模块", + "name": this.$t('commons.module_title'), "level": 0, "children": this.data, }); diff --git a/frontend/src/business/components/common/select-tree/SelectTree.vue b/frontend/src/business/components/common/select-tree/SelectTree.vue index dee9aec6d..903273af6 100644 --- a/frontend/src/business/components/common/select-tree/SelectTree.vue +++ b/frontend/src/business/components/common/select-tree/SelectTree.vue @@ -236,7 +236,9 @@ setKey(thisKey) { this.$refs.tree.setCurrentKey(thisKey); let node = this.$refs.tree.getNode(thisKey); - this.setData(node.data); + if (node && node.data) { + this.setData(node.data); + } }, //单选:设置、初始化对象 setData(data) { @@ -287,7 +289,7 @@ }, //下拉框关闭执行 popoverHide() { - this.$emit('getValue', this.returnDataKeys, this.returnDatas); + this.$emit('getValue', this.returnDataKeys, this.returnDatas ? this.returnDatas : {}); }, // 多选,清空所有勾选 clearSelectedNodes() { diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index d9f4e9823..21a57d13d 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -35,20 +35,8 @@ - - - - + @@ -292,7 +280,7 @@ import MsDialogFooter from '../../../common/components/MsDialogFooter' import {getCurrentUser, handleCtrlSEvent, listenGoBack, removeGoBackListener} from "@/common/js/utils"; import {Message} from "element-ui"; import TestCaseAttachment from "@/business/components/track/case/components/TestCaseAttachment"; -import {buildNodePath} from "../../../api/definition/model/NodeTree"; +import {buildNodePath,buildTree} from "../../../api/definition/model/NodeTree"; import CaseComment from "@/business/components/track/case/components/CaseComment"; import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag"; import MsPreviousNextButton from "../../../common/components/MsPreviousNextButton"; @@ -301,12 +289,13 @@ import TestCaseComment from "@/business/components/track/case/components/TestCas import ReviewCommentItem from "@/business/components/track/review/commom/ReviewCommentItem"; import {API_STATUS, REVIEW_STATUS, TEST} from "@/business/components/api/definition/model/JsonData"; import MsTableButton from "@/business/components/common/components/MsTableButton"; +import MsSelectTree from "../../../common/select-tree/SelectTree"; export default { name: "TestCaseEdit", components: { MsTableButton, - + MsSelectTree, ReviewCommentItem, TestCaseComment, MsPreviousNextButton, MsInputTag, CaseComment, MsDialogFooter, TestCaseAttachment }, @@ -325,7 +314,8 @@ export default { dialogFormVisible: false, form: { name: '', - module: '', + module: 'root', + nodePath:'', maintainer: getCurrentUser().id, priority: 'P0', type: '', @@ -381,6 +371,10 @@ export default { index: 0, showInputTag: true, tableType:"", + moduleObj: { + id: 'id', + label: 'name', + }, }; }, props: { @@ -435,6 +429,10 @@ export default { this.addListener(); // 添加 ctrl s 监听 }, methods: { + setModule(id,data) { + this.form.module = id; + this.form.nodePath = data.path; + }, clearInput() { //this.$refs['cascade'].panel.clearCheckedNodes() }, @@ -761,11 +759,6 @@ export default { Object.assign(param, this.form); param.steps = JSON.stringify(this.form.steps); param.nodeId = this.form.module; - this.moduleOptions.forEach(item => { - if (this.form.module === item.id) { - param.nodePath = item.path; - } - }); if (this.projectId) { param.projectId = this.projectId; } @@ -838,11 +831,16 @@ export default { this.getTestOptions() }, getModuleOptions() { - let moduleOptions = []; - this.treeNodes.forEach(node => { - buildNodePath(node, {path: ''}, moduleOptions); + this.moduleOptions = []; + this.moduleOptions.unshift({ + "id": "root", + "name": this.$t('commons.module_title'), + "level": 0, + "children": this.treeNodes, + }); + this.moduleOptions.forEach(node => { + buildTree(node, {path: ''}); }); - this.moduleOptions = moduleOptions; }, getMaintainerOptions() { let workspaceId = localStorage.getItem(WORKSPACE_ID); diff --git a/frontend/src/business/components/track/common/NodeTree.vue b/frontend/src/business/components/track/common/NodeTree.vue index 80a9ea0ab..656b41298 100644 --- a/frontend/src/business/components/track/common/NodeTree.vue +++ b/frontend/src/business/components/track/common/NodeTree.vue @@ -92,7 +92,7 @@ export default { allLabel: { type: String, default() { - return this.$t("commons.all_label.case"); + return this.$t('commons.module_title'); } }, nameLimit: { diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index f18927ae8..94837b728 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -5,6 +5,7 @@ export default { pass_rate: 'Pass rate', execution_times: 'Execution times', cover: 'Cover', + module_title: 'Default module', not_cover: 'Not Cover', import: 'Import', import_success: 'Import success', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 7fc3c87f6..251d71ac4 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -5,6 +5,7 @@ export default { pass_rate: '通过率', execution_times: '执行次数', cover: '覆盖', + module_title: '默认模块', not_cover: '不覆盖', import: '导入', import_success: '导入成功', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index fa27161d1..e9f8dddcd 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -5,6 +5,7 @@ export default { pass_rate: '通過率', execution_times: '執行次數', cover: '覆蓋', + module_title: '默認模塊', not_cover: '不覆蓋', import: '導入', import_success: '導入成功', -- GitLab