From f143e68b3246fed3cf60849ed69ba63ed1173b36 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 14 Jan 2022 15:57:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=BC=95=E7=94=A8=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/api/ScenarioRelevance.vue | 103 ++++-------------- 1 file changed, 20 insertions(+), 83 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevance.vue b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevance.vue index dd2414c0c5..50f70f8d61 100644 --- a/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevance.vue +++ b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevance.vue @@ -101,62 +101,27 @@ export default { changeButtonLoadingType() { this.buttonIsWorking = false; }, - reference() { - this.buttonIsWorking = true; - let scenarios = []; - let conditions = this.getConditions(); - if (conditions.selectAll) { - let params = {}; - params.ids = this.currentScenarioIds; - params.condition = conditions; - let url = "/api/automation/list/all/"; - this.result = this.$post(url, params, (response) => { - this.currentScenario = response.data; - if (!this.currentScenario || this.currentScenario.length < 1) { - this.$emit('请选择场景'); - this.buttonIsWorking = false; - return; - } - this.currentScenario.forEach(item => { - let obj = { - id: item.id, - name: item.name, - type: "scenario", - referenced: 'REF', - resourceId: getUUID(), - projectId: item.projectId - }; - scenarios.push(obj); - }); - this.$emit('save', scenarios); - this.$refs.baseRelevance.close(); - this.buttonIsWorking = false; - }, (error) => { - this.buttonIsWorking = false; - }); - } else { - if (!this.currentScenario || this.currentScenario.length < 1) { - this.$emit('请选择场景'); - this.buttonIsWorking = false; - return; - } - this.currentScenario.forEach(item => { + createScenarioDefinition(scenarios, data, referenced) { + data.forEach(item => { + let scenarioDefinition = JSON.parse(item.scenarioDefinition); + if (scenarioDefinition && scenarioDefinition.hashTree) { let obj = { id: item.id, name: item.name, type: "scenario", - referenced: 'REF', + headers: scenarioDefinition.headers, + variables: scenarioDefinition.variables, + environmentMap: scenarioDefinition.environmentMap, + referenced: referenced, resourceId: getUUID(), + hashTree: scenarioDefinition.hashTree, projectId: item.projectId }; scenarios.push(obj); - }); - this.$emit('save', scenarios); - this.$refs.baseRelevance.close(); - this.buttonIsWorking = false; - } + } + }); }, - copy() { + getScenarioDefinition(referenced) { this.buttonIsWorking = true; let scenarios = []; let conditions = this.getConditions(); @@ -174,24 +139,7 @@ export default { } this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => { if (response.data) { - response.data.forEach(item => { - let scenarioDefinition = JSON.parse(item.scenarioDefinition); - if (scenarioDefinition && scenarioDefinition.hashTree) { - let obj = { - id: item.id, - name: item.name, - type: "scenario", - headers: scenarioDefinition.headers, - variables: scenarioDefinition.variables, - environmentMap: scenarioDefinition.environmentMap, - referenced: 'Copy', - resourceId: getUUID(), - hashTree: scenarioDefinition.hashTree, - projectId: item.projectId - }; - scenarios.push(obj); - } - }); + this.createScenarioDefinition(scenarios, response.data, referenced) this.$emit('save', scenarios); this.$refs.baseRelevance.close(); this.buttonIsWorking = false; @@ -210,24 +158,7 @@ export default { } this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => { if (response.data) { - response.data.forEach(item => { - let scenarioDefinition = JSON.parse(item.scenarioDefinition); - if (scenarioDefinition && scenarioDefinition.hashTree) { - let obj = { - id: item.id, - name: item.name, - type: "scenario", - headers: scenarioDefinition.headers, - variables: scenarioDefinition.variables, - environmentMap: scenarioDefinition.environmentMap, - referenced: 'Copy', - resourceId: getUUID(), - hashTree: scenarioDefinition.hashTree, - projectId: item.projectId - }; - scenarios.push(obj); - } - }); + this.createScenarioDefinition(scenarios, response.data, referenced) this.$emit('save', scenarios); this.$refs.baseRelevance.close(); this.buttonIsWorking = false; @@ -237,6 +168,12 @@ export default { }); } }, + reference() { + this.getScenarioDefinition("Copy"); + }, + copy() { + this.getScenarioDefinition("REF"); + }, close() { this.$emit('close'); this.refresh();