提交 ab193fe9 编写于 作者: KK's avatar KK

表单校验单项逻辑调整

上级 8026c716
...@@ -342,47 +342,6 @@ import { Util } from '@/ibiz-core/utils'; ...@@ -342,47 +342,6 @@ import { Util } from '@/ibiz-core/utils';
return falg; return falg;
} }
/**
* 项校验
*
* @param {string} property 属性名
* @param {*} data 行数据
* @param {number} rowIndex 行索引
* @returns Promise<any>
*
* @memberof MainBase
*/
public validate(property:string, data:any):Promise<any>{
return new Promise((resolve, reject) => {
Util.validateItem(property,data,this.rules).then(()=>{
// this.gridItemsModel[rowIndex][property].setError(null);
console.log(property,true)
resolve(true);
}).catch(({ errors, fields }) => {
// this.gridItemsModel[rowIndex][property].setError(errors[0].message);
console.log(property,errors)
resolve(false);
});
});
}
/**
* 校验所有项
*
* @returns Promise<any>
* @memberof MainBase
*/
public async validateAll(){
let validateState = true;
for(let property of Object.keys(this.rules)){
if(!await this.validate(property,this.data)){
validateState = false;
}
}
return validateState;
}
/** /**
* 详情模型集合 * 详情模型集合
* *
...@@ -476,7 +435,7 @@ import { Util } from '@/ibiz-core/utils'; ...@@ -476,7 +435,7 @@ import { Util } from '@/ibiz-core/utils';
if (Object.is(name, '${formitem.name}')) { if (Object.is(name, '${formitem.name}')) {
const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>]; const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
if(await this.checkItem('${formitem.name}')){ if(await this.validItem('${formitem.name}')){
this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c}); this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
} }
} }
...@@ -492,19 +451,17 @@ import { Util } from '@/ibiz-core/utils'; ...@@ -492,19 +451,17 @@ import { Util } from '@/ibiz-core/utils';
* @param name 属性名 * @param name 属性名
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public checkItem(name:string):Promise<any> { public validItem(name:string):Promise<any> {
// return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// var validator = new schema({[name]:this.rules()[name]}); Util.validateItem(name,this.data[name],this.rules[name]).then(()=>{
// validator.validate({[name]:this.data[name]}).then(()=>{ resolve(true);
// resolve(true); }).catch(({ errors, fields }) => {
// }) resolve(false);
// .catch(() => { });
// resolve(false); });
// });;
// })
return new Promise(()=>{});
} }
/** /**
* 表单值变化 * 表单值变化
* *
...@@ -635,14 +592,15 @@ import { Util } from '@/ibiz-core/utils'; ...@@ -635,14 +592,15 @@ import { Util } from '@/ibiz-core/utils';
* @returns {boolean} * @returns {boolean}
* @memberof ${srfclassname('${ctrl.codeName}')} * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
protected formValidateStatus(): boolean { protected async formValidateStatus(): Promise<boolean> {
const refArr: Array<string> = [<#list ctrl.getPSDEFormItems() as formItem><#if formItem.getEditorType?? && formItem.getEditorType() != 'HIDDEN'>'${formItem.getName()}_item', </#if></#list>]; const refArr: Array<string> = ['mobileentity3name_item', 'field_item', 'field10_item', 'field14_item', 'field12_item', 'mobileentity3id_item', 'field15_item', 'field5_item', 'field13_item', 'field2_item', 'field4_item', 'field3_item', 'field11_item', 'field6_item', 'field16_item', 'field17_item', 'formitem1_item', 'formitem_item', 'formitem2_item', 'field9_item', 'field8_item', 'field7_item', 'mobtext2_item', 'mobnumber_item', 'mobtextarea_item', 'mobswitch_item', 'mobradiolist_item', 'mobdropdownlist_item', 'mobchecklist_item', 'mobpicker_item', 'mobpicker_dropdownview_item', 'mobpassword_item', 'mobslider_item', 'mobstepper2_item', 'mobdate_item', 'mobmultifileupload_item', 'mobpicturelist_item', 'mobrating_item', 'mobsinglefileupload_item', 'mobpicture_item', 'mobmpicker2_item', ];
let falg = true; let falg = true;
refArr.forEach((item: any) => { for (let item = 0; item < refArr.length; item++) {
if (this.$refs[item] && (this.$refs[item] as any).validateRules && !(this.$refs[item] as any).validateRules()) { const element = refArr[item];
if (this.$refs[element] && (this.$refs[element] as any).validateRules && !await(this.$refs[element] as any).validateRules()) {
falg = false; falg = false;
} }
}); }
return falg; return falg;
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册