|
|
@@ -34,7 +34,8 @@
|
|
|
addConfiguration:{},
|
|
|
editConfiguration:{},
|
|
|
index:'',
|
|
|
- selectTr:''
|
|
|
+ selectTr:'',
|
|
|
+ configurationErrors:{},
|
|
|
},
|
|
|
mounted(){
|
|
|
$('#configuration').removeClass('d-none');
|
|
|
@@ -60,32 +61,74 @@
|
|
|
edit(configuration,i){
|
|
|
this.editConfiguration = JSON.parse(JSON.stringify(configuration));
|
|
|
this.index = i;
|
|
|
+ this.configurationErrors ={};
|
|
|
$('#edit-configuration').modal('show');
|
|
|
},
|
|
|
update(){
|
|
|
let url = '{{url('apiLocal/configuration/update')}}';
|
|
|
let params = this.editConfiguration;
|
|
|
- window.tempTip.postBasicRequest(url,params,res=>{
|
|
|
- this.$set(this.configurations,this.index,res);
|
|
|
- this.index = null;
|
|
|
- this.editConfiguration = {};
|
|
|
- $("#edit-configuration").modal('hide');
|
|
|
- return "修改完成";
|
|
|
- },true);
|
|
|
+ if(!this.validateConfiguration(params))return;
|
|
|
+ window.axios.post(url,params).then(res=>{
|
|
|
+ if(res.data.success){
|
|
|
+ this.$set(this.configurations,this.index,res.data.data);
|
|
|
+ this.index = null;
|
|
|
+ this.editConfiguration = {};
|
|
|
+ $("#edit-configuration").modal('hide');
|
|
|
+ window.tempTip.showSuccess('修改成功');
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(res.data.errors){
|
|
|
+ this.configurationErrors = res.data.errors;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ window.tempTip.show(res.data.message ?? '修改失败');
|
|
|
+ }).catch(err=>{
|
|
|
+ window.tempTip.show('修改失败'+err);
|
|
|
+ });
|
|
|
},
|
|
|
store(){
|
|
|
+ this.addConfiguration = {};
|
|
|
+ this.configurationErrors ={};
|
|
|
$('#add-configuration').modal('show');
|
|
|
},
|
|
|
- create(){
|
|
|
+ create(params){
|
|
|
let url = '{{url('apiLocal/configuration/store')}}';
|
|
|
- let params = this.addConfiguration;
|
|
|
- window.tempTip.postBasicRequest(url,params,res=>{
|
|
|
- this.configurations.unshift(res);
|
|
|
- this.$forceUpdate();
|
|
|
- this.addConfiguration = {};
|
|
|
- $("#add-configuration").modal('hide');
|
|
|
- return "添加成功";
|
|
|
- },true);
|
|
|
+ if(!this.validateConfiguration(params))return;
|
|
|
+ window.tempTip.setIndex(1099);
|
|
|
+ window.tempTip.setDuration(3000);
|
|
|
+ window.axios.post(url,params).then(res=>{
|
|
|
+ if(res.data.success){
|
|
|
+ this.configurations.unshift(res.data.data);
|
|
|
+ this.$forceUpdate();
|
|
|
+ $("#add-configuration").modal('hide');
|
|
|
+ window.tempTip.showSuccess('添加成功');
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(res.data.errors){
|
|
|
+ this.configurationErrors = res.data.errors;
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ window.tempTip.show(res.data.message ?? '修改失败');
|
|
|
+ }).catch(err=>{
|
|
|
+ window.tempTip.show('修改失败'+err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ validateConfiguration(configuration){
|
|
|
+ let bool = true;
|
|
|
+ if(!configuration.hasOwnProperty('name') || configuration.name.trim() === ''){
|
|
|
+ this.$set(this.configurationErrors,'name',['名称为必填项'])
|
|
|
+ bool = false;
|
|
|
+ }
|
|
|
+ if(!configuration.hasOwnProperty('value') || configuration.value.trim() === ''){
|
|
|
+ this.$set(this.configurationErrors,'value',['值为必填项'])
|
|
|
+ bool = false;
|
|
|
+ }
|
|
|
+ if(!configuration.hasOwnProperty('description') || configuration.description.trim() === ''){
|
|
|
+ this.$set(this.configurationErrors,'description',['描述为必填项'])
|
|
|
+ bool = false;
|
|
|
+ }
|
|
|
+ if(!bool)this.$forceUpdate();
|
|
|
+ return bool;
|
|
|
}
|
|
|
}
|
|
|
});
|