import{d as k,c as x,a as d,t as c,e as t,w as l,f as C,k as _,g,h as p,i as h,x as E,b as P,B,E as w,u as S,_ as U}from"./index-C2VdJ-SC.js";import{a as z}from"./index-DZ_Kha3d.js";const N={class:"user-login-page"},I={class:"login-card"},L={class:"login-subtitle"},R={class:"login-switch"},A=k({__name:"UserLogin",setup(K){const V=S(),a=g(!0),m=g(!1),v=g(),s=B({account:"",password:"",confirmPassword:""}),b={account:[{validator:(f,e,o)=>{e?e.includes("-")?o():o(new Error("账号格式：推广平台-手机号")):o(new Error("请输入账号"))},trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"},{min:6,message:"密码至少6位",trigger:"blur"}],confirmPassword:[{validator:(f,e,o)=>{e?e!==s.password?o(new Error("两次密码不一致")):o():o(new Error("请确认密码"))},trigger:"blur"}]};async function y(){var e,o,r;if(await((e=v.value)==null?void 0:e.validate().catch(()=>!1))){m.value=!0;try{const n=a.value?"/api/user/login":"/api/user/register",{data:u}=await z.post(n,{account:s.account.trim(),password:s.password});a.value?(localStorage.setItem("user_token",u.token),localStorage.setItem("user_account",s.account.trim()),w.success("登录成功"),V.push("/user/dashboard")):(w.success(u.message||"注册成功，请登录"),a.value=!0,s.password="",s.confirmPassword="")}catch(n){w.error(((r=(o=n.response)==null?void 0:o.data)==null?void 0:r.error)||"操作失败")}finally{m.value=!1}}}return(f,e)=>{const o=p("el-input"),r=p("el-form-item"),n=p("el-button"),u=p("el-form");return h(),x("div",N,[d("div",I,[e[4]||(e[4]=d("h1",{class:"login-title"},"CloudSearch 用户中心",-1)),d("p",L,c(a.value?"登录您的账号":"注册新账号"),1),t(u,{ref_key:"formRef",ref:v,model:s,rules:b,"label-width":"0",onKeyup:C(y,["enter"])},{default:l(()=>[t(r,{prop:"account"},{default:l(()=>[t(o,{modelValue:s.account,"onUpdate:modelValue":e[0]||(e[0]=i=>s.account=i),placeholder:"推广平台-手机号（如：蜂小推-13800138000）",size:"large"},null,8,["modelValue"])]),_:1}),t(r,{prop:"password"},{default:l(()=>[t(o,{modelValue:s.password,"onUpdate:modelValue":e[1]||(e[1]=i=>s.password=i),type:"password",placeholder:"密码",size:"large","show-password":""},null,8,["modelValue"])]),_:1}),a.value?P("",!0):(h(),E(r,{key:0,prop:"confirmPassword"},{default:l(()=>[t(o,{modelValue:s.confirmPassword,"onUpdate:modelValue":e[2]||(e[2]=i=>s.confirmPassword=i),type:"password",placeholder:"确认密码",size:"large","show-password":""},null,8,["modelValue"])]),_:1})),t(r,null,{default:l(()=>[t(n,{type:"primary",size:"large",loading:m.value,style:{width:"100%"},onClick:y},{default:l(()=>[_(c(a.value?"登 录":"注 册"),1)]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"]),d("div",R,[_(c(a.value?"还没有账号？":"已有账号？")+" ",1),t(n,{link:"",type:"primary",onClick:e[3]||(e[3]=i=>a.value=!a.value)},{default:l(()=>[_(c(a.value?"立即注册":"去登录"),1)]),_:1})])])])}}}),T=U(A,[["__scopeId","data-v-d9146692"]]);export{T as default};
