diff --git a/xuan-deduct-uniapp/src/pages/mine/coins.vue b/xuan-deduct-uniapp/src/pages/mine/coins.vue index 8de9df8..cfed6a0 100644 --- a/xuan-deduct-uniapp/src/pages/mine/coins.vue +++ b/xuan-deduct-uniapp/src/pages/mine/coins.vue @@ -115,10 +115,10 @@ export default { }, computed: { todayReward() { - return this.getDayReward(this.streakDays % 7) + return this.getDayReward((this.streakDays - 1) % 7) }, currentStreak() { - return this.streakDays % 7 || (this.streakDays > 0 ? 7 : 0) + return this.streakDays } }, onShow() { @@ -167,8 +167,14 @@ export default { this.weekDays = [] for (let i = 0; i < 7; i++) { + // 计算每个位置对应的日期 + // 第1个位置是签到开始的那天,第7个位置是签到的第7天 const date = new Date(today) - date.setDate(today.getDate() - (this.currentStreak - 1 - i)) + // 从今天往前推 (currentStreak - 1 - i) 天 + // 如果 currentStreak = 3,则第1个位置是今天-2天,第2个位置是今天-1天,第3个位置是今天 + // 第4-7个位置是今天+1到+4天 + const offset = i - (this.currentStreak - 1) + date.setDate(today.getDate() + offset) this.weekDays.push({ label: weekLabels[date.getDay()], @@ -190,9 +196,15 @@ export default { yesterday.setDate(today.getDate() - 1) const yesterdayStr = this.formatDate(yesterday) + // 判断是否连续签到 if (lastSignInStr === yesterdayStr) { this.streakDays++ + // 超过7天,重置为第1天 + if (this.streakDays > 7) { + this.streakDays = 1 + } } else { + // 签到中断,重置为第1天 this.streakDays = 1 }