fix(接口自动化): 缺陷修复

This commit is contained in:
fit2-zhao 2021-05-21 11:08:35 +08:00 committed by fit2-zhao
parent 9484471f96
commit 7d70c8efd8
2 changed files with 27 additions and 43 deletions

View File

@ -45,7 +45,7 @@
:request="request"
:showScript="false"/>
<ms-sql-basis-parameters v-if="request.protocol==='SQL'|| request.type==='JDBCSampler'"
:request="request" :is-scenario="false" :environment="environment"
:request="request"
:showScript="false"/>
<ms-dubbo-basis-parameters v-if="request.protocol==='DUBBO' || request.protocol==='dubbo://'|| request.type==='DubboSampler'"
:request="request"
@ -230,12 +230,28 @@
},
},
methods: {
initDataSource() {
let databaseConfigsOptions = [];
if (this.request.protocol === 'SQL' || this.request.type === 'JDBCSampler') {
if (this.environment.config) {
let config = JSON.parse(this.environment.config);
config.databaseConfigs.forEach(item => {
databaseConfigsOptions.push(item);
});
}
}
if (databaseConfigsOptions.length > 0) {
this.request.dataSourceId = databaseConfigsOptions[0].id;
this.request.environmentId = this.environment.id;
}
},
getEnvironments() {
this.environment = {};
let id = this.envMap.get(this.request.projectId);
if (id) {
this.$get('/api/environment/get/' + id, response => {
this.environment = response.data;
this.initDataSource();
});
}
},

View File

@ -6,7 +6,7 @@
<el-form :model="request" :rules="rules" ref="request" label-width="100px" :disabled="isReadOnly" style="margin: 10px">
<el-row>
<el-col :span="8">
<el-form-item prop="environmentId" div v-if="!isScenario" :label="$t('api_test.definition.request.run_env')">
<el-form-item prop="environmentId" :label="$t('api_test.definition.request.run_env')">
<el-select v-model="request.environmentId" size="small" class="ms-htt-width"
:placeholder="$t('api_test.definition.request.run_env')"
@change="environmentChange" clearable>
@ -108,11 +108,6 @@
request: {},
basisData: {},
moduleOptions: Array,
environment: {},//
isScenario: {
type: Boolean,
default: false,
},
showScript: {
type: Boolean,
default: true,
@ -129,28 +124,16 @@
databaseConfigsOptions: [],
isReloadData: false,
activeName: "variables",
rules: {
},
rules: {},
}
},
watch: {
'request.dataSourceId'() {
this.setDataSource();
},
environment: {
handler: function () {
this.initDataSource();
},
deep: true
}
},
created() {
if(this.isScenario){
this.initDataSource();
}else{
this.getEnvironments();
}
this.getEnvironments();
},
computed: {
projectId() {
@ -238,31 +221,16 @@
},
initDataSource() {
let flag = false;
if (this.isScenario && this.environment) {
this.request.environmentId = this.environment.id;
this.databaseConfigsOptions = [];
if (this.environment.config) {
let config = JSON.parse(this.environment.config);
config.databaseConfigs.forEach(item => {
if (item.id !== this.request.dataSourceId) {
this.request.dataSourceId = item.id;
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
if (item.id === this.request.dataSourceId) {
flag = true;
}
flag = true;
this.databaseConfigsOptions.push(item);
});
}
} else {
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
if (item.id === this.request.dataSourceId) {
flag = true;
}
this.databaseConfigsOptions.push(item);
});
break;
}
break;
}
}
if (!flag) {