feat: timer 页面接入 countUp 数字滚动 (load 时 0→duration)
This commit is contained in:
+22
-1
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user