@@ -3,7 +3,7 @@ import RULES from './rules'
33const requiredFn = RULES . required . rule
44
55/**
6- * 环境检测:
6+ * 环境检测
77 */
88const isWx = typeof wx !== 'undefined' && ! ! wx . showToast // 微信小程序
99const isMy = typeof my !== 'undefined' && ! ! my . showToast // 支付宝小程序
@@ -32,7 +32,7 @@ class WeValidator {
3232 * @param {object } rules 验证字段的规则
3333 * @param {object } messages 验证字段错误的提示信息
3434 * @param {function } onMessage 错误提示显示方式
35- * @param {boolean } multiCheck 是否校验多个字段
35+ * @param {boolean } multiCheck 是否同时校验多个字段
3636 */
3737 static defaultOptions = {
3838 rules : { } ,
@@ -81,6 +81,7 @@ class WeValidator {
8181 * 显示错误提示
8282 */
8383 _showErrorMessage ( params , onMessage ) {
84+ // validatorInstance.checkData(data, onMessage)
8485 if ( isFunction ( onMessage ) ) {
8586 return onMessage ( params )
8687 }
@@ -113,18 +114,18 @@ class WeValidator {
113114
114115 // 百度小程序
115116 if ( isSwan ) {
116- return swan . showToast ( {
117- title : params . msg ,
118- icon : 'none'
119- } )
117+ return swan . showToast ( {
118+ title : params . msg ,
119+ icon : 'none'
120+ } )
120121 }
121122
122123 // 头条小程序
123124 if ( isTt ) {
124- return tt . showToast ( {
125- title : params . msg ,
126- icon : 'none'
127- } )
125+ return tt . showToast ( {
126+ title : params . msg ,
127+ icon : 'none'
128+ } )
128129 }
129130
130131 // 浏览器端
@@ -207,23 +208,21 @@ class WeValidator {
207208 value = data [ attr ]
208209 }
209210
210- let param = ruleParam
211-
212211 if ( isFunction ( ruleParam ) ) {
213- param = ruleParam . call ( this , value )
212+ ruleParam = ruleParam . call ( this , value )
214213 }
215214
216- let isFieldValid = WeValidator . checkValue . call ( this , ruleName , value , param )
215+ let isFieldValid = WeValidator . checkValue . call ( this , ruleName , value , ruleParam )
217216
218217 if ( ! isFieldValid ) {
219218 // 验证不通过
220- let msg = this . _getErrorMessage ( ruleName , attr , param )
219+ let msg = this . _getErrorMessage ( ruleName , attr , ruleParam )
221220
222221 if ( showMessage && msg ) {
223222 let errorParam = {
224223 name : attr ,
225224 value : value ,
226- param : param ,
225+ param : ruleParam ,
227226 rule : ruleName ,
228227 msg : msg
229228 }
0 commit comments