import{d as U,r as c,G as B,z as P,R as D,c as M,b as n,a as l,w as t,I as F,J as j,h as m,t as b,B as y,K as T,L as Y,E as A,u as f,M as G,S as J,T as K,i as L,m as C,g as $,C as v,P as q,o as H}from"./index-DqVhJ65C.js";import{C as O}from"./Captcha-hQQe1ifD.js";const Q={class:"min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"},W={class:"max-w-md w-full space-y-8 bg-white p-10 rounded-3xl shadow-xl border border-gray-100"},X={class:"flex w-full gap-4"},Z={class:"text-center mt-6"},ee={class:"fixed bottom-0 w-full p-4 text-center"},ae={class:"text-sm text-gray-400 flex justify-center items-center gap-1"},oe=U({__name:"Register",setup(le){const E=q(),g=c(!1),k=B(()=>new Date().getFullYear()),d=c(0);let x=null;const e=c({username:"",password:"",confirmPassword:"",contact:"",code:""}),_=c(null),i=c(null),w=c(null),S=async()=>{try{const s=await y.get("/auth/captcha");_.value=s.data}catch(s){console.error(s)}},z=s=>{i.value=s,e.value.contact&&h()},h=async()=>{var s,a,o;if(!e.value.contact)return v.warning("请先输入邮箱或手机号");if((s=_.value)!=null&&s.enabled&&!i.value){(a=w.value)==null||a.verify();return}try{(await y.post("/auth/sendCode",{target:e.value.contact,type:"register",...i.value||{}})).code===0&&(v.success("验证码已发送"),d.value=60,x=setInterval(()=>{d.value--,d.value<=0&&clearInterval(x)},1e3))}catch(r){console.error(r),i.value=null,i.value=null,(o=w.value)==null||o.reset()}},I=async()=>{if(!e.value.username||!e.value.password||!e.value.contact||!e.value.code)return v.warning("请填写完整信息");if(e.value.password!==e.value.confirmPassword)return v.warning("两次密码输入不一致");g.value=!0;try{const s=e.value.contact.includes("@"),a=s,o={username:e.value.username,password:e.value.password,code:e.value.code,email:s?e.value.contact:void 0,mobile:s?void 0:e.value.contact};(await y.post("/auth/register",o)).code===0&&(v.success("注册成功，请登录"),E.push("/login"))}catch(s){console.error(s)}finally{g.value=!1}};return P(()=>{S()}),D(()=>{x&&clearInterval(x)}),(s,a)=>{const o=A,r=Y,p=T,V=L,R=$("router-link"),N=j;return H(),M("div",Q,[n("div",W,[a[8]||(a[8]=n("div",{class:"text-center"},[n("h2",{class:"text-3xl font-extrabold text-gray-900"},"注册新账号"),n("p",{class:"mt-2 text-sm text-gray-600"},"加入 NewDNS，开始分发您的域名")],-1)),l(N,{model:e.value,class:"mt-8 space-y-4",onSubmit:F(I,["prevent"])},{default:t(()=>[l(p,null,{default:t(()=>[l(r,{modelValue:e.value.username,"onUpdate:modelValue":a[0]||(a[0]=u=>e.value.username=u),placeholder:"用户名 (4-20位)",size:"large",class:"!rounded-xl"},{prefix:t(()=>[l(o,null,{default:t(()=>[l(f(G))]),_:1})]),_:1},8,["modelValue"])]),_:1}),l(p,null,{default:t(()=>[l(r,{modelValue:e.value.contact,"onUpdate:modelValue":a[1]||(a[1]=u=>e.value.contact=u),placeholder:"邮箱或手机号",size:"large",class:"!rounded-xl"},{prefix:t(()=>[l(o,null,{default:t(()=>[l(f(J))]),_:1})]),_:1},8,["modelValue"])]),_:1}),l(p,null,{default:t(()=>[n("div",X,[l(r,{modelValue:e.value.code,"onUpdate:modelValue":a[2]||(a[2]=u=>e.value.code=u),placeholder:"验证码",size:"large",class:"flex-1 !rounded-xl"},{prefix:t(()=>[l(o,null,{default:t(()=>[l(f(K))]),_:1})]),_:1},8,["modelValue"]),l(V,{size:"large",class:"!rounded-xl w-32",disabled:d.value>0,onClick:h},{default:t(()=>[m(b(d.value>0?`${d.value}s`:"发送"),1)]),_:1},8,["disabled"])])]),_:1}),l(p,null,{default:t(()=>[l(r,{modelValue:e.value.password,"onUpdate:modelValue":a[3]||(a[3]=u=>e.value.password=u),type:"password",placeholder:"设置密码","show-password":"",size:"large",class:"!rounded-xl"},{prefix:t(()=>[l(o,null,{default:t(()=>[l(f(C))]),_:1})]),_:1},8,["modelValue"])]),_:1}),l(p,null,{default:t(()=>[l(r,{modelValue:e.value.confirmPassword,"onUpdate:modelValue":a[4]||(a[4]=u=>e.value.confirmPassword=u),type:"password",placeholder:"确认密码","show-password":"",size:"large",class:"!rounded-xl"},{prefix:t(()=>[l(o,null,{default:t(()=>[l(f(C))]),_:1})]),_:1},8,["modelValue"])]),_:1}),l(O,{ref_key:"captchaRef",ref:w,config:_.value,onSuccess:z},null,8,["config"]),l(V,{type:"primary","native-type":"submit",class:"w-full !h-12 !rounded-xl text-lg",loading:g.value},{default:t(()=>[...a[5]||(a[5]=[m(" 立即注册 ",-1)])]),_:1},8,["loading"]),n("div",Z,[a[7]||(a[7]=n("span",{class:"text-sm text-gray-500"},"已有账号? ",-1)),l(R,{to:"/login",class:"text-sm text-primary font-bold hover:underline"},{default:t(()=>[...a[6]||(a[6]=[m(" 立即登录 ",-1)])]),_:1})])]),_:1},8,["model"])]),n("div",ee,[n("div",ae,[a[9]||(a[9]=m(" Copyright ",-1)),a[10]||(a[10]=n("span",{class:"text-base"},"©",-1)),m(" "+b(k.value)+" 新云DNS系统 ",1)])])])}}});export{oe as default};
