fix(环境管理): 通用配置参数名称校验

--bug=1007489 --user=赵勇 【环境配置】-添加的全局变量名称可以重复 https://www.tapd.cn/55049933/s/1059272
This commit is contained in:
fit2-zhao 2021-10-26 17:37:42 +08:00 committed by fit2-zhao
parent 729d5a2aa0
commit 99e6d2c6eb
2 changed files with 30 additions and 1 deletions

View File

@ -76,7 +76,13 @@ export default {
change: function () {
let isNeedCreate = true;
let removeIndex = -1;
let repeatKey = "";
this.items.forEach((item, index) => {
this.items.forEach((row, rowIndex) => {
if (item.name === row.name && index !== rowIndex) {
repeatKey = item.name;
}
});
if (!item.name && !item.value) {
//
if (index !== this.items.length - 1) {
@ -86,11 +92,15 @@ export default {
isNeedCreate = false;
}
});
if (isNeedCreate) {
if (repeatKey !== "") {
this.$warning(this.$t('api_test.environment.common_config') + "【" + repeatKey + "】" + this.$t('load_test.param_is_duplicate'));
}
if (isNeedCreate && !repeatKey) {
this.items.push(new KeyValue({enable: true}));
}
this.$emit('change', this.items);
// TODO key
},
isDisable: function (index) {
return this.items.length - 1 === index;

View File

@ -84,6 +84,7 @@
import {getUUID} from "@/common/js/utils";
import Jsr233ProcessorContent from "@/business/components/api/automation/scenario/common/Jsr233ProcessorContent";
import {createComponent} from "@/business/components/api/definition/components/jmeter/components";
import {KeyValue} from "@/business/components/api/test/model/ScenarioModel";
export default {
name: "EnvironmentEdit",
@ -212,11 +213,29 @@
}
return uploadFiles;
},
check (items) {
let repeatKey = "";
items.forEach((item, index) => {
items.forEach((row, rowIndex) => {
if (item.name === row.name && index !== rowIndex) {
repeatKey = item.name;
}
});
});
return repeatKey;
},
_save(environment) {
if(!this.projectId){
this.$warning(this.$t('api_test.select_project'));
return;
}
if(environment && environment.config && environment.config.commonConfig &&environment.config.commonConfig.variables){
let repeatKey = this.check(environment.config.commonConfig &&environment.config.commonConfig.variables);
if (repeatKey !== "") {
this.$warning(this.$t('api_test.environment.common_config') + "【" + repeatKey + "】" + this.$t('load_test.param_is_duplicate'));
return ;
}
}
let bodyFiles = this.geFiles(environment);
let param = this.buildParam(environment);
let url = '/api/environment/add';