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

值规则校验

上级 7eceb1e7
......@@ -1268,6 +1268,42 @@ import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
this.$emit('load', this.data);
}
/**
* 值规则校验
*
* @memberof ${srfclassname('${ctrl.codeName}')}
*/
public checkRule(name:string){
const isType = (type : any) =>((/^\[object\s(.*)\]$/ as any).exec(Object.prototype.toString.call(type)))[1];
const isSymbol = isType(this.data[name]);
let erro_text = "";
let checkValue = this.data[name];
this.rules[name].forEach((item:any)=>{
if(item.hasOwnProperty('type') && item.trigger == 'change'){
let type: any = item.type;
if(type != isSymbol.toLowerCase()){
erro_text = item.message;
return;
}
}
if(item.hasOwnProperty('pattern') && item.trigger == 'change'){
let pattern: any = item.pattern;
if(!pattern.test(checkValue)){
erro_text = item.message;
return;
}
}
if(item.hasOwnProperty('required') && item.trigger == 'change'){
if(item.required && !checkValue){
erro_text = item.message
return;
}
}
});
this.detailsModel[name].error = erro_text;
}
</#if>
</#if>
......
<app-mob-input class="app-form-item-input" @change="($event)=>this.data.${editor.name} = $event" :type="'text'" :value="data.${editor.name}" :disabled="detailsModel.${editor.name}.disabled" <#if editor.getPlaceHolder()??> placeholder="${editor.getPlaceHolder()}"</#if>></app-mob-input>
\ No newline at end of file
<app-mob-input class="app-form-item-input" @change="($event)=>{this.data.${editor.name} = $event;this.checkRule('${editor.name}')}" :type="'text'" :value="data.${editor.name}" :disabled="detailsModel.${editor.name}.disabled" <#if editor.getPlaceHolder()??> placeholder="${editor.getPlaceHolder()}"</#if>></app-mob-input>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册