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