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,bG as s,r,a3 as o,S as l,bB as n,bA as t,v as d,I as u,O as i,B as c,F as p,u as m,L as v,x as f,K as b,bD as g}from"./vendor-core-B-NFAs71.js";import{a as w,f as y,S as k,b as h}from"./index-DYPGJs8A.js";import{E as _,i as q,l as x,m as U,n as V,o as I,e as P}from"./vendor-element-C6D3GHVC.js";const S={class:"social-callback"},L={key:0,class:"loading-content"},E={key:1,class:"register-content"},j={class:"register-card"},C={class:"social-info"},R=["src"],$=g(a({__name:"index",setup(a){const{t:g}=s(),$=n(),B=t(),G=w(),N=r(!0),Q=r(""),T=r(!1),z=o({nickname:"",avatar:"",bind_token:"",provider:""}),A=r(),D=o({username:"",password:"",confirmPassword:""}),F={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!==D.password?s(new Error("两次输入的密码不一致")):s():s(new Error("请确认密码"))},trigger:"blur"}]};l(()=>e(null,null,function*(){const e=$.query.token,a=$.query.type;if("unbound"===$.query.status)return N.value=!1,Q.value="unbound",z.bind_token=$.query.bind_token,z.provider=a,z.nickname=decodeURIComponent($.query.nickname||""),void(z.avatar=decodeURIComponent($.query.avatar||""));if(e)try{const s=`${e}_refresh`;G.setToken(e,s),G.setLoginStatus(!0);const r=yield y();G.setUserInfo(r),k.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?B.replace(l):"bind"===n?B.replace("/user/center"):B.replace("/user/dashboard")}catch(s){_.error("登录失败，请重试"),B.replace("/user/login")}else _.error("登录参数错误"),B.replace("/user/login")}));const H=()=>e(null,null,function*(){A.value&&(yield A.value.validate(a=>e(null,null,function*(){var e;if(a){T.value=!0;try{const a=yield h({username:D.username,password:D.password,bind_token:z.bind_token,provider:z.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`;G.setToken(s,r),G.setLoginStatus(!0);const o=yield y();G.setUserInfo(o),k.setUserSession(s,r,Number((null==o?void 0:o.userId)||(null==o?void 0:o.id)||0)),_.success("注册并绑定成功"),B.replace("/user/dashboard")}catch(s){}finally{T.value=!1}}})))});return(e,a)=>(f(),d("div",S,[N.value?(f(),d("div",L,[i(m(q),{class:"is-loading"},{default:p(()=>[i(m(U))]),_:1}),a[3]||(a[3]=c("p",{class:"loading-text"},"正在登录中，请稍候...",-1))])):"unbound"===Q.value?(f(),d("div",E,[c("div",j,[a[6]||(a[6]=c("h2",null,"完善账号信息",-1)),c("div",C,[z.avatar?(f(),d("img",{key:0,src:z.avatar,class:"avatar"},null,8,R)):u("",!0),c("p",null,"欢迎您，"+v(z.nickname),1),a[4]||(a[4]=c("p",{class:"sub-text"},"请设置您的账号密码以完成注册",-1))]),i(m(x),{ref_key:"formRef",ref:A,model:D,rules:F,"label-width":"0",size:"large"},{default:p(()=>[i(m(V),{prop:"username"},{default:p(()=>[i(m(I),{modelValue:D.username,"onUpdate:modelValue":a[0]||(a[0]=e=>D.username=e),placeholder:"请输入用户名 (4-20位字母数字)","prefix-icon":"User"},null,8,["modelValue"])]),_:1}),i(m(V),{prop:"password"},{default:p(()=>[i(m(I),{modelValue:D.password,"onUpdate:modelValue":a[1]||(a[1]=e=>D.password=e),type:"password",placeholder:"请输入密码","prefix-icon":"Lock","show-password":""},null,8,["modelValue"])]),_:1}),i(m(V),{prop:"confirmPassword"},{default:p(()=>[i(m(I),{modelValue:D.confirmPassword,"onUpdate:modelValue":a[2]||(a[2]=e=>D.confirmPassword=e),type:"password",placeholder:"请确认密码","prefix-icon":"Lock","show-password":""},null,8,["modelValue"])]),_:1}),i(m(V),null,{default:p(()=>[i(m(P),{type:"primary",loading:T.value,class:"submit-btn",onClick:H},{default:p(()=>[...a[5]||(a[5]=[b(" 完成注册并登录 ",-1)])]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"])])])):u("",!0)]))}}),[["__scopeId","data-v-4b591984"]]);export{$ as default};
