From f05232727682dd6e4b3a48b5ca67d3fb9f34f6f1 Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Wed, 8 Jul 2026 14:13:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=AD=E7=BB=83=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E9=A6=96=E9=A1=B5=20streak=20=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=203=20=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit timer 记录保存时写 _last_train_at 时间戳,index onShow 检测 < 10s 的标记则触发 just-completed class,卡片脉冲 2 次 + 主题色 边框 + 阴影,3 秒后自动淡出。让'完成训练'的反馈在首页也可见。 --- pages/index/index.js | 26 ++++++++++++++++++++++++++ pages/index/index.wxml | 2 +- pages/index/index.wxss | 12 ++++++++++++ pages/timer/timer.js | 4 ++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/pages/index/index.js b/pages/index/index.js index de070a0..ac06be4 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -41,9 +41,35 @@ Page({ if (this._firstShow) { this._firstShow = false this.refresh() + this._checkFreshTrain() return } this.refresh() + this._checkFreshTrain() + }, + + /** + * If user just returned from completing a training, briefly highlight + * the "今日已完成" badge so the success feels tangible. The flag is + * timestamped; older than 10s is treated as stale (e.g. user reopened + * the app later). + */ + _checkFreshTrain() { + try { + const at = wx.getStorageSync('_last_train_at') + if (!at) return + const age = Date.now() - at + if (age < 0 || age > 10 * 1000) { + wx.removeStorageSync('_last_train_at') + return + } + wx.removeStorageSync('_last_train_at') + this.setData({ justCompleted: true }) + if (this._justCompletedTimer) clearTimeout(this._justCompletedTimer) + this._justCompletedTimer = setTimeout(() => { + this.setData({ justCompleted: false }) + }, 3000) + } catch (e) {} }, onPullDownRefresh() { diff --git a/pages/index/index.wxml b/pages/index/index.wxml index f36b3ed..71f3f51 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -10,7 +10,7 @@ - + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 937471a..0f9d751 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -350,3 +350,15 @@ padding: 12rpx 0; margin-top: 8rpx; } + +/* ---- 训练完成高亮 (3 秒后淡出) ---- */ +.just-completed { + animation: justCompletedPulse 1s ease-in-out 2; + border: 4rpx solid var(--primary) !important; + box-shadow: 0 4rpx 24rpx rgba(var(--primary-rgb), 0.3) !important; +} + +@keyframes justCompletedPulse { + 0%, 100% { transform: scale(1); } + 50% { transform: scale(1.02); } +} diff --git a/pages/timer/timer.js b/pages/timer/timer.js index fabc52f..269bd50 100644 --- a/pages/timer/timer.js +++ b/pages/timer/timer.js @@ -292,6 +292,10 @@ Page({ }) storage.updateStreak(today) + // Flag the just-completed training so the index page can briefly + // highlight the "今日已完成" badge when the user lands back there. + try { wx.setStorageSync('_last_train_at', Date.now()) } catch (e) {} + wx.showToast({ title: `已记录 ${elapsed}秒`, icon: 'none', duration: 1500 }) setTimeout(() => { wx.navigateBack() }, 1500) }