提交 c542965b 编写于 作者: WodahsOrez's avatar WodahsOrez

lxm--表格外部校验--fix2

上级 388aaa7c
...@@ -520,17 +520,44 @@ import { FormItemModel } from '@/model/form-detail'; ...@@ -520,17 +520,44 @@ import { FormItemModel } from '@/model/form-detail';
* @param {string} property 属性名 * @param {string} property 属性名
* @param {*} data 行数据 * @param {*} data 行数据
* @param {number} rowIndex 行索引 * @param {number} rowIndex 行索引
* * @returns Promise<any>
*
* @memberof ${srfclassname('${ctrl.codeName}')} * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
public validate(property:string, data:any, rowIndex:number){ public validate(property:string, data:any, rowIndex:number):Promise<any>{
this.$util.validateItem(property,data,this.rules).then(()=>{ return new Promise((resolve, reject) => {
this.gridItemsModel[rowIndex][property].setError(null); this.$util.validateItem(property,data,this.rules).then(()=>{
}).catch(({ errors, fields }) => { this.gridItemsModel[rowIndex][property].setError(null);
this.gridItemsModel[rowIndex][property].setError(errors[0].message); resolve(true);
}).catch(({ errors, fields }) => {
this.gridItemsModel[rowIndex][property].setError(errors[0].message);
resolve(false);
});
}); });
} }
/**
* 校验所有修改过的编辑项
*
* @returns Promise<any>
* @memberof ${srfclassname('${ctrl.codeName}')}
*/
public async validateAll(){
let validateState = true;
let index = -1;
for(let item of this.items){
index++;
if(item.rowDataState === "create" || item.rowDataState === "update"){
for(let property of Object.keys(this.rules)){
if(!await this.validate(property,item,index)){
validateState = false;
}
}
}
}
return validateState;
}
/** /**
* 表格数据加载 * 表格数据加载
* *
...@@ -1503,43 +1530,58 @@ import { FormItemModel } from '@/model/form-detail'; ...@@ -1503,43 +1530,58 @@ import { FormItemModel } from '@/model/form-detail';
* 保存 * 保存
* *
* @param {*} $event * @param {*} $event
* @returns {void} * @returns {Promise<any>}
* @memberof ${srfclassname('${ctrl.codeName}')} * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
public save(args: any[], params?: any, $event?: any, xData?: any): void { public async save(args: any[], params?: any, $event?: any, xData?: any){
let _this = this; let _this = this;
let promises:any = []; if(!await this.validateAll()){
_this.items.forEach((item:any)=>{ this.$Notice.error({ title: '错误', desc: '值规则校验异常' });
if(!item.rowDataState){ return [];
return; }
} else if(Object.is(item.rowDataState, 'create')){ let successItems:any = [];
if(!this.createAction){ let errorItems:any = [];
this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格createAction参数未配置' }); let errorMessage:any = [];
return; for (const item of _this.items) {
} try {
Object.assign(item,{viewparams:this.viewparams}); if(Object.is(item.rowDataState, 'create')){
promises.push(this.service.add(this.createAction, JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator)); if(!this.createAction){
}else if(Object.is(item.rowDataState, 'update')){ this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格createAction参数未配置' });
if(!this.updateAction){ }else{
this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格updateAction参数未配置' }); Object.assign(item,{viewparams:this.viewparams});
return; let response = await this.service.add(this.createAction, JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator);
} successItems.push(JSON.parse(JSON.stringify(response.data)));
Object.assign(item,{viewparams:this.viewparams}); }
}else if(Object.is(item.rowDataState, 'update')){
if(!this.updateAction){
this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格updateAction参数未配置' });
}else{
Object.assign(item,{viewparams:this.viewparams});
<#if de??> <#if de??>
if(item.${appde.getCodeName()?lower_case}){ if(item.${appde.getCodeName()?lower_case}){
Object.assign(this.context,{${appde.getCodeName()?lower_case}:item.${appde.getCodeName()?lower_case}}) Object.assign(this.context,{${appde.getCodeName()?lower_case}:item.${appde.getCodeName()?lower_case}});
} }
</#if> </#if>
promises.push(this.service.add(this.updateAction,JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator)); let response = await this.service.add(this.updateAction,JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator);
successItems.push(JSON.parse(JSON.stringify(response.data)));
}
}
} catch (error) {
errorItems.push(JSON.parse(JSON.stringify(item)));
errorMessage.push(error);
} }
}); }
Promise.all(promises).then((response: any) => { this.$emit('save', successItems);
this.$emit('save', response); this.refresh([]);
if(errorItems.length === 0){
this.$Notice.success({ title: '', desc: '保存成功!' }); this.$Notice.success({ title: '', desc: '保存成功!' });
this.refresh([]); }else{
}).catch((response: any) => { errorItems.forEach((item:any,index:number)=>{
this.$Notice.error({ title: '错误', desc: '系统异常' }); this.$Notice.error({ title: '保存失败', desc: item.majorentityname+'保存失败!' });
}); console.error(errorMessage[index]);
});
}
return successItems;
} }
<#if ctrl.isEnableRowEdit()> <#if ctrl.isEnableRowEdit()>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册