import{d as I,o as L,c as f,a as n,t as p,e as r,w as i,f as N,k as h,F as C,r as P,b as E,g as _,h as m,i as u,x as U,B as R,E as y,u as F,_ as K}from"./index-DUvV9NL6.js";import{a as V}from"./index-DZ_Kha3d.js";const M={class:"user-login-page"},T={class:"login-card"},$={class:"login-subtitle"},j={class:"login-switch"},D={key:0,class:"qr-section"},A={class:"qr-title"},G={class:"qr-grid"},H={class:"qr-label"},J={class:"qr-img-wrap"},O=["src","alt"],Q=I({__name:"UserLogin",setup(W){const z=F(),l=_(!0),w=_(!1),q=_(),g=_([]),b=_("扫码加入推广团队"),o=R({platform:"",phone:"",password:"",confirmPassword:""}),B={platform:[{required:!0,message:"请选择推广平台",trigger:"change"}],phone:[{validator:(d,e,t)=>{e?/^1[3-9]\d{9}$/.test(e)?t():t(new Error("请输入有效的手机号码")):t(new Error("请输入手机号码"))},trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"},{min:6,message:"密码至少6位",trigger:"blur"}],confirmPassword:[{validator:(d,e,t)=>{e?e!==o.password?t(new Error("两次密码不一致")):t():t(new Error("请确认密码"))},trigger:"blur"}]};L(async()=>{try{const{data:d}=await V.get("/api/promotion-platforms");g.value=d.platforms,d.title&&(b.value=d.title)}catch{}});async function k(){var e,t,v;if(await((e=q.value)==null?void 0:e.validate().catch(()=>!1))){w.value=!0;try{if(l.value){const a=o.platform+"-"+o.phone.trim(),{data:c}=await V.post("/api/user/login",{account:a,password:o.password});localStorage.setItem("user_token",c.token),localStorage.setItem("user_account",a),y.success("登录成功"),z.push("/user/dashboard")}else{const{data:a}=await V.post("/api/user/register",{platform:o.platform,phone:o.phone.trim(),password:o.password});y.success(a.message||"注册成功，请登录"),l.value=!0,o.password="",o.confirmPassword=""}}catch(a){y.error(((v=(t=a.response)==null?void 0:t.data)==null?void 0:v.error)||"操作失败")}finally{w.value=!1}}}return(d,e)=>{const t=m("el-option"),v=m("el-select"),a=m("el-form-item"),c=m("el-input"),x=m("el-button"),S=m("el-form");return u(),f("div",M,[n("div",T,[e[5]||(e[5]=n("h1",{class:"login-title"},"CloudSearch 用户中心",-1)),n("p",$,p(l.value?"登录您的账号":"注册新账号"),1),r(S,{ref_key:"formRef",ref:q,model:o,rules:B,"label-width":"0",onKeyup:N(k,["enter"])},{default:i(()=>[r(a,{prop:"platform"},{default:i(()=>[r(v,{modelValue:o.platform,"onUpdate:modelValue":e[0]||(e[0]=s=>o.platform=s),placeholder:"选择推广平台",size:"large",style:{width:"100%"}},{default:i(()=>[(u(!0),f(C,null,P(g.value,s=>(u(),U(t,{key:s.name,label:s.name,value:s.name},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),r(a,{prop:"phone"},{default:i(()=>[r(c,{modelValue:o.phone,"onUpdate:modelValue":e[1]||(e[1]=s=>o.phone=s),placeholder:"手机号码",size:"large"},null,8,["modelValue"])]),_:1}),r(a,{prop:"password"},{default:i(()=>[r(c,{modelValue:o.password,"onUpdate:modelValue":e[2]||(e[2]=s=>o.password=s),type:"password",placeholder:"密码",size:"large","show-password":""},null,8,["modelValue"])]),_:1}),l.value?E("",!0):(u(),U(a,{key:0,prop:"confirmPassword"},{default:i(()=>[r(c,{modelValue:o.confirmPassword,"onUpdate:modelValue":e[3]||(e[3]=s=>o.confirmPassword=s),type:"password",placeholder:"确认密码",size:"large","show-password":""},null,8,["modelValue"])]),_:1})),r(a,null,{default:i(()=>[r(x,{type:"primary",size:"large",loading:w.value,style:{width:"100%"},onClick:k},{default:i(()=>[h(p(l.value?"登 录":"注 册"),1)]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"]),n("div",j,[h(p(l.value?"还没有账号？":"已有账号？")+" ",1),r(x,{link:"",type:"primary",onClick:e[4]||(e[4]=s=>l.value=!l.value)},{default:i(()=>[h(p(l.value?"立即注册":"去登录"),1)]),_:1})])]),g.value.length>0?(u(),f("div",D,[n("div",A,p(b.value),1),n("div",G,[(u(!0),f(C,null,P(g.value,s=>(u(),f("div",{key:s.name,class:"qr-item"},[n("div",H,"加入【"+p(s.name)+"】团队",1),n("div",J,[n("img",{src:"https://api.qrserver.com/v1/create-qr-code/?size=120x120&data="+encodeURIComponent(s.join_url),alt:"加入"+s.name,class:"qr-image"},null,8,O)])]))),128))])])):E("",!0)])}}}),ee=K(Q,[["__scopeId","data-v-f27b738e"]]);export{ee as default};
