fix: 三个 P2 小修(榜单离线兜底/同天连胜文案/热力图日期解析)
- leaderboard.js _applyLocal 离线兜底补 subText(N次),与云端路径对齐 - timer.js _detectCelebrationLevel 增加 lastIsToday 判断,修复同天二次训练连胜文案虚高 1 天 - calendar-heatmap.js 用 util.dateOnly 归一化后再取'日',修复脆弱的 split 解析
This commit is contained in:
@@ -59,7 +59,9 @@ Component({
|
|||||||
const recordMap = {}
|
const recordMap = {}
|
||||||
if (records && records.length) {
|
if (records && records.length) {
|
||||||
records.forEach((r) => {
|
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
|
recordMap[d] = (recordMap[d] || 0) + r.duration
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,8 @@ Page({
|
|||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
const entry = {
|
const entry = {
|
||||||
rank: 1, openid: 'local', name: localName, nickname: profile.nickname || '',
|
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 })
|
this.setData({ rankedList: [entry], myEntry: { ...entry, isMe: true }, loading: false, refreshing: false, empty: false })
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -244,7 +244,14 @@ Page({
|
|||||||
_detectCelebrationLevel(elapsed) {
|
_detectCelebrationLevel(elapsed) {
|
||||||
const stats = storage.getTotalStats()
|
const stats = storage.getTotalStats()
|
||||||
const streak = storage.getStreak()
|
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) {
|
if (stats.totalSessions === 0) {
|
||||||
return { level: 'first', message: '第一次训练!坚持就是胜利' }
|
return { level: 'first', message: '第一次训练!坚持就是胜利' }
|
||||||
|
|||||||
Reference in New Issue
Block a user