fix(接口测试): 修复切换数据源错误的缺陷

--bug=1031220 --user=王孝刚 【接口测试】github#26909,接口自动化内切换环境 ,SQL步骤的数据源切换错误
https://www.tapd.cn/55049933/s/1423509
This commit is contained in:
wxg0103 2023-10-09 16:37:54 +08:00 committed by fit2-zhao
parent 9bae4b494f
commit c54d119b1a
1 changed files with 14 additions and 2 deletions

View File

@ -39,7 +39,7 @@
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<el-form-item :label="$t('api_test.request.sql.dataSource')" prop="dataSourceId" style="margin-left: 10px"> <el-form-item :label="$t('api_test.request.sql.dataSource')" prop="dataSourceId" style="margin-left: 10px">
<el-select v-model="request.dataSourceId" size="small" @change="reload" :disabled="request.disabled"> <el-select v-model="request.dataSourceId" size="small" @change="reloadDataSource" :disabled="request.disabled">
<el-option <el-option
v-for="(item, index) in databaseConfigsOptions" v-for="(item, index) in databaseConfigsOptions"
:key="index" :key="index"
@ -182,6 +182,14 @@ export default {
}, },
}, },
methods: { methods: {
reloadDataSource(dataSourceId) {
this.databaseConfigsOptions.forEach((item) => {
if (item.id === dataSourceId) {
this.request.targetDataSourceName = item.name;
}
});
this.reload();
},
remove(row) { remove(row) {
let index = this.request.hashTree.indexOf(row); let index = this.request.hashTree.indexOf(row);
this.request.hashTree.splice(index, 1); this.request.hashTree.splice(index, 1);
@ -294,12 +302,13 @@ export default {
this.environments.forEach((environment) => { this.environments.forEach((environment) => {
parseEnvironment(environment); parseEnvironment(environment);
// //
if (environment.id === this.request.environmentId && environment.id !== envId) { if (environment.id === this.request.environmentId) {
hasEnvironment = true; hasEnvironment = true;
if (environment.config && environment.config.databaseConfigs) { if (environment.config && environment.config.databaseConfigs) {
environment.config.databaseConfigs.forEach((item) => { environment.config.databaseConfigs.forEach((item) => {
if (item.id === this.request.dataSourceId) { if (item.id === this.request.dataSourceId) {
targetDataSourceName = item.name; targetDataSourceName = item.name;
this.request.targetDataSourceName = item.name;
} }
}); });
} }
@ -334,6 +343,9 @@ export default {
} }
}, },
initDataSource(envId, currentEnvironment, targetDataSourceName) { initDataSource(envId, currentEnvironment, targetDataSourceName) {
if (!targetDataSourceName) {
targetDataSourceName = this.request.targetDataSourceName;
}
this.databaseConfigsOptions = []; this.databaseConfigsOptions = [];
if (envId) { if (envId) {
this.request.environmentId = envId; this.request.environmentId = envId;