"use strict";const e=require("../../common/vendor.js"),a=require("../../utils/api.js");if(!Array){(e.resolveComponent("t-input")+e.resolveComponent("t-button"))()}Math||((()=>"../../uni_modules/tdesign-uniapp/components/input/input.js")+(()=>"../../uni_modules/tdesign-uniapp/components/button/button.js"))();const n=e.defineComponent({__name:"login",setup(n){const t=e.ref("13777777777"),l=e.ref(""),o=e.ref("one-click"),i=e.ref(!1),s=e.ref(!1),u=e.ref(0),r=e.ref("发送验证码"),c=()=>{o.value="code"===o.value?"one-click":"code"},v=async()=>{if(console.log(t.value),t.value&&11===t.value.length)try{await a.api.auth.sendCode("+86"+t.value),e.index.showToast({title:"验证码已发送",icon:"success"}),s.value=!0,u.value=60;const n=setInterval((()=>{u.value--,r.value=`${u.value}秒后重发`,u.value<=0&&(clearInterval(n),s.value=!1,r.value="发送验证码")}),1e3)}catch(n){console.error("发送验证码失败",n)}else e.index.showToast({title:"请输入正确的手机号",icon:"none"})},d=async()=>{if(t.value&&11===t.value.length)if(l.value&&6===l.value.length){i.value=!0;try{const n=await a.api.auth.verificationLogin("+86"+t.value,l.value);e.index.setStorageSync("token",n.token),e.index.setStorageSync("user",n.user),e.index.showToast({title:"登录成功",icon:"success"}),e.index.reLaunch({url:"/pages/index/index"})}catch(n){console.error("登录失败",n)}finally{i.value=!1}}else e.index.showToast({title:"请输入验证码",icon:"none"});else e.index.showToast({title:"请输入正确的手机号",icon:"none"})},p=async()=>{if(t.value&&11===t.value.length){i.value=!0;try{const n=await a.api.auth.oneClickLogin("+86"+t.value);e.index.setStorageSync("token",n.token),e.index.setStorageSync("user",n.user),e.index.showToast({title:"登录成功",icon:"success"}),e.index.reLaunch({url:"/pages/index/index"})}catch(n){console.error("登录失败",n)}finally{i.value=!1}}else e.index.showToast({title:"请输入正确的手机号",icon:"none"})},g=()=>{e.index.navigateTo({url:"/pages/register/register"})};return(a,n)=>e.e({a:e.o((e=>t.value=e)),b:e.p({placeholder:"请输入手机号",type:"number",maxlength:11,clearable:!0,value:t.value}),c:"code"===o.value},"code"===o.value?{d:e.t(r.value),e:e.o(v),f:e.p({size:"small",variant:"text",disabled:s.value}),g:e.o((e=>l.value=e)),h:e.p({placeholder:"请输入验证码",type:"number",maxlength:6,clearable:!0,value:l.value})}:{},{i:"code"===o.value},"code"===o.value?{j:e.o(d),k:e.p({"t-class":"btn-primary",theme:"primary",size:"large",block:!0,loading:i.value})}:{l:e.o(p),m:e.p({"t-class":"btn-primary",theme:"primary",size:"large",block:!0,loading:i.value})},{n:e.t("code"===o.value?"使用一键登录":"使用验证码登录"),o:e.o(c),p:e.o(g)})}}),t=e._export_sfc(n,[["__scopeId","data-v-7d771541"]]);wx.createPage(t);
