From 36bbd909bff2c6f96e43bae60eb5a8ce694c473e Mon Sep 17 00:00:00 2001 From: "liweiliang0905@gmail.com" Date: Tue, 27 Jan 2026 16:27:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E8=BF=90=E5=8A=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=20BMI=20=E5=81=A5=E5=BA=B7=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在运动页面统计卡片区域下方添加 BMI 分析功能: - 显示当前体重、BMI 值和健康状态 - 可视化 BMI 范围指示条 (偏瘦/正常/偏重/肥胖) - 目标达成预估 (目标体重、目标BMI、距离目标、预计天数) - 计算依据展示 (TDEE、摄入、运动卡路里) - 数据不足时引导用户完善设置 Co-Authored-By: Claude Opus 4.5 --- src/vitals/web/app.py | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/vitals/web/app.py b/src/vitals/web/app.py index 3d5c79d..b39c13c 100644 --- a/src/vitals/web/app.py +++ b/src/vitals/web/app.py @@ -4758,6 +4758,17 @@ def get_exercise_page_html() -> str: + +
+
+

BMI 健康分析

+ 设置目标 → +
+
+
加载中...
+
+
+

近 30 天运动时长趋势

@@ -4941,6 +4952,87 @@ def get_exercise_page_html() -> str: } } + async function loadBmiAnalysis() { + try { + const res = await fetch('/api/bmi/analysis'); + const data = await res.json(); + const container = document.getElementById('bmi-content'); + + if (!data.current_bmi) { + container.innerHTML = ` +
+

数据不足

+

请完善身高、体重信息以启用 BMI 分析

+ 去设置 +
+ `; + return; + } + + const statusColor = data.bmi_status?.color || '#94A3B8'; + const bmiPercent = Math.min(Math.max((data.current_bmi - 15) / 20 * 100, 0), 100); + + container.innerHTML = ` +
+
+
当前体重
+
${data.current_weight || '--'} kg
+
+
+
当前 BMI
+
${data.current_bmi || '--'}
+
+
+
BMI 状态
+
${data.bmi_status?.status || '--'}
+
(${data.bmi_status?.range || ''})
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
偏瘦 <18.5
+
正常
+
偏重
+
肥胖 >28
+
+
+ +
+
目标达成预估
+
+
目标体重: ${data.target_weight} kg
+
目标 BMI: ${data.target_bmi}
+
距离目标: ${data.weight_diff > 0 ? '-' : '+'}${Math.abs(data.weight_diff || 0)} kg
+
预估达成: ${data.estimated_days ? '约 ' + data.estimated_days + ' 天' : '数据不足'}
+
+ ${data.calculation_basis ? ` +
+ 计算依据: 近30天平均每日净消耗 ${data.calculation_basis.daily_deficit} 卡 + (TDEE ${data.calculation_basis.tdee} - 摄入 ${data.calculation_basis.avg_intake} + 运动 ${data.calculation_basis.avg_exercise}) +
+ ` : ''} +
+ +
+ 健康减重建议每周 0.5-1 kg +
+ `; + } catch (e) { + console.error('加载 BMI 分析失败:', e); + document.getElementById('bmi-content').innerHTML = '
加载失败
'; + } + } + async function loadExerciseList() { try { const res = await fetch('/api/exercises?days=30'); @@ -5027,6 +5119,7 @@ def get_exercise_page_html() -> str: loadExerciseStats(); loadExerciseList(); loadTodaySteps(); + loadBmiAnalysis(); async function loadTodaySteps() { try {