// 倒计时
export function TimerEnd (elm, iNum) {
this.init(elm, iNum)
}
TimerEnd.prototype = {
init: function (obj, iNum) {
setTimeout(() => {
this.oSecond = document.getElementById(obj)
removeClass(this.oSecond, 'btn-red')
this.oSecond.innerText = '60秒后重发'
this.timer = null
this.iSecond = 60
if (!this.oSecond) return
this.interval(iNum)
}, 0)
return this
},
interval: function (iNum) {
var isec = iNum || this.iSecond
addClass(this.oSecond, 'disabled')
this.timer = setInterval(() => {
this.oSecond.innerText =
isec <= 10 ? '0' + --isec + '秒后重发' : --isec + '秒后重发'
if (isec <= 0) {
clearInterval(this.timer)
removeClass(this.oSecond, 'disabled')
addClass(this.oSecond, 'btn-red')
this.oSecond.innerText = '重新获取'
}
}, 1000)
},
clearTimer: function () {
this.timer && clearInterval(this.timer)
}
}
网友评论