fix: 保存环境

This commit is contained in:
chenjianxing 2020-07-21 00:47:58 +08:00
parent 6ed20d81d6
commit c052d1ea95
6 changed files with 38 additions and 11 deletions

View File

@ -58,14 +58,32 @@
}
},
copyEnvironment(environment) {
if (!environment.id) {
this.$warning(this.$t('commons.please_save'))
return;
}
let newEnvironment = {};
Object.assign(newEnvironment, environment);
newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
if (!this.validateEnvironment(newEnvironment)) {
return;
}
this.$refs.environmentEdit._save(newEnvironment);
this.environments.push(newEnvironment);
this.$refs.environmentItems.itemSelected(this.environments.length -1 , newEnvironment);
},
validateEnvironment(environment) {
if (!environment.name || !!environment.name && environment.name.length > 64) {
this.$error(this.$t('commons.input_limit', [1, 64]));
return false;
}
if (!this.$refs.environmentEdit.validateSocket(environment.socket)) {
this.$error(this.$t('commons.formatErr'));
return false;
}
return true;
},
getNoRepeatName(name) {
for (let i in this.environments) {
if (this.environments[i].name === name) {
@ -97,14 +115,13 @@
}
},
getEnvironment(environment) {
let item = environment;
if (!(environment.variables instanceof Array)) {
item.variables = JSON.parse(environment.variables);
environment.variables = JSON.parse(environment.variables);
}
if (!(environment.headers instanceof Array)) {
item.headers = JSON.parse(environment.headers);
environment.headers = JSON.parse(environment.headers);
}
this.currentEnvironment = item;
this.currentEnvironment = environment;
},
getDefaultEnvironment() {
return {variables: [{}], headers: [{}], protocol: 'https', projectId: this.projectId};

View File

@ -100,8 +100,12 @@
buildParam(environment) {
let param = {};
Object.assign(param, environment);
param.variables = JSON.stringify(environment.variables);
param.headers = JSON.stringify(environment.headers);
if (!(environment.variables instanceof String)) {
param.variables = JSON.stringify(environment.variables);
}
if (!(environment.headers instanceof String)) {
param.headers = JSON.stringify(environment.headers);
}
return param;
},
validateSocket(socket) {

View File

@ -274,7 +274,7 @@
},
checkScheduleEdit() {
if (!this.testPlan.id) {
this.$message('请先保存测试');
this.$message(this.$t('api_test.environment.please_save_test'));
return false;
}
return true;
@ -284,7 +284,7 @@
if (intervalTime < duration) {
return {
pass: false,
info: '间隔时间不能小于压测时长'
info: this.$t('load_test.schedule_tip')
}
}
return {

View File

@ -102,6 +102,7 @@ export default {
login_username: 'ID or email',
input_login_username: 'Please input the user ID or email',
input_name: 'Please enter name',
please_save: 'Please save first',
formatErr: 'Format Error',
id: 'ID',
please_upload: 'Please upload file',
@ -319,7 +320,8 @@ export default {
download_log_file: 'Download',
user_name: 'Creator',
special_characters_are_not_supported: 'Test name does not support special characters',
pressure_config_params_is_empty: 'Pressure configuration parameters cannot be empty!'
pressure_config_params_is_empty: 'Pressure configuration parameters cannot be empty!',
schedule_tip: 'The interval must not be less than the pressure measuring time'
},
api_test: {
creator: "Creator",

View File

@ -104,6 +104,7 @@ export default {
input_name: '请输入名称',
please_upload: '请上传文件',
formatErr: '格式错误',
please_save: '请先保存',
id: 'ID',
date: {
select_date: '选择日期',
@ -318,7 +319,8 @@ export default {
pressure_prediction_chart: '压力预估图',
user_name: '创建人',
special_characters_are_not_supported: '测试名称不支持特殊字符',
pressure_config_params_is_empty: '压力配置参数不能为空!'
pressure_config_params_is_empty: '压力配置参数不能为空!',
schedule_tip: '间隔时间不能小于压测时长'
},
api_test: {
creator: "创建人",

View File

@ -101,6 +101,7 @@ export default {
delete_confirm: '請輸入以下內容,確認刪除:',
input_name: '請輸入名稱',
formatErr: '格式錯誤',
please_save: '請先保存',
id: 'ID',
please_upload: '請上傳文件',
date: {
@ -317,7 +318,8 @@ export default {
pressure_prediction_chart: '壓力預估圖',
user_name: '創建人',
special_characters_are_not_supported: '測試名稱不支持特殊字符',
pressure_config_params_is_empty: '壓力配置參數不能為空!'
pressure_config_params_is_empty: '壓力配置參數不能為空!',
schedule_tip: '間隔時間不能小於壓測時長'
},
api_test: {
creator: "創建人",