var e=(e,a,s)=>new Promise((r,o)=>{var l=e=>{try{t(s.next(e))}catch(a){o(a)}},n=e=>{try{t(s.throw(e))}catch(a){o(a)}},t=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);t((s=s.apply(e,a)).next())});import{t as a,bJ as s,bA as r,bz as o,r as l,a2 as n,S as t,v as d,x as u,I as i,O as c,B as p,F as m,u as v,L as f,K as b}from"./vendor-core-k7kcNcJz.js";import{l as g,n as w,S as y,E as k,b as h}from"./index-n5dZU89t.js";import{E as _,n as q,i as x,S as U,A as V,e as I,U as P}from"./vendor-element-B74pkaZM.js";const S={class:"social-callback"},E={key:0,class:"loading-content"},L={key:1,class:"register-content"},j={class:"register-card"},C={class:"social-info"},R=["src"],$=h(a({__name:"index",setup(a){const{t:h}=s(),$=r(),z=o(),A=g(),N=l(!0),Q=l(""),T=l(!1),B=n({nickname:"",avatar:"",bind_token:"",provider:""}),F=l(),G=n({username:"",password:"",confirmPassword:""}),H={username:[{required:!0,message:"请输入用户名",trigger:"blur"},{min:4,max:20,message:"用户名长度应为 4-20 位",trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"},{min:6,message:"密码至少 6 位",trigger:"blur"}],confirmPassword:[{required:!0,message:"请确认密码",trigger:"blur"},{validator:(e,a,s)=>{a?a!==G.password?s(new Error("两次输入的密码不一致")):s():s(new Error("请确认密码"))},trigger:"blur"}]};t(()=>e(null,null,function*(){const e=$.query.token,a=$.query.type;if("unbound"===$.query.status)return N.value=!1,Q.value="unbound",B.bind_token=$.query.bind_token,B.provider=a,B.nickname=decodeURIComponent($.query.nickname||""),void(B.avatar=decodeURIComponent($.query.avatar||""));if(e)try{const s=`${e}_refresh`;A.setToken(e,s),A.setLoginStatus(!0);const r=yield w();A.setUserInfo(r),y.setUserSession(e,s,Number((null==r?void 0:r.userId)||(null==r?void 0:r.id)||0));const o={qq:"QQ",wechat:"微信",wx:"微信",weibo:"微博",alipay:"支付宝",github:"GitHub"}[a]||a||"第三方";_.success(`使用 ${o} 登录成功`);const l=$.query.redirect,n=$.query.action;l?z.replace(l):"bind"===n?z.replace("/user/center"):z.replace("/user/dashboard")}catch(s){_.error("登录失败，请重试"),z.replace("/user/login")}else _.error("登录参数错误"),z.replace("/user/login")}));const J=()=>e(null,null,function*(){F.value&&(yield F.value.validate(a=>e(null,null,function*(){var e;if(a){T.value=!0;try{const a=yield k({username:G.username,password:G.password,bind_token:B.bind_token,provider:B.provider}),s=(null==a?void 0:a.token)||(null==(e=null==a?void 0:a.data)?void 0:e.token);if(!s)throw new Error("登录凭证缺失");const r=`${s}_refresh`;A.setToken(s,r),A.setLoginStatus(!0);const o=yield w();A.setUserInfo(o),y.setUserSession(s,r,Number((null==o?void 0:o.userId)||(null==o?void 0:o.id)||0)),_.success("注册并绑定成功"),z.replace("/user/dashboard")}catch(s){}finally{T.value=!1}}})))});return(e,a)=>(u(),d("div",S,[N.value?(u(),d("div",E,[c(v(x),{class:"is-loading"},{default:m(()=>[c(v(q))]),_:1}),a[3]||(a[3]=p("p",{class:"loading-text"},"正在登录中，请稍候...",-1))])):"unbound"===Q.value?(u(),d("div",L,[p("div",j,[a[6]||(a[6]=p("h2",null,"完善账号信息",-1)),p("div",C,[B.avatar?(u(),d("img",{key:0,src:B.avatar,class:"avatar"},null,8,R)):i("",!0),p("p",null,"欢迎您，"+f(B.nickname),1),a[4]||(a[4]=p("p",{class:"sub-text"},"请设置您的账号密码以完成注册",-1))]),c(v(P),{ref_key:"formRef",ref:F,model:G,rules:H,"label-width":"0",size:"large"},{default:m(()=>[c(v(U),{prop:"username"},{default:m(()=>[c(v(V),{modelValue:G.username,"onUpdate:modelValue":a[0]||(a[0]=e=>G.username=e),placeholder:"请输入用户名 (4-20位字母数字)","prefix-icon":"User"},null,8,["modelValue"])]),_:1}),c(v(U),{prop:"password"},{default:m(()=>[c(v(V),{modelValue:G.password,"onUpdate:modelValue":a[1]||(a[1]=e=>G.password=e),type:"password",placeholder:"请输入密码","prefix-icon":"Lock","show-password":""},null,8,["modelValue"])]),_:1}),c(v(U),{prop:"confirmPassword"},{default:m(()=>[c(v(V),{modelValue:G.confirmPassword,"onUpdate:modelValue":a[2]||(a[2]=e=>G.confirmPassword=e),type:"password",placeholder:"请确认密码","prefix-icon":"Lock","show-password":""},null,8,["modelValue"])]),_:1}),c(v(U),null,{default:m(()=>[c(v(I),{type:"primary",loading:T.value,class:"submit-btn",onClick:J},{default:m(()=>[...a[5]||(a[5]=[b(" 完成注册并登录 ",-1)])]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"])])])):i("",!0)]))}}),[["__scopeId","data-v-7224398e"]]);export{$ as default};
