feat: 签到中断或超过7天重置为第1天
- 签到中断时重置连续签到天数为1 - 连续签到超过7天时重置为第1天 - 优化签到进度显示逻辑
This commit is contained in:
1 parent
df562f9a52
commit
365a01f5e8
1 file changed
+15
-3
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user