From 990ecd17c266405ee1c536724c6553f3f8328dbe Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 10 Mar 2022 18:47:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=9C=BA=E6=99=AF=E6=AD=A5=E9=AA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/automation/ApiAutomation.vue | 13 +- .../automation/scenario/EditApiScenario.vue | 140 ++------- .../api/automation/version/ScenarioDiff.vue | 265 ++++++++++++------ .../request/http/ApiHttpRequestForm.vue | 3 +- 4 files changed, 207 insertions(+), 214 deletions(-) diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 262a724c6d..d7d301c069 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -385,6 +385,9 @@ export default { this.isSave = false; this.isLeave = false; } + if (this.tabs && this.tabs.length === 0) { + this.refreshAll(); + } }, handleCommand(e) { switch (e) { @@ -466,6 +469,9 @@ export default { this.isSave = false; this.removeTab(targetName); } + if (this.tabs && this.tabs.length === 0) { + this.refreshAll(); + } }, removeTab(targetName) { this.tabs = this.tabs.filter(tab => tab.name !== targetName); @@ -496,12 +502,7 @@ export default { }, refresh(data) { this.setTabTitle(data); - this.$refs.apiScenarioList.search(data); - if (this.$refs.apiTrashScenarioList) { - this.$refs.apiTrashScenarioList.search(data); - } this.isSave = true; - this.$refs.nodeTree.list(); }, refreshTree() { if (this.$refs.nodeTree) { @@ -518,7 +519,7 @@ export default { setTabTitle(data) { for (let index in this.tabs) { let tab = this.tabs[index]; - if (tab.name === this.activeName) { + if (tab && tab.name === this.activeName) { tab.label = data.name; break; } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 6e08e63920..221e757734 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -345,18 +345,14 @@ width="100%"> @@ -435,7 +431,6 @@ export default { data() { return { onSampleError: true, - newOnSampleError: true, showConfigButtonWithOutPermission: false, props: { label: "label", @@ -476,26 +471,21 @@ export default { debugVisible: false, customizeRequest: {protocol: "HTTP", type: "API", hashTree: [], referenced: 'Created', active: false}, operatingElements: [], - currentRow: {cases: [], apis: [], referenced: true}, selectedTreeNode: undefined, selectedNode: undefined, expandedNode: [], scenarioDefinition: [], - scenarioDefinitionOrg: [], path: "/api/automation/create", debugData: {}, reportId: "", enableCookieShare: false, - newEnableCookieShare: false, globalOptions: { spacing: 30 }, response: {}, projectIds: new Set, projectEnvMap: new Map, - newProjectEnvMap: new Map, projectList: [], - debugResult: new Map, drawer: false, isFullUrl: true, expandedStatus: false, @@ -527,16 +517,14 @@ export default { environmentType: ENV_TYPE.JSON, executeType: "", versionData: [], - newData: [], - oldData: [], dialogVisible: false, - newScenarioDefinition: [], - oldScenarioDefinition: [], currentItem: {}, pluginDelStep: false, isBatchProcess: false, isCheckedAll: false, selectDataCounts: 0, + dffScenarioId: "", + scenarioRefId: "", batchOperators: [ { name: this.$t('api_test.automation.bulk_activation_steps'), @@ -566,14 +554,6 @@ export default { ], } }, - watch: { - scenarioDefinition: { - handler(v) { - this.currentScenario.scenarioDefinition = v; - }, - deep: true - }, - }, created() { if (!this.currentScenario.apiScenarioModuleId) { this.currentScenario.apiScenarioModuleId = ""; @@ -1496,6 +1476,7 @@ export default { this.currentScenario.tags = JSON.parse(this.currentScenario.tags); } this.pluginDelStep = false; + this.$emit('refresh', this.currentScenario); resolve(); }); } @@ -1552,21 +1533,6 @@ export default { this.environmentType = response.data.environmentType; } this.currentScenario.variables = []; - let index = 1; - if (obj.variables) { - obj.variables.forEach(item => { - // 兼容历史数据 - if (item.name) { - if (!item.type) { - item.type = "CONSTANT"; - item.id = getUUID(); - } - item.num = index; - this.currentScenario.variables.push(item); - index++; - } - }) - } if (obj.headers) { this.currentScenario.headers = obj.headers; } @@ -1578,18 +1544,6 @@ export default { } this.dataProcessing(obj.hashTree); this.scenarioDefinition = obj.hashTree; - let v1 = { - apiScenarioModuleId: this.currentScenario.apiScenarioModuleId, - name: this.currentScenario.name, - status: this.currentScenario.status, - principal: this.currentScenario.principal, - level: this.currentScenario.level, - tags: this.currentScenario.tags, - description: this.currentScenario.description, - scenarioDefinition: this.scenarioDefinition - }; - this.currentScenario.scenarioDefinitionOrg = v1 - this.oldScenarioDefinition = obj.hashTree; } } if (this.currentScenario.copy) { @@ -1606,13 +1560,27 @@ export default { }); } this.loading = false; - this.setDomain(); this.sort(); - this.commandTreeNode(); + this.cancelBatchProcessing(); // 初始化resourceId if (this.scenarioDefinition) { this.resetResourceId(this.scenarioDefinition); } + // 记录初始化数据 + let v1 = { + apiScenarioModuleId: this.currentScenario.apiScenarioModuleId, + name: this.currentScenario.name, + status: this.currentScenario.status, + principal: this.currentScenario.principal, + level: this.currentScenario.level, + tags: this.currentScenario.tags, + description: this.currentScenario.description, + scenarioDefinition: this.scenarioDefinition + }; + + this.currentScenario.scenarioDefinitionOrg = JSON.parse(JSON.stringify(v1)); + this.currentScenario.scenarioDefinition = this.scenarioDefinition; + }) } }, @@ -1750,8 +1718,6 @@ export default { }, detailRefresh(result) { // 把执行结果分发给各个请求 - this.debugResult = result; - this.sort() }, fullScreen() { this.drawer = true; @@ -1900,68 +1866,14 @@ export default { }); }, compare(row) { - this.$get('/api/automation/get/' + row.id + "/" + this.currentScenario.refId, response => { - this.$get("/api/automation/getApiScenario/" + response.data.id, res => { - if (res.data) { - if (res.data.scenarioDefinition != null) { - let obj = JSON.parse(res.data.scenarioDefinition); - if (obj) { - if (obj.hashTree) { - for (let i = 0; i < obj.hashTree.length; i++) { - if (!obj.hashTree[i].index) { - obj.hashTree[i].index = i + 1; - } - obj.hashTree[i].disabled = true; - if (!obj.hashTree[i].requestResult) { - obj.hashTree[i].requestResult = [{responseResult: {}}]; - } - } - this.newEnableCookieShare = obj.enableCookieShare; - if (obj.onSampleError === undefined) { - this.newOnSampleError = true; - } else { - this.newOnSampleError = obj.onSampleError; - } - } - this.dataProcessing(obj.hashTree); - this.newScenarioDefinition = obj.hashTree; - for (let i = 0; i < this.oldScenarioDefinition.length; i++) { - this.oldScenarioDefinition[i].disabled = true; - } - if (response.data.environmentJson) { - this.newProjectEnvMap = objToStrMap(JSON.parse(response.data.environmentJson)); - } else { - // 兼容历史数据 - this.newProjectEnvMap.set(this.projectId, obj.environmentId); - } - } - } - res.data.userName = response.data.userName - this.dealWithTag(res.data); - this.oldData = this.currentScenario; - this.newData = res.data; - this.closeExpansion() - } - this.sort(); - this.dialogVisible = true; - }); - }) + this.scenarioRefId = this.currentScenario.refId; + this.dffScenarioId = row.id; + this.dialogVisible = true; }, closeDiff() { this.oldScenarioDefinition = [] }, - dealWithTag(newScenario) { - if (newScenario.tags) { - if (Object.prototype.toString.call(newScenario.tags) === "[object String]") { - newScenario.tags = JSON.parse(newScenario.tags); - } - } - if (this.currentScenario.tags) { - if (Object.prototype.toString.call(this.currentScenario.tags) === "[object String]") { - this.currentScenario.tags = JSON.parse(this.currentScenario.tags); - } - } - }, + checkout(row) { let api = this.versionData.filter(v => v.versionId === row.id)[0]; if (api.tags && api.tags.length > 0) { diff --git a/frontend/src/business/components/api/automation/version/ScenarioDiff.vue b/frontend/src/business/components/api/automation/version/ScenarioDiff.vue index 847e2e5cc5..9a30a07e92 100644 --- a/frontend/src/business/components/api/automation/version/ScenarioDiff.vue +++ b/frontend/src/business/components/api/automation/version/ScenarioDiff.vue @@ -2,20 +2,22 @@
- 当前{{oldData.versionName }}{{oldData.userName}}{{oldData.createTime | timestampFormatDate }} + 当前{{ oldData.versionName }} + {{ oldData.userName }}{{ oldData.createTime | timestampFormatDate }} - {{ newData.versionName }}{{newData.userName}}{{newData.createTime | timestampFormatDate }} + {{ newData.versionName }} + {{ newData.userName }}{{ newData.createTime | timestampFormatDate }}
-
+
{{ $t('test_track.plan_view.base_info') }}
- @@ -130,10 +132,10 @@
- + - + - +
@@ -267,7 +269,7 @@ {{ $t('api_test.automation.step_total') }}:{{ newScenarioDefinition.length }} - {{ $t('api_test.automation.scenario_total') }} + {{ $t('api_test.automation.scenario_total') }} :{{ getNewVariableSize() }} @@ -284,7 +286,7 @@
- + @@ -296,7 +298,7 @@ @node-expand="nodeExpand(newScenarioDefinition,null,'new')" @node-collapse="nodeCollapse(newScenarioDefinition,null,'new')" @node-click="nodeClick" - draggable ref="newStepTree" > + draggable ref="newStepTree"> import("@/business/components/common/select-tree/SelectTree"), MsInputTag: () => import("@/business/components/api/automation/scenario/MsInputTag"), EnvPopover: () => import("@/business/components/api/automation/scenario/EnvPopover"), }, - watch:{ - 'dialogVisible'(){ - if(this.dialogVisible===false){ + watch: { + 'dialogVisible'() { + if (this.dialogVisible === false) { this.leftChildData = {}; this.leftChildNode = {}; - this.leftChildVnode ={}; + this.leftChildVnode = {}; this.rightChildData = {}; this.rightChildNode = {}; - this.rightChildVnode ={}; + this.rightChildVnode = {}; this.currentRightChild = undefined; this.currentLeftChild = undefined; } } }, - data(){ - return{ - options: API_STATUS, - levels: PRIORITY, - loading: false, - isReloadData:true, - moduleObj: { - id: 'id', - label: 'name', - }, - oldEnvResult:{ - loading: false - }, - newEnvResult:{ - loading: false - }, - showHideTree: true, - environmentType: ENV_TYPE.JSON, - props: { - label: "label", - children: "hashTree" - }, - oldExpandedNode:[], - newExpandedNode:[], - stepEnable:true, - currentLeftChild:undefined, - currentRightChild:undefined, - leftChildData:{}, - rightChildData:{}, - leftChildNode:{}, - rightChildNode:{}, - leftChildVnode:{}, - rightChildVnode:{}, - dialogVisible:false, - oldColor:"", - newColor:"" - } + data() { + return { + options: API_STATUS, + levels: PRIORITY, + loading: false, + isReloadData: true, + moduleObj: { + id: 'id', + label: 'name', + }, + oldEnvResult: { + loading: false + }, + newEnvResult: { + loading: false + }, + showHideTree: true, + environmentType: ENV_TYPE.JSON, + props: { + label: "label", + children: "hashTree" + }, + oldExpandedNode: [], + newExpandedNode: [], + stepEnable: true, + currentLeftChild: undefined, + currentRightChild: undefined, + leftChildData: {}, + rightChildData: {}, + leftChildNode: {}, + rightChildNode: {}, + leftChildVnode: {}, + rightChildVnode: {}, + dialogVisible: false, + oldColor: "", + newColor: "", + newScenarioDefinition: [], + oldScenarioDefinition: [], + oldData: {}, + newData: {}, + newEnableCookieShare: {}, + newOnSampleError: {}, + newProjectEnvMap: new Map, + } }, methods: { + getCurrentScenario() { + return new Promise((resolve) => { + if (this.currentScenarioId) { + this.result = this.$get("/api/automation/getApiScenario/" + this.currentScenarioId, response => { + if (response.data) { + if (response.data.scenarioDefinition != null) { + let obj = JSON.parse(response.data.scenarioDefinition); + if (obj) { + this.oldScenarioDefinition = obj.hashTree; + } + } + this.oldData = response.data; + this.$get('/api/automation/follow/' + this.currentScenarioId, response => { + this.oldData.follows = response.data; + for (let i = 0; i < response.data.length; i++) { + if (response.data[i] === this.currentUser().id) { + this.showFollow = true; + break; + } + } + }); + this.getDffScenario(); + resolve(); + } + }) + } + }); + }, + getDffScenario() { + return new Promise((resolve) => { + this.$get('/api/automation/get/' + this.dffScenarioId + "/" + this.scenarioRefId, response => { + this.$get("/api/automation/getApiScenario/" + response.data.id, res => { + if (res.data) { + if (res.data.scenarioDefinition != null) { + let obj = JSON.parse(res.data.scenarioDefinition); + if (obj) { + if (obj.hashTree) { + for (let i = 0; i < obj.hashTree.length; i++) { + if (!obj.hashTree[i].index) { + obj.hashTree[i].index = i + 1; + } + obj.hashTree[i].disabled = true; + if (!obj.hashTree[i].requestResult) { + obj.hashTree[i].requestResult = [{responseResult: {}}]; + } + } + this.newEnableCookieShare = obj.enableCookieShare; + if (obj.onSampleError === undefined) { + this.newOnSampleError = true; + } else { + this.newOnSampleError = obj.onSampleError; + } + } + this.newScenarioDefinition = obj.hashTree; + for (let i = 0; i < this.oldScenarioDefinition.length; i++) { + this.oldScenarioDefinition[i].disabled = true; + } + if (response.data.environmentJson) { + this.newProjectEnvMap = objToStrMap(JSON.parse(response.data.environmentJson)); + } else { + // 兼容历史数据 + this.newProjectEnvMap.set(this.projectId, obj.environmentId); + } + } + } + res.data.userName = response.data.userName + this.dealWithTag(res.data); + this.newData = res.data; + this.closeExpansion() + resolve(); + } + }); + }) + }) + }, + dealWithTag(newScenario) { + if (newScenario.tags) { + if (Object.prototype.toString.call(newScenario.tags) === "[object String]") { + newScenario.tags = JSON.parse(newScenario.tags); + } + } + }, getDiff() { let oldVnode = this.$refs.old let vnode = this.$refs.new @@ -605,7 +686,6 @@ export default{ this.rightChildNode = node this.rightChildVnode = source this.currentRightChild = source; - console.log(this.rightChildVnode) if (this.currentLeftChild) { this.dialogVisible = true; } @@ -630,7 +710,7 @@ export default{ } return size; }, - getNewVariableSize(){ + getNewVariableSize() { let size = 0; if (this.newData.variables) { size += this.newData.variables.length; @@ -642,18 +722,19 @@ export default{ } }, created() { + this.getCurrentScenario(); }, mounted() { this.$nextTick(function () { - setTimeout(this.getDiff,(this.$refs.old.$children.length+1)*1000) + setTimeout(this.getDiff, (this.$refs.old.$children.length + 1) * 5000); }) } } diff --git a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue index 4536c684f8..32cdfca5f3 100644 --- a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue @@ -118,7 +118,6 @@ import MsApiAdvancedConfig from "./ApiAdvancedConfig"; import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor"; import {hasPermission} from '@/common/js/utils'; import Convert from "@/business/components/common/json-schema/convert/convert"; -import MsJmxStep from "../../step/JmxStep"; import {stepCompute, hisDataProcessing} from "@/business/components/api/definition/api-definition"; export default { @@ -134,7 +133,7 @@ export default { MsApiBody, MsApiKeyValue, MsApiAssertions, - MsJmxStep + MsJmxStep: () => import( "@/business/components/api/definition/components/step/JmxStep"), }, props: { method: String,