feat: v1.5 — plan editor, voice prompts, UI polish

Major features:
- Training plan editor: edit preset days/duration per plan (in-place
  override via custom_plans storage; preset ids preserved so existing
  records stay valid)
- Voice prompts at 4 fixed points during training (halfway / 30s /
  10s / done) via Tencent Cloud TTS (cloudfunctions/tts + utils/voice.js)
- Free-training button: switched from outline (transparent) to ghost
  variant (theme-tinted) for visual weight

Bug fixes:
- 4 functional pages: SVG data URIs failed to render in WeChat because
  '\#' in colors was parsed as a data-URI fragment delimiter. encode the
  whole SVG via encodeURIComponent in utils/icons.js build().
- Old records (saved before id field was added) could not be deleted
  (data-id was empty, triggered defensive guard). Backfill stable
  legacy-<month>-<index>-<duration> ids in getRecords() and persist.
- settings.js plan-row editor button event was bubbling up to the row's
  bindtap (which also fired onSelectPlan). Wrapped in catch:tap.

UI:
- Settings page: 3 hardcoded plans replaced with dynamic buildPlansList
  that overlays custom_plans on top of presets
- Plan editor: bottom-sheet modal in settings page (regular view, not
  ui-modal — WeChat custom component root element drops position:fixed
  in this runtime)
- Free-training button: rounded pill style, full-width, 24rpx gap from
  primary action; bottom sheet uses max-height: 88vh + internal scroll
- Version bumped to v1.5, last updated 2026-06-10

Removed:
- Daily reminder section (dailyReminder / reminderTime) — replaced by
  the 4 voice prompts which cover the same user need without requiring
  long-term scheduling that WeChat mini-programs can't actually do

Misc:
- utils/plan.js refactored to formula-driven: presets declare
  totalDays/startTarget/increment/cycleDays, days[] is generated. Same
  formula applies to custom plans.
- Timer _remind() guards each prompt on minimum duration so short
  free-mode sessions don't fire 'last30' at the start
- Cloud storage cloud_plans field added to data push payload; restored
  on first install via _restoreFromCloud
- .gitignore added for local AI tool caches (.reasonix/, reasonix.toml,
  .codegraph/daemon.pid)
This commit is contained in:
2026-06-10 17:23:13 +08:00
parent 90e0e64156
commit 1d55df72b3
54 changed files with 2710 additions and 934 deletions
+96 -8
View File
@@ -2,6 +2,8 @@ const Timer = require('../../utils/timer')
const storage = require('../../utils/storage')
const planMod = require('../../utils/plan')
const themeMod = require('../../utils/theme')
const iconsMod = require('../../utils/icons')
const voice = require('../../utils/voice')
Page({
data: {
@@ -16,7 +18,8 @@ Page({
overtime: 0,
todayTarget: 0,
planDay: 1,
isFreeMode: false
isFreeMode: false,
icons: iconsMod.build()
},
onLoad(options) {
@@ -26,22 +29,25 @@ Page({
onShow() {
themeMod.applyThemeToPage(this)
const theme = themeMod.getCurrentTheme()
this.setData({ theme, icons: iconsMod.build(theme) })
},
_init(options) {
let target
let planDay = 1
let isFreeMode = false
if (options && options.free) {
target = parseInt(options.free) || 60
const parsed = parseInt(options.free)
target = parsed > 0 ? parsed : 60
isFreeMode = true
} else {
const settings = storage.getSettings()
const allRecords = Object.values(storage.getRecords()).flat()
const plan = planMod.getPlan(settings.planId)
planDay = planMod.getPlanDay(settings.planId, allRecords)
const customPlans = storage.getCustomPlans()
const plan = planMod.getPlan(settings.planId, customPlans)
planDay = planMod.getPlanDay(settings.planId, allRecords, settings.planStartDate)
target = planMod.getTodayTarget(settings.planId, Math.min(planDay, plan.totalDays))
}
@@ -53,25 +59,101 @@ Page({
isFreeMode
})
if (this._timer) {
this._timer.stop()
this._timer = null
}
// Reset reminder state
this._halfwaySignaled = false
this._lastMinuteAt = 0
this._lastCountdown = 0
this._timer = new Timer({
onTick: (tick) => {
this.setData({
remaining: tick.remaining > 0 ? tick.remaining : 0,
overtime: tick.remaining <= 0 ? tick.elapsed - this.data.duration : 0
})
this._remind(tick)
},
onComplete: () => {
this.setData({ status: 'completed', isCompleted: true })
if (storage.getSettings().vibrate) {
const s = storage.getSettings()
if (s.vibrate) {
try { wx.vibrateLong() } catch (e) {}
}
// 4th voice prompt: completion
if (s.voiceGuide !== false) {
voice.play('complete')
}
wx.showToast({ title: '目标完成! 太棒了!', icon: 'success', duration: 2000 })
}
})
},
/**
* Per-tick reminders: vibration + voice prompts at 4 fixed points.
* - halfway: once when elapsed reaches half of duration
* - 30s: once when remaining hits 30
* - 10s: once when remaining hits 10
* - complete: fired in onComplete above
*
* Vibration and voice are independently gated by `vibrate` / `voiceGuide`
* settings — user can mute haptics but keep voice (e.g. in office) or vice versa.
*/
_remind(tick) {
const s = storage.getSettings()
const { remaining, elapsed, duration } = tick
const vibrate = (n, ms) => {
if (!s.vibrate) return
try {
for (let i = 0; i < n; i++) {
setTimeout(() => wx.vibrateShort(), i * (ms + 30))
}
} catch (e) {}
}
// Each prompt is gated on a minimum duration so short free-mode
// trainings don't trigger them at nonsensical times (e.g. firing
// "最后30秒" on the first tick of a 30s session because remaining
// happens to equal 30 at elapsed=0).
//
// Thresholds chosen so prompts fire in the right ORDER for any
// duration: halfway first, then last30, then last10.
// 1. Halfway: needs >=10s total so the midpoint is at least 5s in
if (duration >= 10 && !this._halfwaySignaled && elapsed >= Math.floor(duration / 2)) {
this._halfwaySignaled = true
if (s.voiceGuide !== false) voice.play('halfway')
vibrate(2, 150)
}
// 2. Last 30 seconds: only if duration > 60s so halfway has already passed
if (duration > 60 && remaining === 30 && !this._last30Signaled) {
this._last30Signaled = true
if (s.voiceGuide !== false) voice.play('last30')
}
// 3. Last 10 seconds: only if duration > 20s so we have at least 10s of training
if (duration > 20 && remaining === 10 && !this._last10Signaled) {
this._last10Signaled = true
if (s.voiceGuide !== false) voice.play('last10')
}
// 4. Countdown buzzes at 5..1: only if duration >= 6s (so we can reach them)
if (duration >= 6 && remaining <= 5 && remaining > 0 && remaining !== this._lastCountdown) {
this._lastCountdown = remaining
vibrate(1, 100)
}
},
onUnload() {
if (this._timer) this._timer.stop()
voice.stop()
if (this._timer) {
this._timer.stop()
this._timer = null
}
},
onStart() {
@@ -88,6 +170,7 @@ Page({
onPause() {
if (!this.data.isRunning || this.data.isPaused) return
this._timer.pause()
voice.stop()
this.setData({ isPaused: true, status: 'paused' })
},
@@ -103,6 +186,11 @@ Page({
finishTraining() {
const elapsed = this._timer.stop()
if (elapsed < 3) {
wx.showToast({ title: '训练时间太短', icon: 'none', duration: 1500 })
setTimeout(() => { wx.navigateBack() }, 1500)
return
}
const today = storage.getToday()
storage.saveRecord({
date: today,
@@ -113,6 +201,6 @@ Page({
storage.updateStreak(today)
wx.showToast({ title: `已记录 ${elapsed}`, icon: 'none', duration: 1500 })
setTimeout(() => { wx.navigateBack() }, 3000)
setTimeout(() => { wx.navigateBack() }, 1500)
}
})
+2 -1
View File
@@ -1,6 +1,7 @@
{
"usingComponents": {
"progress-ring": "../../components/progress-ring/progress-ring"
"progress-ring": "/components/progress-ring/progress-ring",
"ui-btn": "/components/ui-btn/ui-btn"
},
"navigationBarTitleText": "训练中"
}
+33 -27
View File
@@ -30,7 +30,7 @@
</view>
<view class="overtime-badge" wx:if="{{isCompleted && overtime > 0}}">
<text class="overtime-icon">🔥</text>
<image class="overtime-icon" src="{{icons.hotFill}}" mode="aspectFit"></image>
<text>+{{overtime}}s</text>
</view>
</view>
@@ -38,58 +38,64 @@
<!-- 状态提示 -->
<view class="hint-section">
<view class="hint-row" wx:if="{{status === 'idle'}}">
<text class="hint-emoji">🧘</text>
<image class="hint-icon" src="{{icons.targetFill}}" mode="aspectFit"></image>
<text class="hint-text">
<block wx:if="{{isFreeMode}}">自由训练 · 目标 {{duration}} 秒</block>
<block wx:else>今日目标 {{duration}} 秒 · 第 {{planDay}} 天</block>
</text>
</view>
<view class="hint-row" wx:elif="{{status === 'running'}}">
<text class="hint-emoji running-pulse">💪</text>
<image class="hint-icon running-pulse" src="{{icons.likeFill}}" mode="aspectFit"></image>
<text class="hint-text running">保持姿势,核心收紧!</text>
</view>
<view class="hint-row" wx:elif="{{status === 'paused'}}">
<text class="hint-emoji"></text>
<image class="hint-icon" src="{{icons.notificationForbidFill}}" mode="aspectFit"></image>
<text class="hint-text paused">已暂停</text>
</view>
<view class="hint-row completed-hint" wx:elif="{{status === 'completed'}}">
<text class="hint-emoji completed-bounce">🎉</text>
<image class="hint-icon completed-bounce" src="{{icons.roundCheckFill}}" mode="aspectFit"></image>
<text class="hint-text completed">目标完成! 继续坚持!</text>
</view>
</view>
<!-- 控制按钮 -->
<view class="controls">
<button
<ui-btn
wx:if="{{!isRunning && !isPaused}}"
class="ctrl-btn start-btn"
variant="primary"
size="xl"
block
text="开始"
icon-src="{{icons.playFill}}"
bindtap="onStart"
>
<text class="ctrl-icon">▶</text>
<text>开始</text>
</button>
></ui-btn>
<view class="ctrl-row" wx:if="{{isRunning || isPaused}}">
<button
<ui-btn
wx:if="{{!isPaused}}"
class="ctrl-btn pause-btn"
variant="ghost"
size="xl"
text="暂停"
icon-src="{{icons.notificationForbidFill}}"
custom-style="margin-right: 28rpx;"
bindtap="onPause"
>
<text class="ctrl-icon">⏸</text>
<text>暂停</text>
</button>
<button
></ui-btn>
<ui-btn
wx:if="{{isPaused}}"
class="ctrl-btn resume-btn"
variant="primary"
size="xl"
text="继续"
icon-src="{{icons.playFill}}"
custom-style="margin-right: 28rpx;"
bindtap="onStart"
>
<text class="ctrl-icon">▶</text>
<text>继续</text>
</button>
<button class="ctrl-btn stop-btn" bindtap="onStop">
<text class="ctrl-icon">⏹</text>
<text>结束</text>
</button>
></ui-btn>
<ui-btn
variant="outline"
size="xl"
text="结束"
icon-src="{{icons.stop}}"
bindtap="onStop"
></ui-btn>
</view>
</view>
</view>
+20 -124
View File
@@ -27,46 +27,14 @@
z-index: 0;
}
.breathe-ring-1 {
width: 480rpx;
height: 480rpx;
animation-delay: 0s;
}
.breathe-ring-1 { width: 480rpx; height: 480rpx; animation-delay: 0s; }
.breathe-ring-2 { width: 400rpx; height: 400rpx; animation-delay: 0.5s; border-color: rgba(var(--primary-rgb), 0.25); border-width: 4rpx; }
.breathe-ring-3 { width: 320rpx; height: 320rpx; animation-delay: 1s; border-color: rgba(var(--primary-rgb), 0.35); border-width: 5rpx; }
.breathe-ring-2 {
width: 400rpx;
height: 400rpx;
animation-delay: 0.5s;
border-color: rgba(var(--primary-rgb), 0.25);
border-width: 4rpx;
}
.breathe-ring-3 {
width: 320rpx;
height: 320rpx;
animation-delay: 1s;
border-color: rgba(var(--primary-rgb), 0.35);
border-width: 5rpx;
}
.breathe-ring.fast {
animation: breathePulseFast 1.4s ease-in-out infinite;
}
.breathe-ring.fast.breathe-ring-1 {
animation-delay: 0s;
border-color: rgba(var(--primary-rgb), 0.3);
}
.breathe-ring.fast.breathe-ring-2 {
animation-delay: 0.25s;
border-color: rgba(var(--primary-rgb), 0.45);
}
.breathe-ring.fast.breathe-ring-3 {
animation-delay: 0.5s;
border-color: rgba(var(--primary-rgb), 0.6);
}
.breathe-ring.fast { animation: breathePulseFast 1.4s ease-in-out infinite; }
.breathe-ring.fast.breathe-ring-1 { animation-delay: 0s; border-color: rgba(var(--primary-rgb), 0.3); }
.breathe-ring.fast.breathe-ring-2 { animation-delay: 0.25s; border-color: rgba(var(--primary-rgb), 0.45); }
.breathe-ring.fast.breathe-ring-3 { animation-delay: 0.5s; border-color: rgba(var(--primary-rgb), 0.6); }
/* celebration burst */
.celebrate-burst {
@@ -91,18 +59,9 @@
.s6 { top: -20rpx; left: 40rpx; animation-delay: 0.05s; }
@keyframes sparkBurst {
0% {
opacity: 0;
transform: translate(0, 0) scale(0.3);
}
40% {
opacity: 1;
transform: translate(0, -30rpx) scale(1.3);
}
100% {
opacity: 0;
transform: translate(0, -80rpx) scale(0.4);
}
0% { opacity: 0; transform: translate(0, 0) scale(0.3); }
40% { opacity: 1; transform: translate(0, -30rpx) scale(1.3); }
100% { opacity: 0; transform: translate(0, -80rpx) scale(0.4); }
}
/* overtime badge */
@@ -125,8 +84,8 @@
}
.overtime-icon {
font-size: 28rpx;
line-height: 1;
width: 28rpx;
height: 28rpx;
}
/* ---- hint section ---- */
@@ -142,9 +101,9 @@
gap: 10rpx;
}
.hint-emoji {
font-size: 28rpx;
line-height: 1;
.hint-icon {
width: 32rpx;
height: 32rpx;
}
.running-pulse {
@@ -161,23 +120,11 @@
line-height: 1.3;
}
.hint-text.running {
color: var(--primary);
font-weight: 600;
}
.hint-text.running { color: var(--primary); font-weight: 600; }
.hint-text.paused { color: var(--primary-light); }
.hint-text.completed { color: var(--success); font-weight: 600; }
.hint-text.paused {
color: var(--primary-light);
}
.hint-text.completed {
color: var(--success);
font-weight: 600;
}
.completed-hint {
animation: popIn 0.5s ease;
}
.completed-hint { animation: popIn 0.5s ease; }
/* ---- controls ---- */
.controls {
@@ -187,59 +134,8 @@
justify-content: center;
}
.ctrl-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 12rpx;
width: 300rpx;
height: 108rpx;
border-radius: 54rpx;
font-size: 36rpx;
font-weight: 600;
text-align: center;
border: none;
padding: 0;
}
.ctrl-btn:active {
transform: scale(0.94);
}
.ctrl-btn::after {
border: none;
}
.ctrl-icon {
font-size: 32rpx;
line-height: 1;
}
.start-btn {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: #fff;
box-shadow: 0 8rpx 28rpx rgba(var(--primary-rgb), 0.35);
}
.pause-btn {
background: var(--primary-bg);
color: var(--primary);
margin-right: 28rpx;
}
.resume-btn {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: #fff;
margin-right: 28rpx;
box-shadow: 0 8rpx 28rpx rgba(var(--primary-rgb), 0.35);
}
.stop-btn {
background: #F5F5F5;
color: var(--text-secondary);
}
.ctrl-row {
display: flex;
justify-content: center;
align-items: center;
}