From 1c140bd503bfb824444d77949dfd0357abfc27d8 Mon Sep 17 00:00:00 2001 From: liucheng Date: Sat, 25 Jul 2026 14:51:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=204=20=E4=B8=AA?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E6=80=A7=E9=97=AE=E9=A2=98(=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E7=A7=92=E6=95=B0/=E4=B8=BB=E9=A2=98=E5=90=8C?= =?UTF-8?q?=E6=AD=A5/=E4=BA=91=E6=8E=A8=E9=80=81=E5=AE=9A=E4=BD=8D/streak?= =?UTF-8?q?=E9=87=8D=E7=AE=97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - timer: 完成弹窗存实际时长 completionActualElapsed,分享改用它,避免用动画值导致秒数错误 - theme: setTheme 补 _markLocalChanged,避免云恢复覆盖未同步的主题改动 - cloud: _doPush 重定位查询补 orderBy(updatedAt desc),与 pullAll 一致,避免命中最旧文档 - storage: deleteRecord 改用 recomputeStreak,修复删连续链中间某天 streak 虚高 Co-Authored-By: Claude --- pages/timer/timer.js | 5 +++-- utils/cloud.js | 1 + utils/storage.js | 5 +++-- utils/theme.js | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pages/timer/timer.js b/pages/timer/timer.js index 0edbcdd..56b092c 100644 --- a/pages/timer/timer.js +++ b/pages/timer/timer.js @@ -412,6 +412,7 @@ Page({ // Modal state showCompletion: true, completionElapsed: 0, + completionActualElapsed: elapsed, completionTarget: this.data.duration, completionOvertime: Math.max(0, elapsed - this.data.duration), completionStreak: finalStreak, @@ -494,7 +495,7 @@ Page({ * 刚才撑了多久,转化率更高;右上角"···"菜单也共用同一份文案。 */ onShareAppMessage() { - const elapsed = this.data.completionElapsed || this.data.duration + const elapsed = this.data.completionActualElapsed || this.data.duration const s = config.share.timer return { title: s.titleTemplate.replace('{elapsed}', elapsed), @@ -506,7 +507,7 @@ Page({ * 分享到朋友圈,同样带上刚完成的时长晒成绩。 */ onShareTimeline() { - const elapsed = this.data.completionElapsed || this.data.duration + const elapsed = this.data.completionActualElapsed || this.data.duration return { title: config.share.timer.timelineTitleTemplate.replace('{elapsed}', elapsed) } diff --git a/utils/cloud.js b/utils/cloud.js index 4d11ced..d1e4e73 100644 --- a/utils/cloud.js +++ b/utils/cloud.js @@ -176,6 +176,7 @@ const _doPush = async () => { if (openid) { const existing = await db.collection(DB_COLLECTION) .where({ _openid: openid }) + .orderBy('updatedAt', 'desc') // 与 pullAll 一致,避免命中最旧文档 .limit(1) .get() if (existing && existing.data && existing.data.length > 0) { diff --git a/utils/storage.js b/utils/storage.js index a59a2e2..6567c01 100644 --- a/utils/storage.js +++ b/utils/storage.js @@ -96,8 +96,8 @@ const deleteRecord = (recordId) => { }) if (!found) return // id not found, don't overwrite storage wx.setStorageSync(RECORDS_KEY, records) - // Re-validate streak: deleting the last record for a day should break the streak - validateStreak() + // 重新计算连续打卡:删连续链中间某天会断链,validateStreak 只在 lastDate 被删时重算,不够 + recomputeStreak() cloud.pushAll() } @@ -435,6 +435,7 @@ module.exports = { validateStreak, recomputeStreak, updateStreak, + _markLocalChanged, getToday, getDateOffset, getTodayRecord diff --git a/utils/theme.js b/utils/theme.js index 9f8b105..9ceec6b 100644 --- a/utils/theme.js +++ b/utils/theme.js @@ -96,6 +96,8 @@ const setTheme = (id) => { const app = getApp() if (app && app.globalData) app.globalData.theme = theme + // 标记本地已改动,避免下次启动云恢复用旧 themeId 覆盖刚选的主题 + try { require('./storage')._markLocalChanged() } catch (e) {} // sync to cloud (lazy-require to avoid circular deps) try { require('./cloud').pushAll() } catch (e) {} return theme