feat: 添加看视频得金币功能
- 每日可观看5次视频,- 每次观看获得3金币 - 显示今日剩余观看次数 - 记录观看历史到金币记录
This commit is contained in:
1 parent
e34586e3f0
commit
a6e5763ffc
2 files changed
+66
-4
No files matched your search
@@ -39,6 +39,21 @@
|
||||
<view class="task-card">
|
||||
<text class="task-title">其他任务</text>
|
||||
|
||||
<view class="task-item">
|
||||
<view class="task-left">
|
||||
<view class="task-icon">
|
||||
<text class="task-icon-text">🎬</text>
|
||||
</view>
|
||||
<view class="task-info">
|
||||
<text class="task-name">看视频得金币</text>
|
||||
<text class="task-reward">+3金币/次 (今日剩余{{ videoCount }}次)</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="task-btn" :class="{ disabled: videoCount <= 0 }" @click="watchVideo">
|
||||
<text class="task-btn-text">{{ videoCount > 0 ? '观看' : '已用完' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="task-item">
|
||||
<view class="task-left">
|
||||
<view class="task-icon">
|
||||
@@ -92,7 +107,8 @@ export default {
|
||||
signedToday: false,
|
||||
streakDays: 0,
|
||||
weekDays: [],
|
||||
records: []
|
||||
records: [],
|
||||
videoCount: 5
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -104,6 +120,7 @@ export default {
|
||||
this.loadCoins()
|
||||
this.initWeekProgress()
|
||||
this.loadRecords()
|
||||
this.loadVideoCount()
|
||||
},
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
@@ -211,6 +228,44 @@ export default {
|
||||
menus: ['shareAppMessage']
|
||||
})
|
||||
},
|
||||
loadVideoCount() {
|
||||
const today = this.formatDate(new Date())
|
||||
const lastVideoDate = uni.getStorageSync('lastVideoDate')
|
||||
if (lastVideoDate === today) {
|
||||
this.videoCount = uni.getStorageSync('videoCount') || 0
|
||||
} else {
|
||||
this.videoCount = 5
|
||||
uni.setStorageSync('lastVideoDate', today)
|
||||
uni.setStorageSync('videoCount', 5)
|
||||
}
|
||||
},
|
||||
watchVideo() {
|
||||
if (this.videoCount <= 0) {
|
||||
uni.showToast({ title: '今日观看次数已用完', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
uni.showLoading({ title: '加载视频中...' })
|
||||
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
|
||||
this.videoCount--
|
||||
this.coins += 3
|
||||
|
||||
uni.setStorageSync('userCoins', this.coins)
|
||||
uni.setStorageSync('videoCount', this.videoCount)
|
||||
|
||||
this.records.unshift({
|
||||
name: '观看视频',
|
||||
amount: 3,
|
||||
time: this.formatTime(new Date())
|
||||
})
|
||||
this.saveRecords()
|
||||
|
||||
uni.showToast({ title: '+3金币', icon: 'success' })
|
||||
}, 2000)
|
||||
},
|
||||
formatDate(date) {
|
||||
const y = date.getFullYear()
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||
@@ -467,6 +522,10 @@ page {
|
||||
border-radius: 32rpx;
|
||||
}
|
||||
|
||||
.task-btn.disabled {
|
||||
background: #D1D5DB;
|
||||
}
|
||||
|
||||
.task-btn-text {
|
||||
font-size: 26rpx;
|
||||
color: #ffffff;
|
||||
|
||||
@@ -173,13 +173,15 @@ page {
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.vip-tag {
|
||||
margin-left: 8rpx;
|
||||
padding: 2rpx 10rpx;
|
||||
padding: 0 8rpx;
|
||||
border-radius: 12rpx;
|
||||
height: 28rpx;
|
||||
display: inline-flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.vip-tag.normal {
|
||||
@@ -203,9 +205,10 @@ page {
|
||||
}
|
||||
|
||||
.vip-tag-text {
|
||||
font-size: 18rpx;
|
||||
font-size: 16rpx;
|
||||
font-weight: 500;
|
||||
color: #ffffff;
|
||||
line-height: 28rpx;
|
||||
}
|
||||
|
||||
.user-coins {
|
||||
|
||||
Reference in new issue
Block a user