var h=(l,p,n)=>new Promise((f,r)=>{var i=a=>{try{c(n.next(a))}catch(o){r(o)}},g=a=>{try{c(n.throw(a))}catch(o){r(o)}},c=a=>a.done?f(a.value):Promise.resolve(a.value).then(i,g);c((n=n.apply(l,p)).next())});import{u as C,F as U}from"./useForm-kq1sxERw.js";import{u as q,l as B,d as z,e as I,m as D,c as N}from"./index-D4Ne4xf-.js";import{l as O,aB as Z,Z as $,U as t,F as v,r as y,b as G,w as H,u as d,m as J,M as K,y as Q}from"./vue-chunks-DyZSmvoe.js";import{u as T}from"./useValidator-BN3tPovt.js";import{x as W,y as X}from"./element-plus-DNKe9-lk.js";function _(l){return typeof l=="function"||Object.prototype.toString.call(l)==="[object Object]"&&!Q(l)}const ae=O({__name:"LoginForm",emits:["to-register"],setup(l,{emit:p}){const{required:n}=T(),f=p;q();const r=B(),i=z(),{currentRoute:g,addRoute:c,push:a}=Z(),{t:o}=N(),P={username:[n()],password:[n()]},R=$([{field:"title",colProps:{span:24},formItemProps:{slots:{default:()=>t("h2",{class:"text-2xl font-bold text-center w-[100%]"},[o("login.login")])}}},{field:"username",label:o("login.username"),component:"Input",colProps:{span:24},componentProps:{placeholder:"用户名"}},{field:"password",label:o("login.password"),component:"InputPassword",colProps:{span:24},componentProps:{style:{width:"100%"},placeholder:"密码"}},{field:"tool",colProps:{span:24},formItemProps:{slots:{default:()=>{let e;return t(v,null,[t("div",{class:"flex justify-between items-center w-[100%]"},[t(W,{modelValue:m.value,"onUpdate:modelValue":s=>m.value=s,label:o("login.remember"),size:"small"},null),t(X,{type:"primary",underline:!1},_(e=o("login.forgetPassword"))?e:{default:()=>[e]})])])}}}},{field:"login",colProps:{span:24},formItemProps:{slots:{default:()=>{let e,s;return t(v,null,[t("div",{class:"w-[100%]"},[t(I,{loading:w.value,type:"primary",class:"w-[100%]",onClick:M},_(e=o("login.login"))?e:{default:()=>[e]})]),t("div",{class:"w-[100%] mt-15px"},[t(I,{class:"w-[100%]",onClick:j},_(s=o("login.register"))?s:{default:()=>[s]})])])}}}}]),m=y(r.getRememberMe),k=()=>{const e=r.getLoginInfo;if(e){const{username:s,password:u}=e;V({username:s,password:u})}};G(()=>{k()});const{formRegister:x,formMethods:F}=C(),{getFormData:S,getElFormExpose:L,setValues:V}=F,w=y(!1),E=y("");H(()=>g.value,e=>{var s;E.value=(s=e==null?void 0:e.query)==null?void 0:s.redirect},{immediate:!0});const M=()=>h(this,null,function*(){const e=yield L();yield e==null?void 0:e.validate(s=>h(this,null,function*(){if(s){w.value=!0;const u=yield S();try{const b=yield D(u);b&&(d(m)?r.setLoginInfo({username:u.username,password:u.password}):r.setLoginInfo(void 0),r.setRememberMe(d(m)),r.setUserInfo(b),yield i.generateRoutes("static").catch(()=>{}),i.getAddRouters.forEach(A=>{c(A)}),i.setIsAddRouters(!0),a({path:i.addRouters[0].path}))}finally{w.value=!1}}}))}),j=()=>{f("to-register")};return(e,s)=>(J(),K(d(U),{schema:R,rules:P,"label-position":"top","hide-required-asterisk":"",size:"large",class:"dark:border-1 dark:border-[var(--el-border-color)] dark:border-solid",onRegister:d(x)},null,8,["schema","onRegister"]))}});export{ae as _};
