fix: 修复 4 个正确性问题(分享秒数/主题同步/云推送定位/streak重算)

- timer: 完成弹窗存实际时长 completionActualElapsed,分享改用它,避免用动画值导致秒数错误
- theme: setTheme 补 _markLocalChanged,避免云恢复覆盖未同步的主题改动
- cloud: _doPush 重定位查询补 orderBy(updatedAt desc),与 pullAll 一致,避免命中最旧文档
- storage: deleteRecord 改用 recomputeStreak,修复删连续链中间某天 streak 虚高

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liucheng
2026-07-25 14:51:09 +08:00
parent b47a48259e
commit 1c140bd503
4 changed files with 9 additions and 4 deletions
+3 -2
View File
@@ -412,6 +412,7 @@ Page({
// Modal state // Modal state
showCompletion: true, showCompletion: true,
completionElapsed: 0, completionElapsed: 0,
completionActualElapsed: elapsed,
completionTarget: this.data.duration, completionTarget: this.data.duration,
completionOvertime: Math.max(0, elapsed - this.data.duration), completionOvertime: Math.max(0, elapsed - this.data.duration),
completionStreak: finalStreak, completionStreak: finalStreak,
@@ -494,7 +495,7 @@ Page({
* 刚才撑了多久,转化率更高;右上角"···"菜单也共用同一份文案。 * 刚才撑了多久,转化率更高;右上角"···"菜单也共用同一份文案。
*/ */
onShareAppMessage() { onShareAppMessage() {
const elapsed = this.data.completionElapsed || this.data.duration const elapsed = this.data.completionActualElapsed || this.data.duration
const s = config.share.timer const s = config.share.timer
return { return {
title: s.titleTemplate.replace('{elapsed}', elapsed), title: s.titleTemplate.replace('{elapsed}', elapsed),
@@ -506,7 +507,7 @@ Page({
* 分享到朋友圈,同样带上刚完成的时长晒成绩。 * 分享到朋友圈,同样带上刚完成的时长晒成绩。
*/ */
onShareTimeline() { onShareTimeline() {
const elapsed = this.data.completionElapsed || this.data.duration const elapsed = this.data.completionActualElapsed || this.data.duration
return { return {
title: config.share.timer.timelineTitleTemplate.replace('{elapsed}', elapsed) title: config.share.timer.timelineTitleTemplate.replace('{elapsed}', elapsed)
} }
+1
View File
@@ -176,6 +176,7 @@ const _doPush = async () => {
if (openid) { if (openid) {
const existing = await db.collection(DB_COLLECTION) const existing = await db.collection(DB_COLLECTION)
.where({ _openid: openid }) .where({ _openid: openid })
.orderBy('updatedAt', 'desc') // 与 pullAll 一致,避免命中最旧文档
.limit(1) .limit(1)
.get() .get()
if (existing && existing.data && existing.data.length > 0) { if (existing && existing.data && existing.data.length > 0) {
+3 -2
View File
@@ -96,8 +96,8 @@ const deleteRecord = (recordId) => {
}) })
if (!found) return // id not found, don't overwrite storage if (!found) return // id not found, don't overwrite storage
wx.setStorageSync(RECORDS_KEY, records) wx.setStorageSync(RECORDS_KEY, records)
// Re-validate streak: deleting the last record for a day should break the streak // 重新计算连续打卡:删连续链中间某天会断链,validateStreak 只在 lastDate 被删时重算,不够
validateStreak() recomputeStreak()
cloud.pushAll() cloud.pushAll()
} }
@@ -435,6 +435,7 @@ module.exports = {
validateStreak, validateStreak,
recomputeStreak, recomputeStreak,
updateStreak, updateStreak,
_markLocalChanged,
getToday, getToday,
getDateOffset, getDateOffset,
getTodayRecord getTodayRecord
+2
View File
@@ -96,6 +96,8 @@ const setTheme = (id) => {
const app = getApp() const app = getApp()
if (app && app.globalData) app.globalData.theme = theme if (app && app.globalData) app.globalData.theme = theme
// 标记本地已改动,避免下次启动云恢复用旧 themeId 覆盖刚选的主题
try { require('./storage')._markLocalChanged() } catch (e) {}
// sync to cloud (lazy-require to avoid circular deps) // sync to cloud (lazy-require to avoid circular deps)
try { require('./cloud').pushAll() } catch (e) {} try { require('./cloud').pushAll() } catch (e) {}
return theme return theme