import{C as e,D as t,E as n,M as r,O as i,T as a,_ as o,a as s,b as c,k as l,l as u,m as d,o as f,s as p,v as m,x as h,y as g}from"./index-vhvNh9F8.js";var _={class:`page`},v={class:`login-form`},y={class:`captcha-row`},b=[`innerHTML`],x={class:`sms-row`},S={style:{"text-align":`center`,"margin-top":`16px`}},C=p({__name:`Login`,setup(p){let C=u(),w=t({phone:``,password:``,captchaText:``,captchaId:``,smsCode:``}),T=i(!1),E=i(``),D=i(0),O=null;async function k(){try{let e=await s.get(`/captcha/image`);e.code===0&&(E.value=e.data.svg,w.captchaId=e.data.id)}catch{}}function A(){D.value=60,O&&clearInterval(O),O=setInterval(()=>{D.value--,D.value<=0&&(clearInterval(O),O=null)},1e3)}async function j(){if(!w.phone){alert(`请先输入手机号`);return}if(!w.captchaId||!w.captchaText){alert(`请先输入图形验证码`);return}try{if((await s.post(`/captcha/verify`,{id:w.captchaId,text:w.captchaText})).code!==0){alert(`验证码错误，请重新输入`),k();return}}catch{alert(`验证失败`);return}try{let e=await s.post(`/captcha/sms`,{phone:w.phone});e.code===0?(alert(e.message||`验证码已发送`),A()):alert(e.message||`发送失败`)}catch{alert(`网络错误`)}}async function M(){if(!w.phone||!w.password){alert(`请填写完整信息`);return}T.value=!0;try{if(w.smsCode){let e=await s.post(`/user/sms-login`,{phone:w.phone,sms_code:w.smsCode});e.code===0?(localStorage.setItem(`token`,e.data.token),C.push(`/`)):alert(e.message||`登录失败`)}else{let e=await s.post(`/user/login`,w);e.code===0?(localStorage.setItem(`token`,e.data.token),C.push(`/`)):alert(e.message||`登录失败`)}}catch{alert(`网络错误`)}T.value=!1}return h(()=>{k()}),(t,i)=>{let s=a(`van-field`),u=a(`van-button`);return e(),o(`div`,_,[c(f,{title:`登录`,onBack:i[0]||=e=>l(C).push(`/user`)}),d(`div`,v,[i[7]||=m(`<div class="login-logo" data-v-a71084e2><svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="var(--primary)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" data-v-a71084e2><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z" fill="rgba(108,92,231,.1)" data-v-a71084e2></path></svg><div class="login-title" data-v-a71084e2>欢迎回来</div><div class="login-sub" data-v-a71084e2>登录你的省胜优铺账号</div></div>`,1),c(s,{modelValue:w.phone,"onUpdate:modelValue":i[1]||=e=>w.phone=e,label:`手机号`,placeholder:`请输入手机号`,clearable:``},null,8,[`modelValue`]),c(s,{modelValue:w.password,"onUpdate:modelValue":i[2]||=e=>w.password=e,type:`password`,label:`密码`,placeholder:`请输入密码`},null,8,[`modelValue`]),d(`div`,y,[c(s,{modelValue:w.captchaText,"onUpdate:modelValue":i[3]||=e=>w.captchaText=e,label:`验证码`,placeholder:`输入验证码`,maxlength:`4`},null,8,[`modelValue`]),E.value?(e(),o(`div`,{key:0,class:`captcha-img`,onClick:k,innerHTML:E.value},null,8,b)):(e(),o(`span`,{key:1,class:`captcha-refresh`,onClick:k},`获取验证码`))]),d(`div`,x,[c(s,{modelValue:w.smsCode,"onUpdate:modelValue":i[4]||=e=>w.smsCode=e,label:`短信验证`,placeholder:`输入短信验证码`,maxlength:`6`},null,8,[`modelValue`]),c(u,{round:``,size:`small`,class:`sms-btn`,disabled:D.value>0,onClick:j},{default:n(()=>[g(r(D.value>0?D.value+`s`:`获取验证码`),1)]),_:1},8,[`disabled`])]),c(u,{round:``,block:``,class:`primary-btn`,style:{"margin-top":`24px`,height:`44px`},onClick:M,loading:T.value},{default:n(()=>[...i[6]||=[g(`登 录`,-1)]]),_:1},8,[`loading`]),d(`div`,S,[d(`span`,{class:`register-link`,onClick:i[5]||=e=>l(C).push(`/register`)},`没有账号？去注册`)])])])}}},[[`__scopeId`,`data-v-a71084e2`]]);export{C as default};