| | |
| | | }); |
| | | }, |
| | | // 对部分表单字段进行校验 |
| | | async validateField(value, callback, event = null) { |
| | | async validateField(value, callback, event = null,options) { |
| | | // $nextTick是必须的,否则model的变更,可能会延后于此方法的执行 |
| | | this.$nextTick(() => { |
| | | // 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息 |
| | |
| | | errorsRes.push(...errors); |
| | | childErrors.push(...errors); |
| | | } |
| | | //没有配置,或者配置了showErrorMsg为true时候,才修改子组件message,默认没有配置 |
| | | if(!options||options?.showErrorMsg==true){ |
| | | child.message = |
| | | childErrors[0]?.message ? childErrors[0].message : null; |
| | | |
| | | } |
| | | if (i == (rules.length - 1)) { |
| | | resolve(errorsRes) |
| | | } |
| | |
| | | }); |
| | | }); |
| | | }, |
| | | // 校验全部数据 |
| | | validate(callback) { |
| | | /** |
| | | * 校验全部数据 |
| | | * @param {Object} options |
| | | * @param {Boolean} options.showErrorMsg -是否显示校验信息, |
| | | */ |
| | | validate(options) { |
| | | // 开发环境才提示,生产环境不会提示 |
| | | if (process.env.NODE_ENV === 'development' && Object.keys(this.formRules).length === 0) { |
| | | error('未设置rules,请看文档说明!如果已经设置,请刷新页面。'); |
| | |
| | | } else { |
| | | resolve(true) |
| | | } |
| | | }); |
| | | },null,options); |
| | | }); |
| | | }); |
| | | }, |