import{C as e,D as t,E as n,M as r,O as i,T as a,_ as o,a as s,b as c,k as l,l as u,m as d,o as f,s as p,v as m,x as h,y as g}from"./index-vhvNh9F8.js";var _={class:`page`},v={style:{padding:`30px 24px`}},y={class:`captcha-row`},b=[`innerHTML`],x={class:`sms-row`},S=p({__name:`Register`,setup(p){let S=u(),C=t({phone:``,password:``,nickname:``,captchaText:``,captchaId:``,smsCode:``}),w=i(!1),T=i(``),E=i(0),D=null;async function O(){try{let e=await s.get(`/captcha/image`);e.code===0&&(T.value=e.data.svg,C.captchaId=e.data.id)}catch{}}function k(){E.value=60,D&&clearInterval(D),D=setInterval(()=>{E.value--,E.value<=0&&(clearInterval(D),D=null)},1e3)}async function A(){if(!C.phone){alert(`请先输入手机号`);return}if(!C.captchaId||!C.captchaText){alert(`请先输入图形验证码`);return}try{if((await s.post(`/captcha/verify`,{id:C.captchaId,text:C.captchaText})).code!==0){alert(`验证码错误`),O();return}}catch{alert(`验证失败`);return}try{let e=await s.post(`/captcha/sms`,{phone:C.phone});e.code===0?(alert(e.message||`验证码已发送`),k()):alert(e.message||`发送失败`)}catch{alert(`网络错误`)}}async function j(){if(!C.phone||!C.password){alert(`请填写完整`);return}if(C.password.length<6){alert(`密码至少6位`);return}if(!C.smsCode){alert(`请验证手机号`);return}w.value=!0;try{let e=await s.post(`/user/register`,{...C,sms_code:C.smsCode});e.code===0?(alert(`注册成功`),S.push(`/login`)):alert(e.message||`注册失败`)}catch{alert(`网络错误`)}w.value=!1}return h(()=>{O()}),(t,i)=>{let s=a(`van-field`),u=a(`van-button`);return e(),o(`div`,_,[c(f,{title:`注册`,onBack:i[0]||=e=>l(S).push(`/login`)}),d(`div`,v,[i[7]||=m(`<div class="reg-logo" data-v-dcab0ca4><svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="var(--primary)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" data-v-dcab0ca4><path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2" data-v-dcab0ca4></path><circle cx="12" cy="7" r="4" data-v-dcab0ca4></circle><line x1="12" y1="11" x2="12" y2="17" data-v-dcab0ca4></line><line x1="9" y1="14" x2="15" y2="14" data-v-dcab0ca4></line></svg><div class="reg-title" data-v-dcab0ca4>创建账号</div></div>`,1),c(s,{modelValue:C.phone,"onUpdate:modelValue":i[1]||=e=>C.phone=e,label:`手机号`,placeholder:`请输入手机号`},null,8,[`modelValue`]),d(`div`,y,[c(s,{modelValue:C.captchaText,"onUpdate:modelValue":i[2]||=e=>C.captchaText=e,label:`验证码`,placeholder:`输入验证码`,maxlength:`4`},null,8,[`modelValue`]),T.value?(e(),o(`div`,{key:0,class:`captcha-img`,onClick:O,innerHTML:T.value},null,8,b)):(e(),o(`span`,{key:1,class:`captcha-refresh`,onClick:O},`获取验证码`))]),d(`div`,x,[c(s,{modelValue:C.smsCode,"onUpdate:modelValue":i[3]||=e=>C.smsCode=e,label:`短信验证`,placeholder:`输入短信验证码`,maxlength:`6`},null,8,[`modelValue`]),c(u,{round:``,size:`small`,class:`sms-btn`,disabled:E.value>0,onClick:A},{default:n(()=>[g(r(E.value>0?E.value+`s`:`获取验证码`),1)]),_:1},8,[`disabled`])]),c(s,{modelValue:C.password,"onUpdate:modelValue":i[4]||=e=>C.password=e,type:`password`,label:`密码`,placeholder:`至少6位`},null,8,[`modelValue`]),c(s,{modelValue:C.nickname,"onUpdate:modelValue":i[5]||=e=>C.nickname=e,label:`昵称`,placeholder:`选填`},null,8,[`modelValue`]),c(u,{round:``,block:``,class:`primary-btn`,style:{"margin-top":`24px`,height:`44px`},onClick:j,loading:w.value},{default:n(()=>[...i[6]||=[g(`注 册`,-1)]]),_:1},8,[`loading`])])])}}},[[`__scopeId`,`data-v-dcab0ca4`]]);export{S as default};