feat: timer 页面接入 countUp 数字滚动 (load 时 0→duration)

This commit is contained in:
2026-07-08 11:37:13 +08:00
parent c3be8450aa
commit 5d810fd058
+22 -1
View File
@@ -4,13 +4,14 @@ const planMod = require('../../utils/plan')
const themeMod = require('../../utils/theme') const themeMod = require('../../utils/theme')
const iconsMod = require('../../utils/icons') const iconsMod = require('../../utils/icons')
const voice = require('../../utils/voice') const voice = require('../../utils/voice')
const { countUp } = require('../../utils/countUp')
Page({ Page({
data: { data: {
theme: { primary: '#FF6B35', primaryLight: '#FF8C5A', primaryBg: '#FFF3ED', primaryRgb: '255,107,53' }, theme: { primary: '#FF6B35', primaryLight: '#FF8C5A', primaryBg: '#FFF3ED', primaryRgb: '255,107,53' },
themeStyle: themeMod.BASE_VARS, themeStyle: themeMod.BASE_VARS,
duration: 60, duration: 60,
remaining: 60, remaining: 0,
status: 'idle', status: 'idle',
isRunning: false, isRunning: false,
isPaused: false, isPaused: false,
@@ -25,6 +26,16 @@ Page({
onLoad(options) { onLoad(options) {
themeMod.applyThemeToPage(this) themeMod.applyThemeToPage(this)
this._init(options) this._init(options)
// countUp: 数字从 0 滚到目标秒数
const target = this.data.duration
if (this._countUpTask) this._countUpTask.cancel()
this._countUpTask = countUp({
from: 0,
to: target,
duration: 600,
onUpdate: (v) => this.setData({ remaining: v }),
onComplete: () => { this._countUpTask = null }
})
}, },
onShow() { onShow() {
@@ -158,6 +169,10 @@ Page({
this._timer.stop() this._timer.stop()
this._timer = null this._timer = null
} }
if (this._countUpTask) {
this._countUpTask.cancel()
this._countUpTask = null
}
}, },
onStart() { onStart() {
@@ -167,6 +182,12 @@ Page({
return return
} }
if (this.data.isRunning) return if (this.data.isRunning) return
// 取消可能还在滚的 countUp,确保 remaining = duration
if (this._countUpTask) {
this._countUpTask.cancel()
this._countUpTask = null
this.setData({ remaining: this.data.duration })
}
this._timer.start(this.data.duration) this._timer.start(this.data.duration)
this.setData({ isRunning: true, status: 'running' }) this.setData({ isRunning: true, status: 'running' })
const s = storage.getSettings() const s = storage.getSettings()