// pages/wxbind/wxbind.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { mobile: '', code: '', codeSent: false, countdown: 60, isButtonEnabled: false }, bindMobileInput(e) { this.setData({ mobile: e.detail.value }, this.checkButtonState); }, bindCodeInput(e) { this.setData({ code: e.detail.value }, this.checkButtonState); }, checkButtonState() { const { mobile, code } = this.data; const isButtonEnabled = mobile.length === 11 && code.length == 6; this.setData({ isButtonEnabled }); console.log(isButtonEnabled); }, sendCode: function () { if (!this.data.mobile) { wx.showToast({ title: '请输入手机号', icon: 'none', duration: 2000, }); return; } // 在这里处理发送验证码的逻辑,可以调用后台接口实现 // 以下是一个简单的示例,仅作参考 wx.showToast({ title: '验证码已发送', icon: 'success', duration: 2000, }); this.setData({ codeSent: true, }); // 启动倒计时 this.startCountdown(); }, //倒计时 startCountdown: function () { let that = this; let timer = setInterval(function () { let countdown = that.data.countdown - 1; that.setData({ countdown: countdown, }); if (countdown <= 0) { clearInterval(timer); that.setData({ codeSent: false, countdown: 60, }); } }, 1000); }, bind: function () { if (!this.data.isButtonEnabled) return; wx.showToast({ title: '绑定成功', icon: 'success' }); // 跳转到 TabBar 页面 wx.switchTab({ url: '/pages/home/home' // 这里填写你想要跳转的 TabBar 页面路径 }); }, postCode: function () { post('/items', { name: 'New Item' }) .then((data) => { this.setData({ items: [...this.data.items, data] }); }) .catch((error) => { console.error('Failed to add item:', error); }); } })