diff --git a/src/NutritionCalculator.jsx b/src/NutritionCalculator.jsx
new file mode 100644
index 0000000..1a0f7d7
--- /dev/null
+++ b/src/NutritionCalculator.jsx
@@ -0,0 +1,344 @@
+import { useState, useMemo } from 'react';
+import { Activity, Flame, Target, AlertTriangle, Info, Footprints, Beef, Ruler } from 'lucide-react';
+
+// 年龄别 BMI 百分位(近似值,用于 <20 岁):[第5, 第85, 第95] 百分位
+const BMI_TABLE = {
+ male: {
+ 10: [14.2, 19.4, 22.6],
+ 11: [14.6, 20.2, 23.4],
+ 12: [15.0, 21.0, 24.2],
+ 13: [15.4, 21.8, 25.0],
+ 14: [16.0, 22.6, 25.8],
+ 15: [16.6, 23.3, 26.4],
+ 16: [17.2, 23.9, 27.0],
+ 17: [17.7, 24.4, 27.4],
+ 18: [18.0, 24.8, 27.8],
+ },
+ female: {
+ 10: [14.0, 19.5, 22.6],
+ 11: [14.5, 20.4, 23.5],
+ 12: [15.0, 21.4, 24.4],
+ 13: [15.5, 22.4, 25.2],
+ 14: [16.0, 23.2, 26.0],
+ 15: [16.4, 23.9, 26.6],
+ 16: [16.8, 24.4, 27.1],
+ 17: [17.1, 24.8, 27.5],
+ 18: [17.3, 25.0, 27.8],
+ },
+};
+
+const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
+const r0 = (n) => Math.round(n);
+const r1 = (n) => Math.round(n * 10) / 10;
+
+function palFromSteps(steps) {
+ return clamp(1.2 + (steps / 1000) * 0.04, 1.2, 1.95);
+}
+
+function classifyYouth(bmi, age, sex) {
+ const a = clamp(r0(age), 10, 18);
+ const [p5, p85, p95] = BMI_TABLE[sex][a];
+ if (bmi < p5) return { label: '偏低 / 偏瘦', color: 'text-sky-600', bg: 'bg-sky-50', border: 'border-sky-200', p5, p85, p95 };
+ if (bmi < p85) return { label: '健康范围', color: 'text-emerald-600', bg: 'bg-emerald-50', border: 'border-emerald-200', p5, p85, p95 };
+ if (bmi < p95) return { label: '偏重', color: 'text-amber-600', bg: 'bg-amber-50', border: 'border-amber-200', p5, p85, p95 };
+ return { label: '肥胖', color: 'text-rose-600', bg: 'bg-rose-50', border: 'border-rose-200', p5, p85, p95 };
+}
+
+function classifyAdult(bmi) {
+ if (bmi < 18.5) return { label: '偏瘦', color: 'text-sky-600', bg: 'bg-sky-50', border: 'border-sky-200', p5: 18.5, p85: 24, p95: 28 };
+ if (bmi < 24) return { label: '正常', color: 'text-emerald-600', bg: 'bg-emerald-50', border: 'border-emerald-200', p5: 18.5, p85: 24, p95: 28 };
+ if (bmi < 28) return { label: '超重', color: 'text-amber-600', bg: 'bg-amber-50', border: 'border-amber-200', p5: 18.5, p85: 24, p95: 28 };
+ return { label: '肥胖', color: 'text-rose-600', bg: 'bg-rose-50', border: 'border-rose-200', p5: 18.5, p85: 24, p95: 28 };
+}
+
+function StatCard({ icon, title, value, unit, sub, accent }) {
+ return (
+
+
+ {icon}
+ {title}
+
+
+ {value}
+ {unit}
+
+ {sub &&
{sub}
}
+
+ );
+}
+
+export default function NutritionCalculator() {
+ const [sex, setSex] = useState('male');
+ const [age, setAge] = useState(16);
+ const [height, setHeight] = useState(175);
+ const [weight, setWeight] = useState(55);
+ const [steps, setSteps] = useState(10000);
+
+ const r = useMemo(() => {
+ const H = Number(height) || 0;
+ const W = Number(weight) || 0;
+ const A = Number(age) || 0;
+ const S = Number(steps) || 0;
+
+ const hm = H / 100;
+ const bmi = hm > 0 && W > 0 ? W / (hm * hm) : 0;
+ const isYouth = A < 20;
+ const status = isYouth ? classifyYouth(bmi, A, sex) : classifyAdult(bmi);
+
+ // 基础代谢
+ const mifflin = 10 * W + 6.25 * H - 5 * A + (sex === 'male' ? 5 : -161);
+ let schofield;
+ if (sex === 'male') schofield = A < 18 ? 17.7 * W + 657 : 15.3 * W + 679;
+ else schofield = A < 18 ? 13.4 * W + 692 : 14.7 * W + 496;
+ const bmr = (mifflin + schofield) / 2;
+
+ // 活动系数
+ const pal = palFromSteps(S);
+ const tdee = bmr * pal;
+
+ // 增重目标
+ const gainLow = tdee + 300;
+ const gainHigh = tdee + 500;
+
+ // EER(IOM 青少年公式)交叉验证
+ let eer = null;
+ if (A >= 12 && A <= 18) {
+ const pa = pal <= 1.4 ? 1.13 : pal <= 1.6 ? 1.26 : 1.42;
+ eer = sex === 'male'
+ ? 88.5 - 61.9 * A + pa * (26.7 * W + 903 * hm)
+ : 135.3 - 30.8 * A + pa * (10 * W + 934 * hm) + 25;
+ }
+
+ // 蛋白质
+ const protLo = isYouth ? 1.5 * W : 1.2 * W;
+ const protHi = isYouth ? 1.8 * W : 1.6 * W;
+
+ // 目标体重:BMI 20–21
+ const targetLo = hm > 0 ? 20 * hm * hm : 0;
+ const targetHi = hm > 0 ? 21 * hm * hm : 0;
+ const healthyMin = hm > 0 ? status.p5 * hm * hm : 0;
+
+ const underweight = isYouth ? bmi < status.p5 : bmi < 18.5;
+
+ return {
+ bmi, status, isYouth, mifflin, schofield, bmr, pal, tdee,
+ gainLow, gainHigh, eer, protLo, protHi,
+ targetLo, targetHi, healthyMin, underweight,
+ };
+ }, [sex, age, height, weight, steps]);
+
+ const pct = (v) => clamp(((v - 13) / (30 - 13)) * 100, 0, 100);
+ const seg = (a, b) => Math.max(0, pct(b) - pct(a));
+
+ return (
+
+
+
+
+
+ {/* 输入区 */}
+
+
+
+
+
+
+
+
+
+
+ {[
+ { label: '年龄', value: age, set: setAge, unit: '岁', min: 6, max: 99 },
+ { label: '身高', value: height, set: setHeight, unit: 'cm', min: 100, max: 220 },
+ { label: '体重', value: weight, set: setWeight, unit: 'kg', min: 25, max: 150 },
+ ].map((f) => (
+
+
+
+ f.set(e.target.value === '' ? '' : Number(e.target.value))}
+ className="w-full text-sm text-slate-800 outline-none bg-transparent"
+ />
+ {f.unit}
+
+
+ ))}
+
+
+
+
+
+ {Number(steps).toLocaleString()} 步 · 活动系数 {r.pal.toFixed(2)}
+
+
setSteps(Number(e.target.value))}
+ className="w-full accent-emerald-500"
+ />
+
+
+
+ {/* BMI 卡片 */}
+
+
+
+
BMI(身体质量指数)
+
+ {r1(r.bmi)}
+ {r.status.label}
+
+
+
+ {r.isYouth ? `同龄${sex === 'male' ? '男生' : '女生'}参考:偏瘦 < ${r1(r.status.p5)},健康 ${r1(r.status.p5)}–${r1(r.status.p85)}` : '成人参考:偏瘦 < 18.5,正常 18.5–24'}
+
+
+
+
+
+ 1318.5242830
+
+
+
+ {/* 结果 */}
+
+ }
+ accent="text-orange-500"
+ title="基础代谢 BMR"
+ value={r0(r.bmr)}
+ unit="kcal"
+ sub={`Mifflin 公式 ${r0(r.mifflin)} · Schofield 公式 ${r0(r.schofield)}(取平均)`}
+ />
+ }
+ accent="text-emerald-500"
+ title="维持体重(当前活动量)"
+ value={`${r0(r.tdee - 100)}–${r0(r.tdee + 100)}`}
+ unit="kcal/天"
+ sub={`BMR × 活动系数 ${r.pal.toFixed(2)}${r.eer ? ` · EER 官方公式校核 ${r0(r.eer)}` : ''}`}
+ />
+ }
+ accent="text-emerald-600"
+ title={r.underweight ? '健康增重目标' : '增重参考(如需)'}
+ value={`${r0(r.gainLow)}–${r0(r.gainHigh)}`}
+ unit="kcal/天"
+ sub="维持热量 +300~500 kcal,每周增重约 0.25–0.5 kg"
+ />
+ }
+ accent="text-rose-500"
+ title="蛋白质目标"
+ value={`${r0(r.protLo)}–${r0(r.protHi)}`}
+ unit="g/天"
+ sub={r.isYouth ? '按 1.5–1.8 g/kg 计算(生长 + 肌肉)' : '按 1.2–1.6 g/kg 计算'}
+ />
+
+
+ {/* 目标体重 */}
+
+
+
+
目标体重参考
+
+
+
+
健康下限
+
{r1(r.healthyMin)}
+
kg
+
+
+
理想区间
+
{r1(r.targetLo)}–{r1(r.targetHi)}
+
kg
+
+
+
需要增加
+
+ {r.targetLo > Number(weight) ? `${r1(r.targetLo - Number(weight))}–${r1(r.targetHi - Number(weight))}` : '已达标'}
+
+
kg
+
+
+
+ “健康下限”为同年龄同性别第 5 百分位对应体重;“理想区间”按 BMI 20–21 计算,落在同龄健康范围中段。
+
+
+
+ {/* 提醒 */}
+ {(Number(age) < 18 || r.underweight) && (
+
+
+
+
+
请让家长带你去医院确认一次
+
+ {Number(age) < 18 ? '你还在生长发育期,' : ''}
+ {r.underweight ? '体重也落在同龄人偏低区间。' : ''}
+ 青少年偏瘦有时只是“晚长”,但也可能与肠胃吸收、甲状腺、压力或饮食行为有关,这些靠计算器判断不了。
+
+
建议挂儿科 / 青少年保健科,让医生用生长曲线评估;有条件再找临床营养师开一份个性化食谱。
+
+
+
+ )}
+
+ {/* 算法说明 */}
+
+
+
+
算法说明
+
+
+ - BMI = 体重(kg) ÷ 身高(m)²。未满 20 岁按年龄别百分位分类,不套用成人 18.5–24 的标准。
+ - BMR 取两个公式的平均:Mifflin-St Jeor(成人通用)+ Schofield(15–18 岁专用,更贴合发育期)。
+ - 活动系数由步数换算:PAL = 1.2 + 步数 ÷ 1000 × 0.04,上限 1.95。1 万步 ≈ 1.6。
+ - 维持热量 = BMR × PAL;增重热量 = 维持 + 300~500 kcal。
+ - 额外用 IOM 的 EER 青少年公式(已含生长所需能量)交叉校核,两套结果通常相差 10% 以内。
+ - 快走与慢走热量差可达 ±15%,这是主要误差来源。
+
+
+
+
+ 本工具仅供健康教育参考,不构成医疗建议。未满 18 岁或有体重异常,请咨询医生或注册营养师。
+
+
+
+ );
+}