mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-03 04:28:51 +08:00
refactor(接口测试): 优化引用场景代码
This commit is contained in:
parent
ed26b6a2e8
commit
f143e68b32
@ -101,62 +101,27 @@ export default {
|
|||||||
changeButtonLoadingType() {
|
changeButtonLoadingType() {
|
||||||
this.buttonIsWorking = false;
|
this.buttonIsWorking = false;
|
||||||
},
|
},
|
||||||
reference() {
|
createScenarioDefinition(scenarios, data, referenced) {
|
||||||
this.buttonIsWorking = true;
|
data.forEach(item => {
|
||||||
let scenarios = [];
|
let scenarioDefinition = JSON.parse(item.scenarioDefinition);
|
||||||
let conditions = this.getConditions();
|
if (scenarioDefinition && scenarioDefinition.hashTree) {
|
||||||
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 = {
|
let obj = {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
type: "scenario",
|
type: "scenario",
|
||||||
referenced: 'REF',
|
headers: scenarioDefinition.headers,
|
||||||
|
variables: scenarioDefinition.variables,
|
||||||
|
environmentMap: scenarioDefinition.environmentMap,
|
||||||
|
referenced: referenced,
|
||||||
resourceId: getUUID(),
|
resourceId: getUUID(),
|
||||||
|
hashTree: scenarioDefinition.hashTree,
|
||||||
projectId: item.projectId
|
projectId: item.projectId
|
||||||
};
|
};
|
||||||
scenarios.push(obj);
|
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 => {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
copy() {
|
getScenarioDefinition(referenced) {
|
||||||
this.buttonIsWorking = true;
|
this.buttonIsWorking = true;
|
||||||
let scenarios = [];
|
let scenarios = [];
|
||||||
let conditions = this.getConditions();
|
let conditions = this.getConditions();
|
||||||
@ -174,24 +139,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
response.data.forEach(item => {
|
this.createScenarioDefinition(scenarios, response.data, referenced)
|
||||||
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.$emit('save', scenarios);
|
this.$emit('save', scenarios);
|
||||||
this.$refs.baseRelevance.close();
|
this.$refs.baseRelevance.close();
|
||||||
this.buttonIsWorking = false;
|
this.buttonIsWorking = false;
|
||||||
@ -210,24 +158,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
response.data.forEach(item => {
|
this.createScenarioDefinition(scenarios, response.data, referenced)
|
||||||
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.$emit('save', scenarios);
|
this.$emit('save', scenarios);
|
||||||
this.$refs.baseRelevance.close();
|
this.$refs.baseRelevance.close();
|
||||||
this.buttonIsWorking = false;
|
this.buttonIsWorking = false;
|
||||||
@ -237,6 +168,12 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
reference() {
|
||||||
|
this.getScenarioDefinition("Copy");
|
||||||
|
},
|
||||||
|
copy() {
|
||||||
|
this.getScenarioDefinition("REF");
|
||||||
|
},
|
||||||
close() {
|
close() {
|
||||||
this.$emit('close');
|
this.$emit('close');
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
Loading…
Reference in New Issue
Block a user