ProfileStats.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view :style="{ '--font-scale': fontScale }">
  3. <!-- 行动数据 -->
  4. <view class="section">
  5. <view class="section-header">
  6. <text class="section-title">🎯 行动数据</text>
  7. </view>
  8. <view class="action-card">
  9. <view class="action-item">
  10. <text class="action-value">{{ actionData.taskCount }}</text>
  11. <text class="action-label">完成任务</text>
  12. </view>
  13. <view class="action-divider"></view>
  14. <view class="action-item">
  15. <text class="action-value">{{ actionData.purchaseCount }}</text>
  16. <text class="action-label">购买商品</text>
  17. </view>
  18. <view class="action-divider"></view>
  19. <view class="action-item">
  20. <text class="action-value">{{ actionData.activityCount }}</text>
  21. <text class="action-label">参加活动</text>
  22. </view>
  23. <view class="action-divider"></view>
  24. <view class="action-item">
  25. <text class="action-value">{{ actionData.courseCount }}</text>
  26. <text class="action-label">学习课程</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { getUserActionStats } from '../../../utils/api.js'
  34. import fontScaleMixin from '@/mixins/font-scale.js'
  35. export default {
  36. mixins: [fontScaleMixin],
  37. name: 'ProfileStats',
  38. data() {
  39. return {
  40. actionData: {
  41. purchaseCount: 0,
  42. activityCount: 0,
  43. taskCount: 0,
  44. courseCount: 0
  45. }
  46. }
  47. },
  48. onShow() {
  49. if (!uni.getStorageSync('token')) return
  50. this.loadActionData()
  51. },
  52. methods: {
  53. async loadActionData() {
  54. try {
  55. const res = await getUserActionStats()
  56. if (res.code === 200 && res.data) {
  57. this.actionData.purchaseCount = res.data.purchaseCount || 0
  58. this.actionData.activityCount = res.data.activityCount || 0
  59. this.actionData.taskCount = res.data.taskCount || 0
  60. this.actionData.courseCount = res.data.courseCount || 0
  61. }
  62. } catch (e) {
  63. this.actionData.taskCount = parseInt(uni.getStorageSync('completedTasks') || 0)
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. .section {
  71. margin: 20rpx $uni-space-lg;
  72. }
  73. .section-header {
  74. display: flex;
  75. justify-content: space-between;
  76. align-items: center;
  77. margin-bottom: 20rpx;
  78. }
  79. .section-title {
  80. font-size: calc(30rpx * var(--font-scale, 1));
  81. font-weight: bold;
  82. color: $facade-text-strong;
  83. }
  84. .section-more {
  85. font-size: calc(24rpx * var(--font-scale, 1));
  86. color: $facade-text-muted;
  87. }
  88. .action-card {
  89. background: $app-surface;
  90. border-radius: 24rpx;
  91. padding: $uni-space-lg 20rpx;
  92. display: flex;
  93. align-items: center;
  94. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  95. }
  96. .action-item {
  97. flex: 1;
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. }
  102. .action-value {
  103. font-size: calc(40rpx * var(--font-scale, 1));
  104. font-weight: bold;
  105. color: $brand-primary;
  106. }
  107. .action-label {
  108. font-size: calc(24rpx * var(--font-scale, 1));
  109. color: $facade-text-muted;
  110. margin-top: 8rpx;
  111. }
  112. .action-divider {
  113. width: 1rpx;
  114. height: 60rpx;
  115. background: $facade-fill;
  116. }
  117. </style>