From 76cd2b6c0f57b74afb1c2c251c047bf42cf43e23 Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Fri, 31 Jul 2026 10:23:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=89=E4=B8=AA=20P2=20=E5=B0=8F?= =?UTF-8?q?=E4=BF=AE(=E6=A6=9C=E5=8D=95=E7=A6=BB=E7=BA=BF=E5=85=9C?= =?UTF-8?q?=E5=BA=95/=E5=90=8C=E5=A4=A9=E8=BF=9E=E8=83=9C=E6=96=87?= =?UTF-8?q?=E6=A1=88/=E7=83=AD=E5=8A=9B=E5=9B=BE=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E8=A7=A3=E6=9E=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - leaderboard.js _applyLocal 离线兜底补 subText(N次),与云端路径对齐 - timer.js _detectCelebrationLevel 增加 lastIsToday 判断,修复同天二次训练连胜文案虚高 1 天 - calendar-heatmap.js 用 util.dateOnly 归一化后再取'日',修复脆弱的 split 解析 --- components/calendar-heatmap/calendar-heatmap.js | 4 +++- pages/leaderboard/leaderboard.js | 3 ++- pages/timer/timer.js | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/components/calendar-heatmap/calendar-heatmap.js b/components/calendar-heatmap/calendar-heatmap.js index 085c237..da68d90 100644 --- a/components/calendar-heatmap/calendar-heatmap.js +++ b/components/calendar-heatmap/calendar-heatmap.js @@ -59,7 +59,9 @@ Component({ const recordMap = {} if (records && records.length) { records.forEach((r) => { - const d = parseInt(r.date.split('-')[2]) + // 先用 util.dateOnly 归一化日期(兼容 "YYYY-MM-DD HH:MM:SS" / ISO 等), + // 再稳定地取出「日」,避免直接 split('-')[2] 取到 "DD HH:MM:SS" 靠 parseInt 侥幸解析的脆弱写法 + const d = parseInt(util.dateOnly(r.date).split('-')[2], 10) recordMap[d] = (recordMap[d] || 0) + r.duration }) } diff --git a/pages/leaderboard/leaderboard.js b/pages/leaderboard/leaderboard.js index 38b8942..fb90bbd 100644 --- a/pages/leaderboard/leaderboard.js +++ b/pages/leaderboard/leaderboard.js @@ -205,7 +205,8 @@ Page({ if (duration > 0) { const entry = { rank: 1, openid: 'local', name: localName, nickname: profile.nickname || '', - duration, durationText: util.formatDuration(duration), sessions + duration, durationText: util.formatDuration(duration), sessions, + subText: `${sessions}次` } this.setData({ rankedList: [entry], myEntry: { ...entry, isMe: true }, loading: false, refreshing: false, empty: false }) } else { diff --git a/pages/timer/timer.js b/pages/timer/timer.js index 8e50cd5..82070fa 100644 --- a/pages/timer/timer.js +++ b/pages/timer/timer.js @@ -244,7 +244,14 @@ Page({ _detectCelebrationLevel(elapsed) { const stats = storage.getTotalStats() const streak = storage.getStreak() - const nextStreak = (streak.lastDate && streak.count >= 1) ? streak.count + 1 : 1 + // 本函数运行在保存记录之前(pre-save state)。updateStreak 对「同一天再次训练」 + // 会直接 return、不递增连胜数;所以若 streak.lastDate 已是今天,nextStreak 应取 + // 当前 count 而非 count+1,否则庆祝文案会比真实连胜多 1 天。 + const todayOnly = storage.getToday().substring(0, 10) + const lastIsToday = !!(streak.lastDate && streak.lastDate.substring(0, 10) === todayOnly) + const nextStreak = lastIsToday + ? (streak.count || 1) + : ((streak.lastDate && streak.count >= 1) ? streak.count + 1 : 1) if (stats.totalSessions === 0) { return { level: 'first', message: '第一次训练!坚持就是胜利' }