refactor: 打开环境配置时默认选中当前配置

This commit is contained in:
shiziyuan9527 2021-03-25 18:33:03 +08:00
parent dfc24d96a4
commit a8b54c9d74
4 changed files with 33 additions and 11 deletions

View File

@ -5,12 +5,12 @@
<el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
@ -78,12 +78,12 @@ export default {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId) {
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId);
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();

View File

@ -77,7 +77,7 @@
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.projectId);
this.$refs.environmentConfig.open(this.projectId, this.environmentId);
},
environmentChange(value) {
for (let i in this.environments) {

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete',
func: this.deleteEnvironment
}
]
],
selectEnvironmentId: ''
}
},
methods: {
open: function (projectId) {
open: function (projectId, envId) {
this.visible = true;
this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments();
listenGoBack(this.close);
},
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
if (this.environments.length > 0) {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
let item = new Environment({
projectId: this.projectId

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete',
func: this.deleteEnvironment
}
]
],
selectEnvironmentId: ''
}
},
methods: {
open: function (projectId) {
open: function (projectId, envId) {
this.visible = true;
this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments();
listenGoBack(this.close);
},
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
if (this.environments.length > 0) {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
let item = new Environment({
projectId: this.projectId