import{f as e,g as a,d as l,o as t,c as s,w as n,l as o,t as i,u,e as c,A as r,B as v,C as d,v as f,z as p,i as m}from"./index-CJxdOECQ.js";import{_ as g}from"./input.BkLVqGkG.js";import{r as _,b,_ as h}from"./button.BC3KjxGU.js";import{a as k}from"./api.U2gW6MFc.js";import"./parent-map.DJ2qhm0x.js";const y=h(e({__name:"login",setup(e){const h=a("13777777777"),y=a(""),x=a("one-click"),C=a(!1),j=a(!1),w=a(0),I=a("发送验证码"),z=()=>{x.value="code"===x.value?"one-click":"code"},L=async()=>{if(console.log(h.value),h.value&&11===h.value.length)try{await k.auth.sendCode("+86"+h.value),r({title:"验证码已发送",icon:"success"}),j.value=!0,w.value=60;const e=setInterval((()=>{w.value--,I.value=`${w.value}秒后重发`,w.value<=0&&(clearInterval(e),j.value=!1,I.value="发送验证码")}),1e3)}catch(e){console.error("发送验证码失败",e)}else r({title:"请输入正确的手机号",icon:"none"})},U=async()=>{if(h.value&&11===h.value.length)if(y.value&&6===y.value.length){C.value=!0;try{const e=await k.auth.verificationLogin("+86"+h.value,y.value);v("token",e.token),v("user",e.user),r({title:"登录成功",icon:"success"}),d({url:"/pages/index/index"})}catch(e){console.error("登录失败",e)}finally{C.value=!1}}else r({title:"请输入验证码",icon:"none"});else r({title:"请输入正确的手机号",icon:"none"})},A=async()=>{if(h.value&&11===h.value.length){C.value=!0;try{const e=await k.auth.oneClickLogin("+86"+h.value);v("token",e.token),v("user",e.user),r({title:"登录成功",icon:"success"}),d({url:"/pages/index/index"})}catch(e){console.error("登录失败",e)}finally{C.value=!1}}else r({title:"请输入正确的手机号",icon:"none"})},B=()=>{f({url:"/pages/register/register"})};return(e,a)=>{const r=p,v=m,d=_(l("t-input"),g),f=_(l("t-button"),b);return t(),s(v,{class:"login-container"},{default:n((()=>[o(v,{class:"login-header"},{default:n((()=>[o(r,{class:"title"},{default:n((()=>[i("欢迎使用预约系统")])),_:1}),o(r,{class:"subtitle"},{default:n((()=>[i("请登录或注册")])),_:1})])),_:1}),o(v,{class:"login-form"},{default:n((()=>[o(v,{class:"form-item"},{default:n((()=>[o(d,{value:h.value,"onUpdate:value":a[0]||(a[0]=e=>h.value=e),placeholder:"请输入手机号",type:"number",maxlength:11,clearable:""},{prefixIcon:n((()=>[o(r,{class:"prefix-icon"},{default:n((()=>[i("📱")])),_:1})])),_:1},8,["value"])])),_:1}),"code"===x.value?(t(),s(v,{key:0,class:"form-item"},{default:n((()=>[o(d,{value:y.value,"onUpdate:value":a[1]||(a[1]=e=>y.value=e),placeholder:"请输入验证码",type:"number",maxlength:6,clearable:""},{prefixIcon:n((()=>[o(r,{class:"prefix-icon"},{default:n((()=>[i("🔐")])),_:1})])),suffix:n((()=>[o(f,{size:"small",variant:"text",disabled:j.value,onClick:L},{default:n((()=>[i(u(I.value),1)])),_:1},8,["disabled"])])),_:1},8,["value"])])),_:1})):c("",!0),o(v,{class:"form-actions"},{default:n((()=>["code"===x.value?(t(),s(f,{key:0,"t-class":"btn-primary",theme:"primary",size:"large",block:"",loading:C.value,onClick:U},{default:n((()=>[i(" 验证码登录 ")])),_:1},8,["loading"])):(t(),s(f,{key:1,"t-class":"btn-primary",theme:"primary",size:"large",block:"",loading:C.value,onClick:A},{default:n((()=>[i(" 一键登录 ")])),_:1},8,["loading"]))])),_:1}),o(v,{class:"form-switch"},{default:n((()=>[o(r,{onClick:z},{default:n((()=>[i(u("code"===x.value?"使用一键登录":"使用验证码登录"),1)])),_:1}),o(r,{class:"register-link",onClick:B},{default:n((()=>[i("注册新账号")])),_:1})])),_:1})])),_:1})])),_:1})}}}),[["__scopeId","data-v-ba5c5b6b"]]);export{y as default};
