fix: 优化环境编辑

This commit is contained in:
chenjianxing 2020-07-16 16:57:33 +08:00
parent cb3fa9dfa1
commit 04e27d27c8
3 changed files with 34 additions and 22 deletions

View File

@ -50,19 +50,34 @@
this.getEnvironments();
},
deleteEnvironment(environment) {
this.result = this.$get('/api/environment/delete/' + environment.id, response => {
this.$success(this.$t('commons.delete_success'));
this.getEnvironments();
});
if (environment.id) {
this.result = this.$get('/api/environment/delete/' + environment.id, () => {
this.$success(this.$t('commons.delete_success'));
this.getEnvironments();
});
}
},
copyEnvironment(environment) {
let newEnvironment = {};
Object.assign(newEnvironment, environment);
newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
this.$refs.environmentEdit._save(newEnvironment);
this.environments.push(newEnvironment);
this.$refs.environmentItems.itemSelected(this.environments.length -1 , newEnvironment);
},
getNoRepeatName(name) {
for (let i in this.environments) {
if (this.environments[i].name === name) {
return this.getNoRepeatName(name + ' copy');
}
}
return name;
},
addEnvironment() {
this.environments.push(this.getDefaultEnvironment());
let newEnvironment = this.getDefaultEnvironment();
this.environments.push(newEnvironment);
this.$refs.environmentItems.itemSelected(this.environments.length -1 , newEnvironment);
},
environmentSelected(environment) {
this.getEnvironment(environment);
@ -97,6 +112,7 @@
close() {
this.$emit('close');
this.visible = false;
this.$refs.environmentEdit.clearValidate();
}
}
}
@ -116,7 +132,4 @@
height: 100%;
position: absolute;
}
</style>

View File

@ -78,30 +78,30 @@
save() {
this.$refs['from'].validate((valid) => {
if (valid) {
this._save();
this._save(this.environment);
} else {
return false;
}
});
},
_save() {
let param = this.buildParam();
_save(environment) {
let param = this.buildParam(environment);
let url = '/api/environment/add';
if (param.id) {
url = '/api/environment/update';
}
this.result = this.$post(url, param, response => {
if (!param.id) {
this.environment.id = response.data;
environment.id = response.data;
}
this.$success(this.$t('commons.save_success'));
});
},
buildParam() {
buildParam(environment) {
let param = {};
Object.assign(param, this.environment);
param.variables = JSON.stringify(this.environment.variables);
param.headers = JSON.stringify(this.environment.headers);
Object.assign(param, environment);
param.variables = JSON.stringify(environment.variables);
param.headers = JSON.stringify(environment.headers);
return param;
},
validateSocket(socket) {
@ -135,6 +135,9 @@
},
cancel() {
this.$emit('close');
},
clearValidate() {
this.$refs["from"].clearValidate();
}
},
}

View File

@ -10,14 +10,10 @@
</span>
</slot>
</div>
<div :style="{'height': itemBarHeight + 'px'}" v-for="(item, index) in data" :key="index" class="item-bar" @click="itemSelected(index, item)" :class="{'item-selected' : index == selectIndex}">
<!-- <span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-left">-->
<!--&lt;!&ndash; {{item.name}}&ndash;&gt;-->
<!-- </span>-->
<input class="item-input" :style="{'height': itemBarHeight - 12 + 'px', 'line-height': itemBarHeight - 12 + 'px', 'width': width - 90 + 'px'}" v-model="item.name" placeholder="请输入内容"/>
<input class="item-input" :style="{'height': itemBarHeight - 12 + 'px', 'line-height': itemBarHeight - 12 + 'px', 'width': width - 90 + 'px'}" v-model="item.name" :placeholder="$t('commons.input_content')"/>
<span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-right">
<i v-for="(operator, index) in itemOperators" :key="index" :class="operator.icon" @click="operator.func(item)"/>
<i v-for="(operator, index) in itemOperators" :key="index" :class="operator.icon" @click.stop="operator.func(item)"/>
</span>
</div>
</ms-aside-container>