challenge-progress.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="page">
  3. <view class="nav-bar">
  4. <view class="nav-back" @tap="goBack">
  5. <text class="back-text">‹ 返回</text>
  6. </view>
  7. <text class="nav-title">闯关进度</text>
  8. </view>
  9. <scroll-view class="content" scroll-y>
  10. <!-- 进度概览 -->
  11. <view class="progress-overview">
  12. <view class="progress-circle" :style="{ background: 'conic-gradient(#F97316 ' + progressPercent + '%, #f0f0f0 ' + progressPercent + '%)' }">
  13. <text class="progress-percent">{{ progressPercent }}%</text>
  14. </view>
  15. <text class="progress-label">已完成 {{ completedCount }}/{{ totalCount }} 项任务</text>
  16. <text class="progress-cf">已获得 {{ completedReward }} CF值</text>
  17. </view>
  18. <!-- 各周任务 -->
  19. <view class="card" v-for="(tasks, week) in tasksByWeek" :key="week">
  20. <view class="card-header">
  21. <text class="card-title">第{{ week }}周</text>
  22. <text class="card-reward">+{{ weekReward(week) }} CF</text>
  23. </view>
  24. <view class="task-list">
  25. <view class="task-item" v-for="task in tasks" :key="task.taskKey">
  26. <view class="task-left">
  27. <text class="task-icon" :class="{ 'completed': task.status === 'completed' }">{{ task.status === 'completed' ? '✓' : '○' }}</text>
  28. <view class="task-info">
  29. <text class="task-title">{{ task.taskTitle }}</text>
  30. <text class="task-progress">{{ task.currentValue }}/{{ task.targetValue }}</text>
  31. </view>
  32. </view>
  33. <text class="task-reward">+{{ task.rewardCf }} CF</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 连续打卡 -->
  38. <view class="card">
  39. <view class="card-header">
  40. <text class="card-title">连续打卡</text>
  41. <text class="card-streak">{{ streakDays }} 天</text>
  42. </view>
  43. <view class="streak-grid">
  44. <view class="streak-day" v-for="n in 21" :key="n" :class="{ 'done': n <= streakDays }">
  45. <text>{{ n }}</text>
  46. </view>
  47. </view>
  48. <text class="streak-hint">连续打卡可得额外CF加成</text>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. </template>
  53. <script>
  54. import { getChallengeProgress } from '../../utils/api.js'
  55. export default {
  56. data() {
  57. return {
  58. loading: true,
  59. tasksByWeek: {},
  60. totalReward: 0,
  61. completedReward: 0,
  62. completedCount: 0,
  63. totalCount: 0,
  64. streakDays: 0
  65. }
  66. },
  67. computed: {
  68. progressPercent() {
  69. return this.totalCount > 0 ? Math.round(this.completedCount / this.totalCount * 100) : 0
  70. }
  71. },
  72. onLoad() {
  73. this.loadProgress()
  74. },
  75. methods: {
  76. goBack() { uni.navigateBack() },
  77. async loadProgress() {
  78. this.loading = true
  79. try {
  80. var res = await getChallengeProgress(uni.getStorageSync('currentMemberId') || uni.getStorageSync('userId'))
  81. if (res.data && res.data.success) {
  82. this.tasksByWeek = res.data.byWeek || {}
  83. this.totalReward = res.data.totalReward || 0
  84. this.completedReward = res.data.completedReward || 0
  85. this.completedCount = res.data.completedCount || 0
  86. this.totalCount = res.data.totalCount || 0
  87. this.streakDays = res.data.streakDays || 0
  88. }
  89. } catch (e) {
  90. console.log('加载进度失败', e)
  91. } finally {
  92. this.loading = false
  93. }
  94. },
  95. weekReward(week) {
  96. var tasks = this.tasksByWeek[week] || []
  97. return tasks.reduce(function(sum, t) { return sum + (t.rewardCf || 0); }, 0)
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. .page { min-height: 100vh; background: #FFF7ED; }
  104. .nav-bar { display: flex; align-items: center; height: 88rpx; padding-top: env(safe-area-inset-top); background: #fff; border-bottom: 1rpx solid #f0f0f0; position: relative; }
  105. .nav-back { position: absolute; left: 24rpx; top: 0; bottom: 0; display: flex; align-items: center; }
  106. .back-text { font-size: 28rpx; color: #F97316; }
  107. .nav-title { flex: 1; text-align: center; font-size: 32rpx; font-weight: bold; color: #333; }
  108. .content { height: calc(100vh - 88rpx); }
  109. .progress-overview { background: linear-gradient(135deg, #FF8C42, #F97316); padding: 40rpx 32rpx; text-align: center; }
  110. .progress-circle { width: 160rpx; height: 160rpx; border-radius: 50%; margin: 0 auto 16rpx; display: flex; align-items: center; justify-content: center; box-shadow: 0 4rpx 20rpx rgba(249,115,22,0.3); }
  111. .progress-percent { font-size: 36rpx; font-weight: bold; color: #fff; }
  112. .progress-label { font-size: 24rpx; color: rgba(255,255,255,0.9); display: block; }
  113. .progress-cf { font-size: 28rpx; color: #FFD700; font-weight: bold; margin-top: 8rpx; display: block; }
  114. .card { margin: 16rpx 24rpx; background: #fff; border-radius: 20rpx; overflow: hidden; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06); }
  115. .card-header { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 24rpx; border-bottom: 1rpx solid #f5f5f5; }
  116. .card-title { font-size: 28rpx; font-weight: bold; color: #333; }
  117. .card-reward { font-size: 22rpx; color: #F97316; }
  118. .card-streak { font-size: 28rpx; font-weight: bold; color: #F97316; }
  119. .task-list { padding: 16rpx 24rpx; }
  120. .task-item { display: flex; justify-content: space-between; align-items: center; padding: 16rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  121. .task-item:last-child { border-bottom: none; }
  122. .task-left { display: flex; align-items: center; gap: 16rpx; flex: 1; min-width: 0; }
  123. .task-icon { font-size: 32rpx; color: #ccc; width: 40rpx; text-align: center; }
  124. .task-icon.completed { color: #4CAF50; }
  125. .task-info { flex: 1; min-width: 0; }
  126. .task-title { font-size: 26rpx; color: #333; display: block; }
  127. .task-progress { font-size: 22rpx; color: #999; margin-top: 4rpx; display: block; }
  128. .task-reward { font-size: 22rpx; color: #F97316; flex-shrink: 0; margin-left: 16rpx; }
  129. .streak-grid { display: flex; flex-wrap: wrap; gap: 8rpx; padding: 16rpx 24rpx; }
  130. .streak-day { width: 48rpx; height: 48rpx; border-radius: 50%; background: #f0f0f0; display: flex; align-items: center; justify-content: center; font-size: 20rpx; color: #999; }
  131. .streak-day.done { background: #F97316; color: #fff; }
  132. .streak-hint { font-size: 22rpx; color: #999; text-align: center; padding: 0 24rpx 16rpx; display: block; }
  133. </style>