Files
qingcheng-xiaochengxu/pages/course/waitPayOrder/waitPayOrder.js
2025-06-25 15:44:12 +08:00

39 lines
880 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Page({
data: {
// 初始倒计时字符串
countdown: '30分00秒'
},
onLoad(options) {
// 启动倒计时(总秒数 = 29*60 + 17
this.initCountdown(30 * 60 );
},
/**
* 初始化倒计时
* @param {number} totalSeconds 初始总秒数
*/
initCountdown(totalSeconds) {
this.countdownTimer = setInterval(() => {
if (totalSeconds <= 0) {
clearInterval(this.countdownTimer);
this.setData({ countdown: '00分00秒' });
return;
}
totalSeconds--;
const m = Math.floor(totalSeconds / 60);
const s = totalSeconds % 60;
const mm = m < 10 ? '0' + m : '' + m;
const ss = s < 10 ? '0' + s : '' + s;
this.setData({ countdown: `${mm}${ss}` });
}, 1000);
},
onUnload() {
// 页面卸载时清除定时器
clearInterval(this.countdownTimer);
}
});