fix: 修复排行榜数据自增长(冷启动重复创建云端文档)

每次小程序冷启动都会为同一用户创建新的云端文档,
导致 leaderboard 把同一份数据累加 N 次。

改动:
- app.js: onLaunch 改为 async,每次启动先 pullAll 填充 _openid / _docId 缓存
- utils/cloud.js: 引入 _ensureOpenid() 单次解析;_doPush 总是先按 openid
  定位现有文档;update 失败不再回退到 add()(避免创建重复文档)
- utils/storage.js: getTodayRecord 按日期部分比较,修复一天第二次训练
This commit is contained in:
liucheng
2026-06-21 22:56:51 +08:00
parent 47f718a129
commit 6d1992869e
6 changed files with 259 additions and 57 deletions
+7 -1
View File
@@ -245,12 +245,18 @@ const getDateOffset = (dateStr, offset) => {
const getTodayRecord = () => {
const today = getToday()
// Record `date` is "YYYY-MM-DD HH:MM:SS" (formatted at saveRecord time),
// so a strict === check against the freshly-formatted `today` only matches
// a record saved in the exact same second. Compare date-only portions
// instead, otherwise the second training of the day reads as zero and
// the home page flips "今日已完成" back off.
const todayOnly = dateOnly(today)
const records = getRecords()
let totalDuration = 0
let hasRecord = false
Object.keys(records).forEach((month) => {
records[month].forEach((r) => {
if (r.date === today) {
if (dateOnly(r.date) === todayOnly) {
totalDuration += r.duration
hasRecord = true
}