var _=(r,h,l)=>new Promise((n,d)=>{var w=a=>{try{c(l.next(a))}catch(i){d(i)}},P=a=>{try{c(l.throw(a))}catch(i){d(i)}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(w,P);c((l=l.apply(r,h)).next())});import{u as N,F as O}from"./useForm-DFfbRY9m.js";import{d as z,l as L,e as I,n as Z,o as $,q as D,c as G}from"./index-OziN21LA.js";import{u as H}from"./useValidator-dY8qp_qX.js";import{l as J,aB as K,Z as k,U as t,F as Q,b as T,r as F,w as W,m as X,M as Y,u as B,y as ee}from"./vue-chunks-l-AyUCfi.js";import{p as se}from"./element-plus-C2aeItNs.js";function C(r){return typeof r=="function"||Object.prototype.toString.call(r)==="[object Object]"&&!ee(r)}const ce=J({__name:"RegisterForm",emits:["to-login"],setup(r,{emit:h}){const l=h,n=z(),{currentRoute:d,addRoute:w,push:P}=K(),{formRegister:c,formMethods:a}=N(),{getElFormExpose:i,getFormData:b}=a,{t:o}=G(),S=L(),{required:p,lengthRange:R}=H(),E=k({username:"",password:"",code:"",check_password:""}),m=k({id:"",imageBase64:""}),U=k([{field:"title",colProps:{span:24},formItemProps:{slots:{default:()=>t("h2",{class:"text-2xl font-bold text-center w-[100%]"},[o("login.register")])}}},{field:"username",label:o("login.username"),value:"",component:"Input",colProps:{span:24},componentProps:{placeholder:o("login.usernamePlaceholder")}},{field:"password",label:o("login.password"),value:"",component:"InputPassword",colProps:{span:24},componentProps:{style:{width:"100%"},strength:!0,placeholder:o("login.passwordPlaceholder")}},{field:"check_password",label:o("login.checkPassword"),value:"",component:"InputPassword",colProps:{span:24},componentProps:{style:{width:"100%"},strength:!0,placeholder:o("login.passwordPlaceholder")}},{field:"code",label:o("login.code"),colProps:{span:24},formItemProps:{slots:{default:e=>t("div",{class:"w-[100%] flex"},[t(se,{modelValue:e.code,"onUpdate:modelValue":s=>e.code=s,placeholder:o("login.codePlaceholder")},null),t("img",{class:"w-22 ml-2",onClick:y,src:m.imageBase64},null)])}}},{field:"register",colProps:{span:24},formItemProps:{slots:{default:()=>{let e,s;return t(Q,null,[t("div",{class:"w-[100%]"},[t(I,{type:"primary",class:"w-[100%]",loading:u.value,onClick:j},C(e=o("login.register"))?e:{default:()=>[e]})]),t("div",{class:"w-[100%] mt-15px"},[t(I,{class:"w-[100%]",onClick:M},C(s=o("login.hasUser"))?s:{default:()=>[s]})])])}}}}]),y=()=>_(this,null,function*(){const{id:e,imageBase64:s}=yield Z();m.id=e,m.imageBase64=s});T(()=>{y()});const V=F("");W(()=>d.value,e=>{var s;V.value=(s=e==null?void 0:e.query)==null?void 0:s.redirect},{immediate:!0});const q={username:[p(),R({min:6,max:16})],password:[p(),R({min:6,max:16})],check_password:[p(),{validator:(e,s,g)=>{b().then(v=>{const{password:f,check_password:x}=v;f!=x?g(new Error("密码不一致")):g()})}}],code:[p()]},M=()=>{l("to-login")},u=F(!1),j=()=>_(this,null,function*(){const e=yield i();try{if(yield e==null?void 0:e.validate()){const{password:g,code:v,username:f}=yield b(),x=yield $({id:m.id,answer:v});yield D({username:f,password:g}),yield n.generateRoutes("static").catch(()=>{}),n.getAddRouters.forEach(A=>{w(A)}),S.setUserInfo({username:f}),n.setIsAddRouters(!0),P({path:n.addRouters[0].path}),u.value=!0}}catch(s){u.value=!1}finally{u.value=!1}});return(e,s)=>(X(),Y(B(O),{schema:U,rules:q,"label-position":"top",model:E,"hide-required-asterisk":"",size:"large",class:"dark:border-1 dark:border-[var(--el-border-color)] dark:border-solid",onRegister:B(c)},null,8,["schema","model","onRegister"]))}});export{ce as _};
