feat(timer): 训练到目标时长不再自动结束,支持超长发挥

- Timer: 到时间触发 onGoalReached(提示)而非自动结束,elapsed/overtime
  继续累加直到用户手动停止
- timer: onGoalReached 播 goal 语音 + goalReached 状态;finishTraining
  补 complete 语音;完成弹窗显示"超长发挥 +X 秒"
- wxml: 超时 badge 训练中也显示;新增 goalReached hint 分支
- voice/tts: 新增 goal 语音 prompt(需部署 tts 云函数)
- config: 版本号 v2.5 -> v2.6

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 09:37:32 +08:00
parent 6fffc5aece
commit dd9cd1859c
6 changed files with 42 additions and 27 deletions
+10 -7
View File
@@ -1,7 +1,7 @@
class Timer {
constructor(options = {}) {
this.onTick = options.onTick || (() => {})
this.onComplete = options.onComplete || (() => {})
this.onGoalReached = options.onGoalReached || (() => {})
this._duration = 0
this._remaining = 0
@@ -11,7 +11,7 @@ class Timer {
this._intervalId = null
this._running = false
this._paused = false
this._completed = false
this._goalReached = false
this._appShowBound = false
// WeChat freezes setInterval while the mini-program is in background.
@@ -29,7 +29,7 @@ class Timer {
this._duration = duration
this._remaining = duration
this._elapsed = 0
this._completed = false
this._goalReached = false
this._running = true
this._paused = false
this._startTime = Date.now()
@@ -81,15 +81,18 @@ class Timer {
duration: this._duration
})
if (this._remaining <= 0 && !this._completed) {
this._completed = true
this.onComplete({ elapsed: this._elapsed, duration: this._duration })
// Goal reached: fire once but DON'T stop - the user keeps training past
// the target until they manually end. elapsed keeps climbing, so
// overtime (elapsed - duration) grows and the UI shows the surplus.
if (this._remaining <= 0 && !this._goalReached) {
this._goalReached = true
this.onGoalReached({ elapsed: this._elapsed, duration: this._duration })
}
}
get isRunning() { return this._running && !this._paused }
get isPaused() { return this._paused }
get isCompleted() { return this._completed }
get isGoalReached() { return this._goalReached }
get remaining() { return this._remaining }
get elapsed() { return this._elapsed }
}
+1
View File
@@ -22,6 +22,7 @@ const PROMPTS = {
halfway: '已完成一半啦,坚持就是胜利!',
last30: '最后30秒,保持呼吸,稳住姿势!',
last10: '最后10秒,再加把劲!',
goal: '目标达成,继续挑战!',
complete: '太棒了!今天的目标已完成,继续加油!'
}