const app = getApp(); let timer = null as null | number; Page({ data: { mobile: "", code: "", codeText: "发送验证码", }, onLoad() {}, getCode() { if (timer) return; const mobile = this.data.mobile; if (!mobile) { wx.showToast({ title: "手机号不能为空", icon: "none", }); return; } // 验证手机号 if (!/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(mobile)) { wx.showToast({ title: "手机号格式不正确", icon: "none", }); return; } wx.ajax({ method: "POST", url: "?r=zd/login/send-verify-code", data: { mobile, }, }).then((res) => { console.log(res); wx.showToast({ icon: "none", title: "验证码已发送~", }); let time = 60; timer = setInterval(() => { time--; this.setData({ codeText: time + "s后重新发送", }); if (time <= 0) { clearInterval(timer as number); timer = null; this.setData({ codeText: "发送验证码", }); } }, 1000); }); }, handleSubmit() { const { mobile, code } = this.data; const { registrationSource, registChannel, regBusinessId } = app.globalData; wx.ajax({ method: "POST", url: "?r=zd/login/change-user-login", data: { mobile, code, registrationSource, registChannel, regBusinessId, }, }) .then((res) => { console.log(res); wx.reLaunch({ url: "/patient/pages/index/index", }); }) .catch((err) => { wx.showToast({ title: err.data.msg, icon: "none", duration: 3000, }); }); }, handleBack() { wx.navigateBack(); }, });