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: '第一次训练!坚持就是胜利' }