import{d as P,G as j,r as n,c as m,b as l,a as s,A as B,w as o,U as T,K as Y,i as A,g as G,h as u,t as b,B as k,V as K,L,C as d,P as M,o as v}from"./index-DqVhJ65C.js";import{C as q}from"./Captcha-hQQe1ifD.js";const H={class:"min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"},J={class:"max-w-md w-full space-y-8 bg-white p-10 rounded-3xl shadow-xl border border-gray-100"},O={key:0,class:"space-y-6"},Q={class:"text-center mt-4"},W={key:1,class:"space-y-6"},X={class:"text-sm text-gray-500 text-center mb-4"},Z={class:"text-primary font-bold"},$={key:0,class:"text-gray-400 w-16 text-center"},ee={class:"fixed bottom-0 w-full p-4 text-center"},te={class:"text-sm text-gray-400 flex justify-center items-center gap-1"},oe=P({__name:"ForgotPassword",setup(se){const N=M(),R=j(()=>new Date().getFullYear()),f=n(0),x=n(!1),y=n(!1),c=n(0);let E=null;const t=n({target:"",code:"",new_password:"",confirm_password:""}),h=n(null),i=n(null),C=n(null),U=async()=>{try{const a=await k.get("/auth/captcha");h.value=a.data}catch(a){console.error(a)}},z=a=>{i.value=a,V()},V=async()=>{var a,e,p;if(!t.value.target)return d.warning("请输入手机号或邮箱");if((a=h.value)!=null&&a.enabled&&!i.value){(e=C.value)==null||e.verify();return}y.value=!0;try{(await k.post("/auth/sendCode",{target:t.value.target,type:"reset_password",...i.value||{}})).code===0&&(d.success("验证码已发送"),I(),f.value=1)}catch(g){console.error(g),i.value=null,i.value=null,(p=C.value)==null||p.reset()}finally{y.value=!1}},I=()=>{c.value=60,E=setInterval(()=>{c.value--,c.value<=0&&clearInterval(E)},1e3)},D=async()=>{if(!t.value.code)return d.warning("请输入验证码");if(!t.value.new_password)return d.warning("请输入新密码");if(t.value.new_password!==t.value.confirm_password)return d.warning("两次输入密码不一致");x.value=!0;try{(await k.post("/auth/forgotPassword",{target:t.value.target,code:t.value.code,new_password:t.value.new_password})).code===0&&(d.success("密码重置成功"),setTimeout(()=>{N.push("/login")},1500))}catch(a){console.error(a)}finally{x.value=!1}};return U(),(a,e)=>{const p=K,g=T,w=L,_=Y,S=A,F=G("router-link");return v(),m("div",H,[l("div",J,[e[9]||(e[9]=l("div",{class:"text-center"},[l("h2",{class:"text-3xl font-extrabold text-gray-900"},"找回密码"),l("p",{class:"mt-2 text-sm text-gray-600"},"重置您的账户密码")],-1)),s(g,{active:f.value,"finish-status":"success",simple:"",class:"!bg-transparent !p-0 mb-8"},{default:o(()=>[s(p,{title:"验证身份"}),s(p,{title:"重置密码"})]),_:1},8,["active"]),f.value===0?(v(),m("div",O,[s(_,null,{default:o(()=>[s(w,{modelValue:t.value.target,"onUpdate:modelValue":e[0]||(e[0]=r=>t.value.target=r),placeholder:"请输入注册邮箱或手机号",size:"large",class:"!rounded-xl"},{prefix:o(()=>[...e[4]||(e[4]=[l("i",{class:"el-icon-user"},null,-1)])]),_:1},8,["modelValue"])]),_:1}),s(q,{ref_key:"captchaRef",ref:C,config:h.value,onSuccess:z},null,8,["config"]),s(S,{type:"primary",class:"w-full !h-12 !rounded-xl",loading:y.value,onClick:V},{default:o(()=>[...e[5]||(e[5]=[u(" 发送验证码 ",-1)])]),_:1},8,["loading"]),l("div",Q,[s(F,{to:"/login",class:"text-sm text-gray-500 hover:text-primary"},{default:o(()=>[...e[6]||(e[6]=[u("返回登录",-1)])]),_:1})])])):B("",!0),f.value===1?(v(),m("div",W,[l("div",X,[e[7]||(e[7]=u(" 验证码已发送至 ",-1)),l("span",Z,b(t.value.target),1)]),s(_,null,{default:o(()=>[s(w,{modelValue:t.value.code,"onUpdate:modelValue":e[1]||(e[1]=r=>t.value.code=r),placeholder:"请输入6位验证码",size:"large",class:"!rounded-xl"},{append:o(()=>[c.value>0?(v(),m("span",$,b(c.value)+"s",1)):(v(),m("span",{key:1,class:"cursor-pointer text-primary",onClick:V},"重发"))]),_:1},8,["modelValue"])]),_:1}),s(_,null,{default:o(()=>[s(w,{modelValue:t.value.new_password,"onUpdate:modelValue":e[2]||(e[2]=r=>t.value.new_password=r),type:"password",placeholder:"新密码","show-password":"",size:"large",class:"!rounded-xl"},null,8,["modelValue"])]),_:1}),s(_,null,{default:o(()=>[s(w,{modelValue:t.value.confirm_password,"onUpdate:modelValue":e[3]||(e[3]=r=>t.value.confirm_password=r),type:"password",placeholder:"确认新密码","show-password":"",size:"large",class:"!rounded-xl"},null,8,["modelValue"])]),_:1}),s(S,{type:"primary",class:"w-full !h-12 !rounded-xl",loading:x.value,onClick:D},{default:o(()=>[...e[8]||(e[8]=[u(" 确认重置 ",-1)])]),_:1},8,["loading"])])):B("",!0)]),l("div",ee,[l("div",te,[e[10]||(e[10]=u(" Copyright ",-1)),e[11]||(e[11]=l("span",{class:"text-base"},"©",-1)),u(" "+b(R.value)+" 新云DNS系统 ",1)])])])}}});export{oe as default};
