feat: 优化签到进度显示
- 连续签到几天,前几个图标变亮 - 下面的星期几显示对应签到日期的星期 - 添加currentStreak计算属性
This commit is contained in:
1 parent
db22cd87a4
commit
df562f9a52
1 file changed
+7
-11
@@ -16,7 +16,7 @@
|
||||
|
||||
<view class="week-progress">
|
||||
<view class="day-item" v-for="(day, index) in weekDays" :key="index">
|
||||
<view class="day-circle" :class="{ signed: day.signed, today: day.isToday }">
|
||||
<view class="day-circle" :class="{ signed: index < currentStreak, today: index === currentStreak - 1 && signedToday }">
|
||||
<text class="day-num">{{ index + 1 }}</text>
|
||||
</view>
|
||||
<text class="day-label">{{ day.label }}</text>
|
||||
@@ -116,6 +116,9 @@ export default {
|
||||
computed: {
|
||||
todayReward() {
|
||||
return this.getDayReward(this.streakDays % 7)
|
||||
},
|
||||
currentStreak() {
|
||||
return this.streakDays % 7 || (this.streakDays > 0 ? 7 : 0)
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
@@ -153,7 +156,6 @@ export default {
|
||||
},
|
||||
initWeekProgress() {
|
||||
const today = new Date()
|
||||
const dayOfWeek = today.getDay()
|
||||
const weekLabels = ['日', '一', '二', '三', '四', '五', '六']
|
||||
|
||||
const lastSignInStr = uni.getStorageSync('lastSignInDate')
|
||||
@@ -163,20 +165,14 @@ export default {
|
||||
const todayStr = this.formatDate(today)
|
||||
this.signedToday = lastSignInStr === todayStr
|
||||
|
||||
const signInHistory = uni.getStorageSync('signInHistory') || '{}'
|
||||
const history = JSON.parse(signInHistory)
|
||||
|
||||
this.weekDays = []
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const date = new Date(today)
|
||||
date.setDate(today.getDate() - dayOfWeek + i)
|
||||
const dateStr = this.formatDate(date)
|
||||
date.setDate(today.getDate() - (this.currentStreak - 1 - i))
|
||||
|
||||
this.weekDays.push({
|
||||
label: weekLabels[i],
|
||||
signed: history[dateStr] === true,
|
||||
isToday: i === dayOfWeek,
|
||||
date: dateStr
|
||||
label: weekLabels[date.getDay()],
|
||||
date: this.formatDate(date)
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user