From 5d810fd058f3c6878490720abfa8cc4fa779b90b Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Wed, 8 Jul 2026 11:37:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20timer=20=E9=A1=B5=E9=9D=A2=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=20countUp=20=E6=95=B0=E5=AD=97=E6=BB=9A=E5=8A=A8=20(l?= =?UTF-8?q?oad=20=E6=97=B6=200=E2=86=92duration)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/timer/timer.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pages/timer/timer.js b/pages/timer/timer.js index 1ed775a..da5ff6c 100644 --- a/pages/timer/timer.js +++ b/pages/timer/timer.js @@ -4,13 +4,14 @@ const planMod = require('../../utils/plan') const themeMod = require('../../utils/theme') const iconsMod = require('../../utils/icons') const voice = require('../../utils/voice') +const { countUp } = require('../../utils/countUp') Page({ data: { theme: { primary: '#FF6B35', primaryLight: '#FF8C5A', primaryBg: '#FFF3ED', primaryRgb: '255,107,53' }, themeStyle: themeMod.BASE_VARS, duration: 60, - remaining: 60, + remaining: 0, status: 'idle', isRunning: false, isPaused: false, @@ -25,6 +26,16 @@ Page({ onLoad(options) { themeMod.applyThemeToPage(this) 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() { @@ -158,6 +169,10 @@ Page({ this._timer.stop() this._timer = null } + if (this._countUpTask) { + this._countUpTask.cancel() + this._countUpTask = null + } }, onStart() { @@ -167,6 +182,12 @@ Page({ 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.setData({ isRunning: true, status: 'running' }) const s = storage.getSettings()