//验证码按钮计时器锁定
setInterval() {
var currentTime = this.data.currentTime //把手机号跟倒计时值变例成js值
var promise = new Promise((resolved, rejected) => {
_timer = setInterval(() => {
currentTime–; //每执行一次让倒计时秒数减一
this.setData({
text: currentTime + ‘s’ + ‘后再获取’, //按钮文字变成倒计时对应秒数
});
if (currentTime <= 0) {
clearInterval(_timer);
resolved();
}
}, 1000);
});
return promise;
}
if (res.status == 1) {
wx.showToast({
title: ‘验证码已发送’,
icon: ‘success’,
duration: 2000
});
this.setData({
disable: true, //只要点击了按钮就让按钮禁用 (避免正常情况下多次触发定时器事件)
backgroundColor: ‘#EDEDED’,
color: ‘#B3B3B3’
});
this.setInterval().then(() => {
this.setData({
text: ‘获取验证码’,
currentTime: 60,
disable: false,
color: ‘#fff’
})
});
} else {
helper.errToast(res.code)
}