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) }