加入食谱与对应营养:在每日热量目标基础上,按早餐 25%、午餐 35%、晚餐 30%、加餐 10% 分配全天热量,给出示例一日食谱并标注每餐与全天的热量及蛋白质/脂肪/碳水,保证营养均衡
This commit is contained in:
+110
-17
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Flame, Scale, Footprints, Activity } from 'lucide-react';
|
import { Flame, Scale, Footprints, Activity, Target, Utensils, Coffee, Sun, Moon, Cookie } from 'lucide-react';
|
||||||
|
|
||||||
const stepBands = [
|
const stepBands = [
|
||||||
{ min: 0, max: 5000, factor: 1.2, label: '久坐(<5,000 步)' },
|
{ min: 0, max: 5000, factor: 1.2, label: '久坐(<5,000 步)' },
|
||||||
@@ -20,6 +20,53 @@ function bmiCategory(bmi) {
|
|||||||
return { text: '肥胖', color: 'text-red-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%',
|
||||||
|
items: [
|
||||||
|
{ name: '燕麦(干重)', amount: '60 g', kcal: 230, p: 8, f: 4, c: 40 },
|
||||||
|
{ name: '牛奶', amount: '250 ml', kcal: 160, p: 8, f: 8, c: 12 },
|
||||||
|
{ name: '鸡蛋', amount: '1 个', kcal: 70, p: 6, f: 5, c: 0 },
|
||||||
|
{ name: '香蕉', amount: '1 根(约 120 g)', kcal: 105, p: 1, f: 0, c: 27 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'lunch', meal: '午餐', icon: Sun, ratio: '约 35%',
|
||||||
|
items: [
|
||||||
|
{ name: '米饭', amount: '2 碗(约 300 g 熟)', kcal: 350, p: 7, f: 1, c: 77 },
|
||||||
|
{ name: '鸡胸肉', amount: '100 g', kcal: 140, p: 26, f: 3, c: 0 },
|
||||||
|
{ name: '清炒时蔬(含油 10 g)', amount: '200 g', kcal: 160, p: 5, f: 10, c: 12 },
|
||||||
|
{ name: '苹果', amount: '1 个(约 200 g)', kcal: 104, p: 1, f: 0, c: 28 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dinner', meal: '晚餐', icon: Moon, ratio: '约 30%',
|
||||||
|
items: [
|
||||||
|
{ name: '杂粮饭', amount: '1.5 碗(约 225 g 熟)', kcal: 255, p: 6, f: 2, c: 54 },
|
||||||
|
{ name: '三文鱼', amount: '100 g', kcal: 200, p: 20, f: 13, c: 0 },
|
||||||
|
{ name: '白灼蔬菜(含橄榄油 5 g)', amount: '200 g', kcal: 95, p: 5, f: 6, c: 8 },
|
||||||
|
{ name: '无糖酸奶', amount: '100 g', kcal: 70, p: 4, f: 3, c: 8 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'snack', meal: '加餐', icon: Cookie, ratio: '约 10%',
|
||||||
|
items: [
|
||||||
|
{ name: '混合坚果', amount: '15 g', kcal: 90, p: 3, f: 8, c: 3 },
|
||||||
|
{ name: '全麦面包', amount: '1 片', kcal: 90, p: 3, f: 1, c: 17 },
|
||||||
|
{ name: '蓝莓', amount: '100 g', kcal: 57, p: 1, f: 0, c: 14 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
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 menuTotals = menu.reduce((a, m) => {
|
||||||
|
const t = sumMacros(m.items);
|
||||||
|
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 });
|
||||||
|
|
||||||
export default function CalorieCalculator() {
|
export default function CalorieCalculator() {
|
||||||
const [sex, setSex] = useState('female');
|
const [sex, setSex] = useState('female');
|
||||||
const [age, setAge] = useState(30);
|
const [age, setAge] = useState(30);
|
||||||
@@ -39,12 +86,17 @@ export default function CalorieCalculator() {
|
|||||||
const tdee = bmr * band.factor;
|
const tdee = bmr * band.factor;
|
||||||
const round = n => Math.round(n);
|
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 inputCls = 'w-full px-3 py-2 rounded-lg border border-slate-200 focus:outline-none focus:ring-2 focus:ring-sky-400';
|
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 (
|
return (
|
||||||
<div className="max-w-2xl mx-auto p-6 bg-slate-50 rounded-2xl">
|
<div className="max-w-3xl mx-auto p-6 bg-slate-50 rounded-2xl">
|
||||||
<h2 className="text-2xl font-bold text-slate-800 mb-1">每日热量需求计算器</h2>
|
<h2 className="text-2xl font-bold text-slate-800 mb-1">每日热量需求与食谱计算器</h2>
|
||||||
<p className="text-sm text-slate-500 mb-6">Mifflin-St Jeor 公式 + 步数活动系数</p>
|
<p className="text-sm text-slate-500 mb-6">Mifflin-St Jeor 公式 + 步数活动系数 + 营养均衡一日食谱</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4 mb-6">
|
<div className="grid grid-cols-2 gap-4 mb-6">
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
@@ -79,45 +131,86 @@ export default function CalorieCalculator() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4 mb-6">
|
||||||
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
||||||
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Scale size={16} /> BMI</div>
|
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Scale size={16} /> BMI</div>
|
||||||
<div className="text-2xl font-bold text-slate-800">{bmi.toFixed(1)}</div>
|
<div className="text-2xl font-bold text-slate-800">{bmi.toFixed(1)}</div>
|
||||||
<div className={`text-sm font-medium ${cat.color}`}>{cat.text}</div>
|
<div className={`text-sm font-medium ${cat.color}`}>{cat.text}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
||||||
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Flame size={16} /> 基础代谢 BMR</div>
|
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Flame size={16} /> 基础代谢 BMR</div>
|
||||||
<div className="text-2xl font-bold text-slate-800">{round(bmr)}</div>
|
<div className="text-2xl font-bold text-slate-800">{round(bmr)}</div>
|
||||||
<div className="text-sm text-slate-400">千卡 / 天</div>
|
<div className="text-sm text-slate-400">千卡 / 天</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
<div className="bg-white rounded-xl p-4 border border-slate-100">
|
||||||
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Footprints size={16} /> 活动系数</div>
|
<div className="flex items-center gap-2 text-slate-500 text-sm mb-1"><Footprints size={16} /> 活动系数</div>
|
||||||
<div className="text-2xl font-bold text-slate-800">× {band.factor}</div>
|
<div className="text-2xl font-bold text-slate-800">× {band.factor}</div>
|
||||||
<div className="text-sm text-slate-400">{band.label}</div>
|
<div className="text-sm text-slate-400">{band.label}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-gradient-to-br from-emerald-500 to-teal-600 rounded-xl p-4 text-white">
|
<div className="bg-gradient-to-br from-emerald-500 to-teal-600 rounded-xl p-4 text-white">
|
||||||
<div className="flex items-center gap-2 text-emerald-50 text-sm mb-1"><Activity size={16} /> 每日总消耗 TDEE</div>
|
<div className="flex items-center gap-2 text-emerald-50 text-sm mb-1"><Activity size={16} /> 每日总消耗 TDEE</div>
|
||||||
<div className="text-3xl font-bold">{round(tdee)}</div>
|
<div className="text-3xl font-bold">{round(tdee)}</div>
|
||||||
<div className="text-sm text-emerald-50">千卡 / 天(维持体重)</div>
|
<div className="text-sm text-emerald-50">千卡 / 天(维持体重)</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="col-span-2 bg-white rounded-xl p-4 border border-slate-100">
|
<div className="bg-white rounded-xl p-4 border border-slate-100 mb-6">
|
||||||
<div className="text-sm font-medium text-slate-600 mb-2">建议目标热量</div>
|
<div className="flex items-center gap-2 text-slate-700 font-semibold mb-3"><Target size={16} /> 目标营养素(增重 {target} 千卡 / 天)</div>
|
||||||
<div className="flex justify-between text-sm py-1">
|
<div className="grid grid-cols-3 gap-3 text-center">
|
||||||
<span className="text-slate-500">增重(每周 +0.3 kg 左右)</span>
|
<div className="bg-sky-50 rounded-lg p-3">
|
||||||
<span className="font-semibold text-slate-800">{round(tdee + 300)} 千卡</span>
|
<div className="text-xs text-slate-500 mb-1">蛋白质(约 20%)</div>
|
||||||
|
<div className="text-lg font-bold text-sky-700">{proteinG} g</div>
|
||||||
|
<div className="text-xs text-slate-400">{weight} kg × 1.6 g</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-sm py-1">
|
<div className="bg-amber-50 rounded-lg p-3">
|
||||||
<span className="text-slate-500">维持体重</span>
|
<div className="text-xs text-slate-500 mb-1">脂肪(约 25%)</div>
|
||||||
<span className="font-semibold text-slate-800">{round(tdee)} 千卡</span>
|
<div className="text-lg font-bold text-amber-700">{fatG} g</div>
|
||||||
|
<div className="text-xs text-slate-400">总热量 × 25% ÷ 9</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-emerald-50 rounded-lg p-3">
|
||||||
|
<div className="text-xs text-slate-500 mb-1">碳水(约 55%)</div>
|
||||||
|
<div className="text-lg font-bold text-emerald-700">{carbG} g</div>
|
||||||
|
<div className="text-xs text-slate-400">剩余热量 ÷ 4</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-xs text-slate-400 mt-4">* 结果仅供参考,个体肌肉量、代谢与食物热效应等会影响实际需求。</p>
|
<div className="flex items-center gap-2 text-slate-700 font-semibold mb-3"><Utensils size={16} /> 一日食谱(示例,全天约 {menuTotals.kcal} 千卡)</div>
|
||||||
|
<div className="space-y-4">
|
||||||
|
{menu.map(m => {
|
||||||
|
const t = sumMacros(m.items);
|
||||||
|
const Icon = m.icon;
|
||||||
|
return (
|
||||||
|
<div key={m.key} className="bg-white rounded-xl p-4 border border-slate-100">
|
||||||
|
<div className="flex items-center justify-between mb-3">
|
||||||
|
<div className="flex items-center gap-2 font-semibold text-slate-800"><Icon size={16} /> {m.meal}</div>
|
||||||
|
<span className="text-xs text-slate-400">占全天 {m.ratio}</span>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
{m.items.map((it, i) => (
|
||||||
|
<div key={i} className="flex justify-between text-sm">
|
||||||
|
<span className="text-slate-700">{it.name} <span className="text-slate-400">{it.amount}</span></span>
|
||||||
|
<span className="text-slate-500">{it.kcal} 千卡</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 pt-3 border-t border-slate-100 flex justify-between text-sm text-slate-600">
|
||||||
|
<span className="font-medium">小计 {t.kcal} 千卡</span>
|
||||||
|
<span>蛋白 {t.p} g | 脂肪 {t.f} g | 碳水 {t.c} g</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 bg-gradient-to-br from-slate-700 to-slate-900 rounded-xl p-4 text-white">
|
||||||
|
<div className="text-sm text-slate-300 mb-1">全天合计</div>
|
||||||
|
<div className="text-2xl font-bold">{menuTotals.kcal} 千卡</div>
|
||||||
|
<div className="text-sm text-slate-300 mt-1">蛋白 {menuTotals.p} g | 脂肪 {menuTotals.f} g | 碳水 {menuTotals.c} g</div>
|
||||||
|
<div className="text-xs text-slate-400 mt-2">对照目标:{target} 千卡 · 蛋白 {proteinG} g · 脂肪 {fatG} g · 碳水 {carbG} g;份量可按需等比例增减。</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="text-xs text-slate-400 mt-4">* 示例食谱仅供参考,可同类替换(鸡胸肉 ↔ 鱼虾 ↔ 豆制品,米饭 ↔ 杂粮/薯类),保证每餐有主食、优质蛋白和蔬菜水果即可。</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user