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

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

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