import { useState } from 'react'; import { Flame, Scale, Footprints, Activity, Target, Utensils, Coffee, Sun, Moon, Cookie, RotateCcw } from 'lucide-react'; const stepBands = [ { min: 0, max: 5000, factor: 1.2, label: '久坐(<5,000 步)' }, { min: 5000, max: 7500, factor: 1.375, label: '轻度活动(5,000–7,499 步)' }, { min: 7500, max: 10000, factor: 1.55, label: '中度活动(7,500–9,999 步)' }, { min: 10000, max: 12500, factor: 1.65, label: '高度活动(10,000–12,499 步)' }, { min: 12500, max: Infinity, factor: 1.8, label: '非常活跃(≥12,500 步)' }, ]; function bandFor(steps) { return stepBands.find(b => steps >= b.min && steps < b.max) || stepBands[stepBands.length - 1]; } function bmiCategory(bmi) { if (bmi < 18.5) return { text: '偏瘦', color: 'text-amber-600' }; if (bmi < 24) return { text: '正常', color: 'text-emerald-600' }; if (bmi < 28) return { text: '超重', color: 'text-orange-600' }; return { text: '肥胖', color: 'text-red-600' }; } // 每餐拆成「可替换项」,每项给出若干同类食材,点选后实时重算。 // 默认选第一个选项,全天约 2,176 千卡,蛋白/脂肪/碳水约 104/64/300 g(约 19% / 26% / 55%) const menu = [ { key: 'breakfast', meal: '早餐', icon: Coffee, ratio: '约 25%', slots: [ { id: 'b-staple', label: '主食', options: [ { name: '燕麦(干重)', amount: '60 g', kcal: 230, p: 8, f: 4, c: 40 }, { name: '全麦面包', amount: '2 片', kcal: 180, p: 6, f: 2, c: 34 }, { name: '杂粮粥', amount: '1 碗', kcal: 180, p: 4, f: 1, c: 38 }, { name: '蒸红薯', amount: '200 g', kcal: 180, p: 2, f: 0, c: 42 }, ], }, { id: 'b-dairy', label: '奶 / 饮品', options: [ { name: '牛奶', amount: '250 ml', kcal: 160, p: 8, f: 8, c: 12 }, { name: '无糖豆浆', amount: '300 ml', kcal: 90, p: 9, f: 5, c: 4 }, { name: '无糖酸奶', amount: '200 g', kcal: 140, p: 8, f: 6, c: 16 }, ], }, { id: 'b-protein', label: '蛋白', options: [ { name: '鸡蛋', amount: '1 个', kcal: 70, p: 6, f: 5, c: 0 }, { name: '水煮蛋', amount: '1 个', kcal: 78, p: 6, f: 5, c: 1 }, { name: '奶酪', amount: '20 g', kcal: 66, p: 5, f: 5, c: 1 }, ], }, { id: 'b-fruit', label: '水果', options: [ { name: '香蕉', amount: '1 根(约 120 g)', kcal: 105, p: 1, f: 0, c: 27 }, { name: '苹果', amount: '1 个(约 200 g)', kcal: 104, p: 1, f: 0, c: 28 }, { name: '蓝莓', amount: '100 g', kcal: 57, p: 1, f: 0, c: 14 }, { name: '橙子', amount: '1 个(约 200 g)', kcal: 90, p: 2, f: 0, c: 22 }, ], }, ], }, { key: 'lunch', meal: '午餐', icon: Sun, ratio: '约 35%', slots: [ { id: 'l-staple', label: '主食', options: [ { name: '米饭', amount: '2 碗(约 300 g 熟)', kcal: 350, p: 7, f: 1, c: 77 }, { name: '杂粮饭', amount: '2 碗(约 300 g 熟)', kcal: 340, p: 8, f: 2, c: 72 }, { name: '面条(熟)', amount: '300 g', kcal: 330, p: 10, f: 1, c: 70 }, { name: '玉米', amount: '2 根', kcal: 220, p: 8, f: 2, c: 46 }, ], }, { id: 'l-protein', label: '优质蛋白', options: [ { name: '鸡胸肉', amount: '100 g', kcal: 140, p: 26, f: 3, c: 0 }, { name: '三文鱼', amount: '100 g', kcal: 200, p: 20, f: 13, c: 0 }, { name: '瘦牛肉', amount: '100 g', kcal: 180, p: 22, f: 9, c: 0 }, { name: '虾仁', amount: '120 g', kcal: 110, p: 22, f: 1, c: 1 }, { name: '北豆腐', amount: '150 g', kcal: 120, p: 12, f: 7, c: 4 }, ], }, { id: 'l-veg', label: '蔬菜', options: [ { name: '清炒时蔬(含油 10 g)', amount: '200 g', kcal: 160, p: 5, f: 10, c: 12 }, { name: '白灼西兰花', amount: '200 g', kcal: 70, p: 6, f: 1, c: 12 }, { name: '蒜蓉菠菜', amount: '200 g', kcal: 60, p: 5, f: 2, c: 8 }, { name: '凉拌生菜', amount: '200 g', kcal: 40, p: 3, f: 1, c: 6 }, ], }, { id: 'l-fruit', label: '水果', options: [ { name: '苹果', amount: '1 个(约 200 g)', kcal: 104, p: 1, f: 0, c: 28 }, { name: '橙子', amount: '1 个(约 200 g)', kcal: 90, p: 2, f: 0, c: 22 }, { name: '猕猴桃', amount: '2 个', kcal: 90, p: 2, f: 1, c: 21 }, ], }, ], }, { key: 'dinner', meal: '晚餐', icon: Moon, ratio: '约 30%', slots: [ { id: 'd-staple', label: '主食', options: [ { name: '杂粮饭', amount: '1.5 碗(约 225 g 熟)', kcal: 255, p: 6, f: 2, c: 54 }, { name: '米饭', amount: '1.5 碗(约 225 g 熟)', kcal: 260, p: 5, f: 1, c: 57 }, { name: '蒸南瓜', amount: '250 g', kcal: 110, p: 3, f: 0, c: 25 }, { name: '荞麦面(熟)', amount: '200 g', kcal: 220, p: 8, f: 1, c: 45 }, ], }, { id: 'd-protein', label: '优质蛋白', options: [ { name: '三文鱼', amount: '100 g', kcal: 200, p: 20, f: 13, c: 0 }, { name: '鸡腿肉(去皮)', amount: '100 g', kcal: 150, p: 20, f: 7, c: 0 }, { name: '鳕鱼', amount: '120 g', kcal: 110, p: 24, f: 1, c: 0 }, { name: '鸡蛋', amount: '2 个', kcal: 140, p: 12, f: 10, c: 1 }, { name: '豆腐', amount: '150 g', kcal: 120, p: 12, f: 7, c: 4 }, ], }, { id: 'd-veg', label: '蔬菜', options: [ { name: '白灼蔬菜(含橄榄油 5 g)', amount: '200 g', kcal: 95, p: 5, f: 6, c: 8 }, { name: '清炒小白菜', amount: '200 g', kcal: 80, p: 4, f: 5, c: 6 }, { name: '番茄炒蘑菇', amount: '200 g', kcal: 60, p: 4, f: 2, c: 8 }, ], }, { id: 'd-dairy', label: '奶制品', options: [ { name: '无糖酸奶', amount: '100 g', kcal: 70, p: 4, f: 3, c: 8 }, { name: '牛奶', amount: '200 ml', kcal: 128, p: 6, f: 6, c: 10 }, { name: '无糖豆浆', amount: '200 ml', kcal: 60, p: 6, f: 3, c: 3 }, ], }, ], }, { key: 'snack', meal: '加餐', icon: Cookie, ratio: '约 10%', slots: [ { id: 's-nut', label: '坚果', options: [ { name: '混合坚果', amount: '15 g', kcal: 90, p: 3, f: 8, c: 3 }, { name: '核桃', amount: '20 g', kcal: 130, p: 3, f: 13, c: 3 }, { name: '杏仁', amount: '20 g', kcal: 116, p: 4, f: 10, c: 4 }, ], }, { id: 's-staple', label: '加餐主食', options: [ { name: '全麦面包', amount: '1 片', kcal: 90, p: 3, f: 1, c: 17 }, { name: '苏打饼干', amount: '3 片', kcal: 90, p: 2, f: 3, c: 14 }, { name: '燕麦棒', amount: '1 根', kcal: 100, p: 3, f: 3, c: 16 }, ], }, { id: 's-fruit', label: '水果', options: [ { name: '蓝莓', amount: '100 g', kcal: 57, p: 1, f: 0, c: 14 }, { name: '圣女果', amount: '150 g', kcal: 30, p: 1, f: 0, c: 6 }, { name: '葡萄', amount: '100 g', kcal: 70, p: 1, f: 0, c: 18 }, ], }, ], }, ]; const sumMacros = items => items.reduce((a, it) => ({ kcal: a.kcal + it.kcal, p: a.p + it.p, f: a.f + it.f, c: a.c + it.c }), { kcal: 0, p: 0, f: 0, c: 0 }); const buildDefaults = () => { const c = {}; menu.forEach(m => m.slots.forEach(s => { c[s.id] = 0; })); return c; }; export default function CalorieCalculator() { const [sex, setSex] = useState('female'); const [age, setAge] = useState(30); const [height, setHeight] = useState(164); const [weight, setWeight] = useState(51); const [steps, setSteps] = useState(10000); const [choices, setChoices] = useState(buildDefaults); const hM = height / 100; const bmi = hM > 0 ? weight / (hM * hM) : 0; const cat = bmiCategory(bmi); const bmr = sex === 'male' ? 10 * weight + 6.25 * height - 5 * age + 5 : 10 * weight + 6.25 * height - 5 * age - 161; const band = bandFor(steps); const tdee = bmr * band.factor; const round = n => Math.round(n); const target = round(tdee + 300); const proteinG = round(weight * 1.6); const fatG = round((target * 0.25) / 9); const carbG = Math.max(round((target - proteinG * 4 - fatG * 9) / 4), 0); const selectedOf = slot => slot.options[choices[slot.id]] || slot.options[0]; const mealTotals = m => sumMacros(m.slots.map(selectedOf)); const dayTotals = menu.reduce((a, m) => { const t = mealTotals(m); return { kcal: a.kcal + t.kcal, p: a.p + t.p, f: a.f + t.f, c: a.c + t.c }; }, { kcal: 0, p: 0, f: 0, c: 0 }); const inputCls = 'w-full px-3 py-2 rounded-lg border border-slate-200 focus:outline-none focus:ring-2 focus:ring-sky-400'; return (

每日热量需求与食谱计算器

Mifflin-St Jeor 公式 + 步数活动系数 + 可按口味替换的一日食谱

setAge(Number(e.target.value))} className={inputCls} />
setHeight(Number(e.target.value))} className={inputCls} />
setWeight(Number(e.target.value))} className={inputCls} />
setSteps(Number(e.target.value))} className={inputCls} />
BMI
{bmi.toFixed(1)}
{cat.text}
基础代谢 BMR
{round(bmr)}
千卡 / 天
活动系数
× {band.factor}
{band.label}
每日总消耗 TDEE
{round(tdee)}
千卡 / 天(维持体重)
目标营养素(增重 {target} 千卡 / 天)
蛋白质(约 20%)
{proteinG} g
{weight} kg × 1.6 g
脂肪(约 25%)
{fatG} g
总热量 × 25% ÷ 9
碳水(约 55%)
{carbG} g
剩余热量 ÷ 4
一日食谱(点选替换,全天约 {dayTotals.kcal} 千卡)
{menu.map(m => { const t = mealTotals(m); const Icon = m.icon; return (
{m.meal}
占全天 {m.ratio}
{m.slots.map(slot => { const sel = selectedOf(slot); return (
{slot.label}
{slot.options.map((opt, i) => ( ))}
已选:{sel.name} {sel.amount} · {sel.kcal} 千卡
); })}
小计 {t.kcal} 千卡 蛋白 {t.p} g | 脂肪 {t.f} g | 碳水 {t.c} g
); })}
全天合计
{dayTotals.kcal} 千卡
蛋白 {dayTotals.p} g | 脂肪 {dayTotals.f} g | 碳水 {dayTotals.c} g
对照目标:{target} 千卡 · 蛋白 {proteinG} g · 脂肪 {fatG} g · 碳水 {carbG} g;换食材后合计会同步变化,可按需再增减份量。

* 同类食材热量接近,可放心互换;示例仅供参考,保证每餐有主食、优质蛋白和蔬菜水果即可。

); }