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

值规则调整

上级 56603133
......@@ -36,7 +36,7 @@
<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import { Util } from '@/ibiz-core/utils';
@Component({})
export default class AppFormItem extends Vue {
......@@ -258,27 +258,26 @@ export default class AppFormItem extends Vue {
* @returns {boolean}
* @memberof AppFormItem
*/
public validateRules(): boolean {
let erro_text: any = "";
let isCheck: boolean = true;
let required: boolean = true;
this.rules.forEach((item: any) => {
if (item.hasOwnProperty('pattern') && item.trigger == 'change' && this.itemValue) {
let pattern: any = item.pattern;
if (!pattern.test(this.itemValue)) {
erro_text = item.message;
isCheck = false;
}
}
if (item.hasOwnProperty('required') && item.trigger == 'change') {
if (item.required && !this.itemValue) {
erro_text = item.message;
required = false;
}
}
public async validateRules(): Promise<boolean> {
return await this.validate(name,this.itemValue);
}
/**
* 校验值规则
*
* @returns {boolean}
* @memberof AppFormItem
*/
public validate(property:string, data:any):Promise<any>{
return new Promise((resolve, reject) => {
Util.validateItem(property,data,this.rules).then(()=>{
this.errorText = "";
resolve(true);
}).catch(({ errors, fields }) => {
this.errorText = errors[0].message;
resolve(false);
});
});
this.errorText = erro_text;
return isCheck && required ? true : false;
}
}
......
......@@ -309,8 +309,8 @@ export class Util {
*/
public static validateItem(property: string, data:any, rules:any) {
// 1.获取数值和规则
const value = data[property];
const rule = rules[property];
const value = data;
const rule = rules;
// 2.创建校验规则
const schema = new Schema({ [property]: rule })
// 校验返回Promise
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册