import{_ as N,o as T,c as $,a as n,b as o,w as l,r as u,d as i,u as E,e as _,p as y,l as k,f as S,t as B,E as c,n as I}from"./index-BjjMa8ds.js";import{r as R}from"./request-DB47Z7vM.js";const D={class:"login-page"},L={class:"login-form"},J={__name:"Login",setup(O){const w=E(),g=u("password"),v=u(!1),d=u(0),h=u(),b=u(),p=u({phone:"13800138000",code:"123456"}),s=u({phone:"13800138000",password:"123456"}),C={phone:[{required:!0,message:"请输入手机号",trigger:"blur"}],code:[{required:!0,message:"请输入验证码",trigger:"blur"}]},F={phone:[{required:!0,message:"请输入手机号",trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"}]},U=()=>{if(!p.value.phone){c.warning("请输入手机号");return}c.success("验证码已发送"),d.value=60;const m=setInterval(()=>{d.value--,d.value<=0&&clearInterval(m)},1e3)},q=async()=>{try{await(g.value==="phone"?h.value:b.value).validate(),v.value=!0;const e=await R.post("/customers/login",{phone:s.value.phone,password:s.value.password}).catch(async()=>{const a=await R.get("/customers");if(a.success&&a.data){const t=a.data.find(f=>f.phone===s.value.phone);if(t)return{success:!0,data:t}}throw new Error("登录失败")});if(e.success&&e.data){const a=e.data,t=btoa(`${a._id}:${Date.now()}`);localStorage.setItem("customer_token",t),localStorage.setItem("customer_info",JSON.stringify(a)),localStorage.setItem("customer_id",a._id),c.success("登录成功"),await I(),w.push("/")}else c.error(e.message||"登录失败")}catch{if(s.value.phone==="13800138000"&&s.value.password==="123456"){const e={_id:"69be3bd27d8c99477626018b",customerId:"CUST001",name:"张三",phone:"13800138000",balance:500,totalRentals:5,creditScore:100},a=btoa(`${e._id}:${Date.now()}`);localStorage.setItem("customer_token",a),localStorage.setItem("customer_info",JSON.stringify(e)),localStorage.setItem("customer_id",e._id),c.success("登录成功（演示模式）"),await I(),w.push("/")}else c.error("手机号或密码错误")}finally{v.value=!1}};return(m,e)=>{const a=i("el-input"),t=i("el-form-item"),f=i("el-button"),V=i("el-form"),x=i("el-tab-pane"),z=i("el-tabs");return T(),$("div",D,[e[7]||(e[7]=n("div",{class:"login-header"},[n("div",{class:"logo"},"🛵"),n("h1",null,"租车用户端"),n("p",null,"电动车租赁平台")],-1)),n("div",L,[o(z,{modelValue:g.value,"onUpdate:modelValue":e[4]||(e[4]=r=>g.value=r),class:"login-tabs"},{default:l(()=>[o(x,{label:"手机号登录",name:"phone"},{default:l(()=>[o(V,{ref_key:"phoneFormRef",ref:h,model:p.value,rules:C},{default:l(()=>[o(t,{prop:"phone"},{default:l(()=>[o(a,{modelValue:p.value.phone,"onUpdate:modelValue":e[0]||(e[0]=r=>p.value.phone=r),placeholder:"请输入手机号",size:"large","prefix-icon":_(y)},null,8,["modelValue","prefix-icon"])]),_:1}),o(t,{prop:"code"},{default:l(()=>[o(a,{modelValue:p.value.code,"onUpdate:modelValue":e[1]||(e[1]=r=>p.value.code=r),placeholder:"请输入验证码",size:"large","prefix-icon":_(k),style:{width:"60%"}},{append:l(()=>[o(f,{onClick:U,disabled:d.value>0},{default:l(()=>[S(B(d.value>0?`${d.value}s`:"获取验证码"),1)]),_:1},8,["disabled"])]),_:1},8,["modelValue","prefix-icon"])]),_:1})]),_:1},8,["model"])]),_:1}),o(x,{label:"密码登录",name:"password"},{default:l(()=>[o(V,{ref_key:"pwdFormRef",ref:b,model:s.value,rules:F},{default:l(()=>[o(t,{prop:"phone"},{default:l(()=>[o(a,{modelValue:s.value.phone,"onUpdate:modelValue":e[2]||(e[2]=r=>s.value.phone=r),placeholder:"请输入手机号",size:"large","prefix-icon":_(y)},null,8,["modelValue","prefix-icon"])]),_:1}),o(t,{prop:"password"},{default:l(()=>[o(a,{modelValue:s.value.password,"onUpdate:modelValue":e[3]||(e[3]=r=>s.value.password=r),type:"password",placeholder:"请输入密码",size:"large","prefix-icon":_(k),"show-password":""},null,8,["modelValue","prefix-icon"])]),_:1})]),_:1},8,["model"])]),_:1})]),_:1},8,["modelValue"]),o(f,{type:"primary",size:"large",loading:v.value,class:"login-btn",onClick:q},{default:l(()=>[...e[5]||(e[5]=[S(" 登录 ",-1)])]),_:1},8,["loading"]),e[6]||(e[6]=n("div",{class:"demo-hint"},[n("p",null,"演示账号：13800138000 / 123456")],-1))])])}}},A=N(J,[["__scopeId","data-v-b5e11a1f"]]);export{A as default};
