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

表单校验单项逻辑调整

上级 8026c716
......@@ -342,47 +342,6 @@ import { Util } from '@/ibiz-core/utils';
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';
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>];
if(await this.checkItem('${formitem.name}')){
if(await this.validItem('${formitem.name}')){
this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
}
}
......@@ -492,19 +451,17 @@ import { Util } from '@/ibiz-core/utils';
* @param name 属性名
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public checkItem(name:string):Promise<any> {
// return new Promise((resolve, reject) => {
// var validator = new schema({[name]:this.rules()[name]});
// validator.validate({[name]:this.data[name]}).then(()=>{
// resolve(true);
// })
// .catch(() => {
// resolve(false);
// });;
// })
return new Promise(()=>{});
public validItem(name:string):Promise<any> {
return new Promise((resolve, reject) => {
Util.validateItem(name,this.data[name],this.rules[name]).then(()=>{
resolve(true);
}).catch(({ errors, fields }) => {
resolve(false);
});
});
}
/**
* 表单值变化
*
......@@ -635,14 +592,15 @@ import { Util } from '@/ibiz-core/utils';
* @returns {boolean}
* @memberof ${srfclassname('${ctrl.codeName}')}
*/
protected formValidateStatus(): boolean {
const refArr: Array<string> = [<#list ctrl.getPSDEFormItems() as formItem><#if formItem.getEditorType?? && formItem.getEditorType() != 'HIDDEN'>'${formItem.getName()}_item', </#if></#list>];
protected async formValidateStatus(): Promise<boolean> {
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;
refArr.forEach((item: any) => {
if (this.$refs[item] && (this.$refs[item] as any).validateRules && !(this.$refs[item] as any).validateRules()) {
for (let item = 0; item < refArr.length; item++) {
const element = refArr[item];
if (this.$refs[element] && (this.$refs[element] as any).validateRules && !await(this.$refs[element] as any).validateRules()) {
falg = false;
}
});
}
return falg;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册