import{_ as e,G as r,b as t,d as a,p as n,w as s,H as u,i as l,o as i,f as o,k as c,Y as m,Z as f,C as d,W as h,a0 as g,V as k,X as b,L as _,K as p,R as M,a1 as R}from"./index-2PZN6pGH.js";const w={error:"",check:function(e,r){for(var t=0;t<r.length;t++){if(!r[t].checkType)return!0;if(!r[t].name)return!0;if(!r[t].errorMsg)return!0;if(!e[r[t].name])return this.error=r[t].errorMsg,!1;switch(r[t].checkType){case"string":if(!new RegExp("^.{"+r[t].checkRule+"}$").test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"int":if(!new RegExp("^(-[1-9]|[1-9])[0-9]{"+r[t].checkRule+"}$").test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"between":if(!this.isNumber(e[r[t].name]))return this.error=r[t].errorMsg,!1;if((a=r[t].checkRule.split(","))[0]=Number(a[0]),a[1]=Number(a[1]),e[r[t].name]>a[1]||e[r[t].name]<a[0])return this.error=r[t].errorMsg,!1;break;case"betweenD":if(!/^-?[1-9][0-9]?$/.test(e[r[t].name]))return this.error=r[t].errorMsg,!1;if((a=r[t].checkRule.split(","))[0]=Number(a[0]),a[1]=Number(a[1]),e[r[t].name]>a[1]||e[r[t].name]<a[0])return this.error=r[t].errorMsg,!1;break;case"betweenF":var a;if(!/^-?[0-9][0-9]?.+[0-9]+$/.test(e[r[t].name]))return this.error=r[t].errorMsg,!1;if((a=r[t].checkRule.split(","))[0]=Number(a[0]),a[1]=Number(a[1]),e[r[t].name]>a[1]||e[r[t].name]<a[0])return this.error=r[t].errorMsg,!1;break;case"same":if(e[r[t].name]!=r[t].checkRule)return this.error=r[t].errorMsg,!1;break;case"notsame":if(e[r[t].name]==r[t].checkRule)return this.error=r[t].errorMsg,!1;break;case"email":if(!/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"phoneno":if(!/^1[0-9]{10,10}$/.test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"zipcode":if(!/^[0-9]{6}$/.test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"reg":if(!new RegExp(r[t].checkRule).test(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"in":if(-1==r[t].checkRule.indexOf(e[r[t].name]))return this.error=r[t].errorMsg,!1;break;case"notnull":if(null==e[r[t].name]||e[r[t].name].length<1)return this.error=r[t].errorMsg,!1}}return!0},isNumber:function(e){return/^-?[1-9][0-9]?.?[0-9]*$/.test(e)}};const v=e({data:()=>({}),methods:{formSubmit:function(e){console.log("form发生了submit事件，携带数据为："+JSON.stringify(e.detail.value));var t=e.detail.value,a=w.check(t,[{name:"nickname",checkType:"string",checkRule:"1,3",errorMsg:"姓名应为1-3个字符"},{name:"gender",checkType:"in",checkRule:"男,女",errorMsg:"请选择性别"},{name:"loves",checkType:"notnull",checkRule:"",errorMsg:"请选择爱好"}]);r(a?{title:"验证通过!",icon:"none"}:{title:w.error,icon:"none"})},formReset:function(e){console.log("清空数据")}}},[["render",function(e,r,w,v,y,N){const $=t(a("page-head"),u),x=l,S=m,T=f,E=d,O=h,j=g,z=k,C=b,D=_,F=p,G=M,H=R;return i(),n(x,null,{default:s((()=>[o($,{title:"form"}),o(x,{class:"uni-padding-wrap uni-common-mt"},{default:s((()=>[o(H,{onSubmit:N.formSubmit,onReset:N.formReset},{default:s((()=>[o(x,{class:"uni-form-item uni-column"},{default:s((()=>[o(x,{class:"title"},{default:s((()=>[c("姓名")])),_:1}),o(S,{class:"uni-input",name:"nickname",placeholder:"请输入姓名"})])),_:1}),o(x,{class:"uni-form-item uni-column"},{default:s((()=>[o(x,{class:"title"},{default:s((()=>[c("性别")])),_:1}),o(j,{name:"gender"},{default:s((()=>[o(O,null,{default:s((()=>[o(T,{value:"男"}),o(E,null,{default:s((()=>[c("男")])),_:1})])),_:1}),o(O,null,{default:s((()=>[o(T,{value:"女"}),o(E,null,{default:s((()=>[c("女")])),_:1})])),_:1})])),_:1})])),_:1}),o(x,{class:"uni-form-item uni-column"},{default:s((()=>[o(x,{class:"title"},{default:s((()=>[c("爱好")])),_:1}),o(C,{name:"loves"},{default:s((()=>[o(O,null,{default:s((()=>[o(z,{value:"读书"}),o(E,null,{default:s((()=>[c("读书")])),_:1})])),_:1}),o(O,null,{default:s((()=>[o(z,{value:"写字"}),o(E,null,{default:s((()=>[c("写字")])),_:1})])),_:1})])),_:1})])),_:1}),o(x,{class:"uni-form-item uni-column"},{default:s((()=>[o(x,{class:"title"},{default:s((()=>[c("年龄")])),_:1}),o(D,{value:"20",name:"age","show-value":""})])),_:1}),o(x,{class:"uni-form-item uni-column"},{default:s((()=>[o(x,{class:"title"},{default:s((()=>[c("保留选项")])),_:1}),o(x,null,{default:s((()=>[o(F,{name:"switch"})])),_:1})])),_:1}),o(x,{class:"uni-btn-v"},{default:s((()=>[o(G,{"form-type":"submit"},{default:s((()=>[c("Submit")])),_:1}),o(G,{type:"default","form-type":"reset"},{default:s((()=>[c("Reset")])),_:1})])),_:1})])),_:1},8,["onSubmit","onReset"])])),_:1})])),_:1})}],["__scopeId","data-v-1f45e1fa"]]);export{v as default};
