ProfileGrowth.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="section" :style="{ '--font-scale': fontScale }">
  3. <view class="section-header">
  4. <text class="section-title">📈 成长报告</text>
  5. <text class="section-more" @click="goGrowthReport">查看 ›</text>
  6. </view>
  7. <view class="report-card" @click="goGrowthReport">
  8. <view class="report-stat-item">
  9. <text class="report-stat">{{ growthReport.monthActiveDays || 0 }}天</text>
  10. <text class="report-label">本月活跃</text>
  11. </view>
  12. <view class="report-divider"></view>
  13. <view class="report-stat-item">
  14. <text class="report-stat">{{ growthReport.totalTasks || 0 }}</text>
  15. <text class="report-label">累计任务</text>
  16. </view>
  17. <view class="report-divider"></view>
  18. <view class="report-stat-item">
  19. <text class="report-stat">{{ growthReport.completionRate || 0 }}%</text>
  20. <text class="report-label">完成率</text>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import { getGrowthReport } from '../../../utils/api.js'
  27. import fontScaleMixin from '@/mixins/font-scale.js'
  28. export default {
  29. mixins: [fontScaleMixin],
  30. name: 'ProfileGrowth',
  31. data() {
  32. return {
  33. growthReport: {
  34. monthActiveDays: 0,
  35. totalTasks: 0,
  36. completionRate: 0
  37. }
  38. }
  39. },
  40. onShow() {
  41. if (!uni.getStorageSync('token')) return
  42. this.loadGrowthReport()
  43. },
  44. methods: {
  45. loadGrowthReport() {
  46. let memberId = uni.getStorageSync('currentChildId') || null
  47. if (!memberId) {
  48. const children = uni.getStorageSync('childrenList')
  49. if (children && children.length > 0) {
  50. memberId = children[0].id
  51. }
  52. }
  53. if (!memberId) {
  54. this.loadGrowthReportLocal()
  55. return
  56. }
  57. getGrowthReport(memberId).then((res) => {
  58. if (res.code === 200 && res.data) {
  59. const d = res.data
  60. this.growthReport.monthActiveDays = d.monthActiveDays || d.activeDays || 0
  61. this.growthReport.totalTasks = (d.taskStats && d.taskStats.total) || d.totalTasks || 0
  62. this.growthReport.completionRate = (d.taskStats && d.taskStats.completionRate) || d.completionRate || 0
  63. } else {
  64. this.loadGrowthReportLocal()
  65. }
  66. }).catch(() => {
  67. this.loadGrowthReportLocal()
  68. })
  69. },
  70. loadGrowthReportLocal() {
  71. const streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
  72. const completedTasks = parseInt(uni.getStorageSync('completedTasks') || 0)
  73. this.growthReport.monthActiveDays = streakDays > 0 ? Math.min(streakDays, 30) : 0
  74. this.growthReport.totalTasks = completedTasks || 0
  75. this.growthReport.completionRate = 85
  76. },
  77. goGrowthReport() {
  78. const memberId = uni.getStorageSync('currentChildId') || ''
  79. uni.navigateTo({ url: '/pages/growth/report?memberId=' + memberId })
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. .section {
  86. margin: 20rpx $uni-space-lg;
  87. }
  88. .section-header {
  89. display: flex;
  90. justify-content: space-between;
  91. align-items: center;
  92. margin-bottom: 20rpx;
  93. }
  94. .section-title {
  95. font-size: calc(30rpx * var(--font-scale, 1));
  96. font-weight: bold;
  97. color: $facade-text-strong;
  98. }
  99. .section-more {
  100. font-size: calc(24rpx * var(--font-scale, 1));
  101. color: $facade-text-muted;
  102. }
  103. .report-card {
  104. background: $app-surface;
  105. border-radius: 24rpx;
  106. padding: $uni-space-lg;
  107. display: flex;
  108. align-items: center;
  109. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  110. }
  111. .report-stat-item {
  112. flex: 1;
  113. display: flex;
  114. flex-direction: column;
  115. align-items: center;
  116. }
  117. .report-stat {
  118. font-size: calc(40rpx * var(--font-scale, 1));
  119. font-weight: bold;
  120. color: $accent-indigo;
  121. }
  122. .report-label {
  123. font-size: calc(24rpx * var(--font-scale, 1));
  124. color: $facade-text-muted;
  125. margin-top: 8rpx;
  126. }
  127. .report-divider {
  128. width: 1rpx;
  129. height: 60rpx;
  130. background: $facade-fill;
  131. }
  132. </style>