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