-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcddv.min.js
1 lines (1 loc) · 4.39 KB
/
cddv.min.js
1
!function(){"use strict";var e=function(e,a){if(!(e instanceof a))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,a){for(var t=0;t<a.length;t++){var i=a[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(a,t,i){return t&&e(a.prototype,t),i&&e(a,i),a}}(),t=new(function(){function t(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{inputCheckClass:"input-check-failed",finalCheckClass:"submit-check-failed",errorMsgShow:"cddv-msg-show",errorMsgHidden:"cddv-msg-hidden"};e(this,t),this._cfg={nonvoid:function(e,a){return a?e.trim()?0:["nonvoid"]:0},reg:function(e,a){return a.test(e)?0:["reg"]},limit:function(e,a){return+e>=a[0]&&+e<=a[1]?0:["limit"]},equal:function(e,a){return e==a?0:["equal"]},unequal:function(e,a){return e!=a?0:["unequal"]}},this._regList={ImgCode:/^[0-9a-zA-Z]{4}$/,SmsCode:/^\d{4}$/,MailCode:/^\d{4}$/,UserName:/^[\w|\d]{4,16}$/,Password:/^[\w!@#$%^&*.]{6,16}$/,Mobile:/^1[3|5|8]\d{9}$/,RealName:/^[\u4e00-\u9fa5 ]{2,10}$/,BankNum:/^\d{10,19}$/,Money:/^([1-9]\d*|0)$/,Answer:/^\S+$/,Mail:/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/},this._ERR_MSG={nonvoid:"该项要求不能为空值",reg:"格式错误",limit:"您输入的值不在区间内",equal:"两次输入的值不相等",unequal:"两次输入的值重复"},this.inputCheckClass=a.inputCheckClass,this.finalCheckClass=a.finalCheckClass,this.errorMsgHidden=a.errorMsgHidden,this.errorMsgShow=a.errorMsgShow}return a(t,[{key:"cinfig",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.inputCheckClass,e.finalCheckClass;this.inputCheckClass=o.inputCheckClass,this.finalCheckClass=o.finalCheckClass}},{key:"addClass",value:function(e,a){var t=e.className.split();-1==t.indexOf(a)&&(t.push(a),e.className=t.join(" "))}},{key:"removeClass",value:function(e,a){var t=new RegExp("(\\s"+a+"|"+a+"\\s)","g");e.className=e.className.replace(t,"")}},{key:"check",value:function(e,a,t){var i;i="reg"==e.arg?this._regList[e.value.format]?this._regList[e.value.format]:"stirng"==typeof e.value.format?new RegExp(e.value.format):e.value.format:e.value.aim?t._cddv.forms[e.value.aim].value||t.$data[e.value.aim]:t.$data[e.value.format]||e.value.format;var n=this.cfg[e.arg](a.value,i);return a._cddv.validated=0==n,n}},{key:"msg",value:function(e,a,t){var i="";switch(t[0]){case"nonvoid":i="["+e.value.title+"]",a._cddv.msg=i+this._ERR_MSG[t];break;case"reg":i="["+e.value.title+"]格式错误",a._cddv.msg=i;break;case"limit":i=+a.value<e.value.format[0]?"["+e.value.title+"]应该大于"+e.value.format[0]:"["+e.value.title+"]应该小于"+e.value.format[1],a._cddv.msg=this._ERR_MSG[t]+i;break;case"equal":case"unequal":i="["+e.value.title+"]",a._cddv.msg=i+this._ERR_MSG[t];break;default:a._cddv.msg="["+e.value.title+"]验证通过"}}},{key:"install",value:function(e,a){var t=this;e.directive("cddv-input",{bind:function(e,a,i){var n={value:a.value||"",arg:a.arg||""},r=i.context,s=r._cddv;e._cddv={dirty:!1,v_type:n.arg,indeed_value:n.value.format,validated:!1,msg:"未进行验证",title:n.value.title},s.forms[n.value.id]=e,e.onchange=function(){e._cddv.dirty||(e._cddv.dirty=!0);var a=0;a=t.check(n,e,r),t.msg(n,e,a),e._cddv.validated?t.removeClass(e,t.inputCheckClass):t.addClass(e,t.inputCheckClass),r.$emit("cddv-checked")}}}),e.directive("cddv-msg",{bind:function(e,a,i){var n={arg:a.arg},r=i.context;t.addClass(e,t.errorMsgHidden),r.$on("cddv-checked",function(){var a=r._cddv.forms[n.arg];a._cddv.validated?(t.removeClass(e,t.errorMsgShow),t.addClass(e,t.errorMsgHidden)):!a._cddv.validated&&a._cddv.dirty&&(t.removeClass(e,t.errorMsgHidden),t.addClass(e,t.errorMsgShow),e.innerHTML=a._cddv.msg)})}}),e.directive("cddv-final-check",{bind:function(e,a,i){var n={arg:a.arg||"",value:a.value||""},r=i.context;r.$on("cddv-checked",function(){var a=!0;if(n.value.keys)a=n.value.keys.every(function(e,a){return r._cddv.forms[e]._cddv.validated});else for(var i in r._cddv.forms)if("undefined"!=i&&!r._cddv.forms[i]._cddv.validated){a=!1;break}a?(t.removeClass(e,t.finalCheckClass),n.arg?e.onclick=r[n.arg]:e.onclick=n.value.method):(e.onclick=function(){},t.addClass(e,t.finalCheckClass))})}}),e.prototype._cddv={forms:{}},e.mixin({mounted:function(){}})}},{key:"ERR_MSG",get:function(){return this._ERR_MSG}},{key:"cfg",get:function(){return this._cfg}},{key:"regList",get:function(){return this._regList}}]),t}());Vue&&Vue.use(t)}();