This document outlines the implementation of a comprehensive weight management system in the WeightComponent at campus_health_app/frontend/campus-health-app/src/app/modules/weight/weight.component.ts. All features will be implemented in a single component using ECharts for visualizations, with data persisted in localStorage and synced with backend API.
Install required packages:
echarts: ^5.4.3 (charting library)ngx-echarts: ^17.0.0 (Angular wrapper for ECharts)Extend existing WeightRecord interface and add new interfaces:
measurementTime, measurementCondition (空腹/餐后), notes, tags (关键节点标记)targetWeight, targetBodyFat, targetDate, startWeight, startDate, weeklyTargettype, severity, message, detectedDateA. Data Collection Module
B. Goal Management Module
weightGoal keyC. Anomaly Detection Engine
D. Multi-dimensional Filtering
Chart 1: Weight Trend Line Chart (Primary, 50% height)
// Three lines: actual weight (blue), target weight (red), planned trend (gray dashed)
// X-axis: time with custom markers for tagged events
// Y-axis: weight in kg
// Tooltip: show date, weight, body fat, measurement condition
// DataZoom: enable for mobile pinch-to-zoom
// MarkLine: for goal weight and start weight
// MarkPoint: for milestone events (开始运动日, 目标调整日)
Chart 2: Weekly/Monthly Weight Change Bar Chart
// Calculate weight delta per week/month
// Green bars for weight loss (negative values)
// Red bars for weight gain (positive values)
// Label on top of each bar showing exact value (e.g., "-0.6kg")
// Toggle between weekly/monthly view
Chart 3: Weight vs Body Fat Scatter Plot (Right side small chart)
// X-axis: weight (kg), Y-axis: body fat (%)
// Each point represents one measurement
// Color gradient based on date (older = lighter)
// Reference lines showing ideal trend (down-left diagonal)
// Tooltip showing date and values
Chart 4: Goal Progress Ring Chart (Top-right floating)
// Gauge/Pie chart showing progress percentage
// Inner text: "已减 3kg / 目标 5kg"
// Outer ring: progress arc (60% filled)
// Bottom text: "还需减 2kg,预计 11月30日完成"
// Color: green if on track, yellow if slow, red if off track
Chart 5: Summary Stats Cards (Above trend chart)
┌─────────────────────────────────────┐
│ Header: 体重管理 [录入] [目标设置] │
├─────────────────────────────────────┤
│ Summary Cards (3 cards in row) │
├──────────────────────┬──────────────┤
│ │ Goal Ring │
│ Weight Trend Chart │ (Floating) │
│ (50% height) │ │
│ │ │
├──────────────────────┴──────────────┤
│ Filter Bar: [7天][30天][90天][自定义]│
├─────────────────────────────────────┤
│ Weekly/Monthly Change Bar Chart │
├──────────────────────────────────────┤
│ Weight vs Body Fat Scatter Plot │
├─────────────────────────────────────┤
│ Anomaly Alerts & Suggestions │
└─────────────────────────────────────┘
LocalStorage Structure:
{
weightRecords: WeightRecord[],
weightGoal: WeightGoal,
pendingSync: { records: [], goal: null },
lastSyncTime: timestamp
}
Backend Sync Logic:
Create WeightDataService:
Planned Trend Line Calculation:
// Linear interpolation from start weight to target weight
planWeight = startWeight - (daysElapsed / totalDays) * totalWeightToLose
Anomaly Detection Algorithm:
// Check last 7 days for rapid changes
if (Math.abs(weeklyChange) > 2) {
alert = { type: 'rapid_change', severity: 'warning', message: '...' }
}
ETA Calculation:
// Based on average weekly change over last 4 weeks
avgWeeklyChange = sum(last4WeeksChanges) / 4
weeksRemaining = remainingWeight / Math.abs(avgWeeklyChange)
eta = new Date(now + weeksRemaining * 7 * 24 * 60 * 60 * 1000)
campus_health_app/docs/
└── weight-management-implementation.md (this document)
campus_health_app/frontend/campus-health-app/src/app/
├── modules/weight/
│ ├── weight.component.ts (main implementation)
│ ├── weight.component.html (template with all charts)
│ ├── weight.component.scss (mobile-first responsive styles)
│ └── models/
│ └── weight.models.ts (data interfaces)
└── services/
└── weight-data.service.ts (data management & sync)
GET /api/weight/records?from={date}&to={date}
POST /api/weight/records
PUT /api/weight/records/{id}
DELETE /api/weight/records/{id}
GET /api/weight/goal
POST /api/weight/goal
PUT /api/weight/goal