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,bD as s,r,a1 as o,R as l,bz as n,by as t,t as d,H as u,M as i,A as c,E as p,u as m,K as v,v as f,J as b}from"./vendor-core-DQkwEQyE.js";import{a as g,f as w,S as y,b as k,c as h}from"./index-DOwSoTEN.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-CbJWrKZ5.js";const E={class:"social-callback"},S={key:0,class:"loading-content"},L={key:1,class:"register-content"},R={class:"register-card"},j={class:"social-info"},C=["src"],$=h(a({__name:"index",setup(a){const{t:h}=s(),$=n(),z=t(),H=g(),N=r(!0),Q=r(""),T=r(!1),A=o({nickname:"",avatar:"",bind_token:"",provider:""}),D=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",A.bind_token=$.query.bind_token,A.provider=a,A.nickname=decodeURIComponent($.query.nickname||""),void(A.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?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 K=()=>e(null,null,function*(){D.value&&(yield D.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:A.bind_token,provider:A.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("注册并绑定成功"),z.replace("/user/dashboard")}catch(s){}finally{T.value=!1}}})))});return(e,a)=>(f(),d("div",E,[N.value?(f(),d("div",S,[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",L,[c("div",R,[a[6]||(a[6]=c("h2",null,"完善账号信息",-1)),c("div",j,[A.avatar?(f(),d("img",{key:0,src:A.avatar,class:"avatar"},null,8,C)):u("",!0),c("p",null,"欢迎您，"+v(A.nickname),1),a[4]||(a[4]=c("p",{class:"sub-text"},"请设置您的账号密码以完成注册",-1))]),i(m(x),{ref_key:"formRef",ref:D,model:G,rules:J,"label-width":"0",size:"large"},{default:p(()=>[i(m(V),{prop:"username"},{default:p(()=>[i(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}),i(m(V),{prop:"password"},{default:p(()=>[i(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}),i(m(V),{prop:"confirmPassword"},{default:p(()=>[i(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}),i(m(V),null,{default:p(()=>[i(m(P),{type:"primary",loading:T.value,class:"submit-btn",onClick:K},{default:p(()=>[...a[5]||(a[5]=[b(" 完成注册并登录 ",-1)])]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"])])])):u("",!0)]))}}),[["__scopeId","data-v-4b591984"]]);export{$ as default};
