index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 -->
  4. <!-- 统计概览 -->
  5. <view class="stats-card">
  6. <view class="stat-item">
  7. <text class="stat-num">{{ unlockedCount }}</text>
  8. <text class="stat-label">已获得</text>
  9. </view>
  10. <view class="stat-item">
  11. <text class="stat-num">{{ totalBadges }}</text>
  12. <text class="stat-label">总勋章</text>
  13. </view>
  14. <view class="stat-item">
  15. <text class="stat-num">{{ streakDays }}</text>
  16. <text class="stat-label">连续打卡</text>
  17. </view>
  18. </view>
  19. <!-- 勋章列表 -->
  20. <view class="badge-section">
  21. <view class="section-title">勋章墙</view>
  22. <view class="badge-grid" v-if="badges.length > 0">
  23. <view class="badge-item" v-for="badge in badges" :key="badge.id">
  24. <view :class="['badge-icon-wrap', badge.unlocked ? 'unlocked' : 'locked']">
  25. <text class="badge-icon">{{ badge.icon }}</text>
  26. </view>
  27. <text class="badge-name">{{ badge.name }}</text>
  28. <text class="badge-desc" v-if="badge.unlocked">{{ badge.getDesc }}</text>
  29. </view>
  30. </view>
  31. <view class="empty-state" v-else>
  32. <text class="empty-icon">🏅</text>
  33. <text class="empty-text">暂无勋章</text>
  34. <text class="empty-hint">完成任务和打卡获得勋章</text>
  35. </view>
  36. </view>
  37. <!-- 进度目标 -->
  38. <view class="goals-section">
  39. <view class="section-title">近期目标</view>
  40. <view class="goal-item" v-for="goal in goals" :key="goal.id">
  41. <view class="goal-header">
  42. <text class="goal-name">{{ goal.name }}</text>
  43. <text class="goal-progress">{{ goal.current }}/{{ goal.target }}</text>
  44. </view>
  45. <view class="progress-bar">
  46. <view class="progress-fill" :style="{ width: goal.percent + '%' }"></view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { getChildBadges } from '@/utils/api'
  54. export default {
  55. data() {
  56. return {
  57. badges: [],
  58. totalBadges: 0,
  59. unlockedCount: 0,
  60. streakDays: 0,
  61. goals: []
  62. }
  63. },
  64. onLoad() {
  65. this.loadBadges()
  66. this.loadStreak()
  67. this.loadGoals()
  68. },
  69. methods: {
  70. loadBadges() {
  71. const memberId = uni.getStorageSync('memberId') || null
  72. getChildBadges(memberId).then(res => {
  73. if (res.code === 200 && res.data) {
  74. this.badges = res.data.map(item => ({
  75. id: item.badge?.id,
  76. icon: item.badge?.icon || '⭐',
  77. name: item.badge?.name || '未知勋章',
  78. unlocked: !!item.childBadge,
  79. getDesc: item.badge?.description || ''
  80. }))
  81. this.totalBadges = res.data.length
  82. this.unlockedCount = res.data.filter(item => item.childBadge).length
  83. }
  84. }).catch(() => {})
  85. },
  86. loadStreak() {
  87. // 从本地存储获取连续打卡天数
  88. this.streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
  89. },
  90. loadGoals() {
  91. this.goals = [
  92. { id: 1, name: '连续打卡7天', current: this.streakDays, target: 7, percent: Math.min(100, (this.streakDays / 7) * 100) },
  93. { id: 2, name: '获得5个勋章', current: this.unlockedCount, target: 5, percent: Math.min(100, (this.unlockedCount / 5) * 100) },
  94. { id: 3, name: '累计积分1000', current: parseInt(uni.getStorageSync('totalPoints') || 0), target: 1000, percent: Math.min(100, (parseInt(uni.getStorageSync('totalPoints') || 0) / 1000) * 100) }
  95. ]
  96. },
  97. goBack() {
  98. uni.navigateBack()
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped>
  104. .container {
  105. min-height: 100vh;
  106. background: #f5f7fa;
  107. }
  108. .nav-placeholder {
  109. width: 60rpx;
  110. }
  111. .stats-card {
  112. display: flex;
  113. background: #fff;
  114. padding: 40rpx 0;
  115. margin-bottom: 20rpx;
  116. }
  117. .stat-item {
  118. flex: 1;
  119. text-align: center;
  120. }
  121. .stat-num {
  122. display: block;
  123. font-size: 48rpx;
  124. font-weight: 700;
  125. color: #F97316;
  126. }
  127. .stat-label {
  128. display: block;
  129. font-size: 24rpx;
  130. color: #999;
  131. margin-top: 8rpx;
  132. }
  133. .badge-section, .goals-section {
  134. background: #fff;
  135. margin: 0 30rpx 20rpx;
  136. border-radius: 20rpx;
  137. padding: 30rpx;
  138. }
  139. .section-title {
  140. font-size: 30rpx;
  141. font-weight: 600;
  142. color: #333;
  143. margin-bottom: 24rpx;
  144. }
  145. .badge-grid {
  146. display: flex;
  147. flex-wrap: wrap;
  148. gap: 20rpx;
  149. }
  150. .badge-item {
  151. width: calc(33.33% - 14rpx);
  152. text-align: center;
  153. }
  154. .badge-icon-wrap {
  155. width: 80rpx;
  156. height: 80rpx;
  157. border-radius: 50%;
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. margin: 0 auto 12rpx;
  162. }
  163. .badge-icon-wrap.unlocked {
  164. background: linear-gradient(135deg, #FFD700, #FFA500);
  165. }
  166. .badge-icon-wrap.locked {
  167. background: #e8e8e8;
  168. }
  169. .badge-icon {
  170. font-size: 40rpx;
  171. }
  172. .badge-name {
  173. display: block;
  174. font-size: 22rpx;
  175. color: #333;
  176. margin-bottom: 4rpx;
  177. }
  178. .badge-desc {
  179. display: block;
  180. font-size: 18rpx;
  181. color: #999;
  182. }
  183. .empty-state {
  184. text-align: center;
  185. padding: 60rpx 0;
  186. }
  187. .empty-icon {
  188. font-size: 80rpx;
  189. display: block;
  190. margin-bottom: 20rpx;
  191. }
  192. .empty-text {
  193. display: block;
  194. font-size: 28rpx;
  195. color: #999;
  196. margin-bottom: 12rpx;
  197. }
  198. .empty-hint {
  199. display: block;
  200. font-size: 24rpx;
  201. color: #ccc;
  202. }
  203. .goal-item {
  204. margin-bottom: 24rpx;
  205. }
  206. .goal-item:last-child {
  207. margin-bottom: 0;
  208. }
  209. .goal-header {
  210. display: flex;
  211. justify-content: space-between;
  212. margin-bottom: 12rpx;
  213. }
  214. .goal-name {
  215. font-size: 26rpx;
  216. color: #333;
  217. }
  218. .goal-progress {
  219. font-size: 24rpx;
  220. color: #999;
  221. }
  222. .progress-bar {
  223. height: 12rpx;
  224. background: #f0f0f0;
  225. border-radius: 6rpx;
  226. overflow: hidden;
  227. }
  228. .progress-fill {
  229. height: 100%;
  230. background: linear-gradient(90deg, #F97316, #FB923C);
  231. border-radius: 6rpx;
  232. transition: width 0.3s;
  233. }
  234. </style>