| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <template>
- <view class="section">
- <view class="section-header">
- <text class="section-title">📈 成长报告</text>
- <text class="section-more" @click="goGrowthReport">查看 ›</text>
- </view>
- <view class="report-card" @click="goGrowthReport">
- <view class="report-stat-item">
- <text class="report-stat">{{ growthReport.monthActiveDays || 0 }}天</text>
- <text class="report-label">本月活跃</text>
- </view>
- <view class="report-divider"></view>
- <view class="report-stat-item">
- <text class="report-stat">{{ growthReport.totalTasks || 0 }}</text>
- <text class="report-label">累计任务</text>
- </view>
- <view class="report-divider"></view>
- <view class="report-stat-item">
- <text class="report-stat">{{ growthReport.completionRate || 0 }}%</text>
- <text class="report-label">完成率</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getGrowthReport } from '../../../utils/api.js'
- export default {
- name: 'ProfileGrowth',
- data() {
- return {
- growthReport: {
- monthActiveDays: 0,
- totalTasks: 0,
- completionRate: 0
- }
- }
- },
- onShow() {
- if (!uni.getStorageSync('token')) return
- this.loadGrowthReport()
- },
- methods: {
- loadGrowthReport() {
- let memberId = uni.getStorageSync('currentChildId') || null
- if (!memberId) {
- const children = uni.getStorageSync('childrenList')
- if (children && children.length > 0) {
- memberId = children[0].id
- }
- }
- if (!memberId) {
- this.loadGrowthReportLocal()
- return
- }
- getGrowthReport(memberId).then((res) => {
- if (res.code === 200 && res.data) {
- const d = res.data
- this.growthReport.monthActiveDays = d.monthActiveDays || d.activeDays || 0
- this.growthReport.totalTasks = (d.taskStats && d.taskStats.total) || d.totalTasks || 0
- this.growthReport.completionRate = (d.taskStats && d.taskStats.completionRate) || d.completionRate || 0
- } else {
- this.loadGrowthReportLocal()
- }
- }).catch(() => {
- this.loadGrowthReportLocal()
- })
- },
- loadGrowthReportLocal() {
- const streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
- const completedTasks = parseInt(uni.getStorageSync('completedTasks') || 0)
- this.growthReport.monthActiveDays = streakDays > 0 ? Math.min(streakDays, 30) : 0
- this.growthReport.totalTasks = completedTasks || 0
- this.growthReport.completionRate = 85
- },
- goGrowthReport() {
- const memberId = uni.getStorageSync('currentChildId') || ''
- uni.navigateTo({ url: '/pages/growth/report?memberId=' + memberId })
- }
- }
- }
- </script>
- <style scoped>
- .section {
- margin: 20rpx 30rpx;
- }
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .section-more {
- font-size: 24rpx;
- color: #999;
- }
- .report-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx;
- display: flex;
- align-items: center;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .report-stat-item {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .report-stat {
- font-size: 40rpx;
- font-weight: bold;
- color: #667eea;
- }
- .report-label {
- font-size: 24rpx;
- color: #999;
- margin-top: 8rpx;
- }
- .report-divider {
- width: 1rpx;
- height: 60rpx;
- background: #f0f0f0;
- }
- </style>
|