Files
bmi-calculator/nutrition-calculator.html
T
class03m15 ea8fc625e6 新增「每日热量与七大营养素计算器」页面
- 以 BMI 正常但偏瘦、每天约 1 万步的活动量为前提,确定每日所需摄入热量
- 确定蛋白质、脂肪、碳水化合物三大产能营养素的供能比与每日克数
- 确定膳食纤维、维生素、矿物质、水四类不产能营养素的每日推荐量
- 确定以身高、体重、年龄、性别、步数、目标为输入、实时重算结果的参数化结构
2026-09-24 02:42:40 +00:00

253 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>每日热量与七大营养素计算器</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0; padding: 24px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
background: #f4f6f8; color: #1f2933; line-height: 1.6;
}
.wrap { max-width: 860px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: #6b7280; font-size: 13px; margin-bottom: 20px; }
.card {
background: #fff; border-radius: 12px; padding: 20px;
box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; color: #0f766e; letter-spacing: .5px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
label { display: block; font-size: 12px; color: #6b7280; margin-bottom: 4px; }
input[type=number], select {
width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px;
font-size: 14px; background: #fff; color: #1f2933;
}
input:focus, select:focus { outline: 2px solid #0d9488; outline-offset: -1px; border-color: #0d9488; }
.radios { display: flex; gap: 16px; padding-top: 4px; }
.radios label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #1f2933; margin: 0; cursor: pointer; }
.hero {
background: linear-gradient(135deg, #0f766e, #14b8a6); color: #fff;
border-radius: 12px; padding: 22px; margin-bottom: 18px;
}
.hero .big { font-size: 40px; font-weight: 700; line-height: 1.1; }
.hero .unit { font-size: 16px; font-weight: 400; opacity: .9; }
.hero .desc { font-size: 13px; opacity: .9; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.chip {
background: rgba(255,255,255,.16); border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.chip b { font-size: 16px; display: block; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid #eef1f4; }
th { font-size: 12px; color: #6b7280; font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; }
.tag-yes { background: #d1fae5; color: #065f46; }
.tag-no { background: #e5e7eb; color: #4b5563; }
.macro-bar { height: 10px; border-radius: 99px; overflow: hidden; display: flex; margin: 6px 0 16px; }
.macro-bar span { height: 100%; }
.legend { display: flex; gap: 18px; font-size: 12px; color: #4b5563; flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.note { font-size: 12.5px; color: #6b7280; margin-top: 14px; line-height: 1.7; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
@media (max-width: 560px) { .cols { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<div class="wrap">
<h1>每日热量与七大营养素计算器</h1>
<div class="sub">算法:Mifflin-St Jeor 基础代谢 + MET 法步行能耗 + DRIs 2023 供能比</div>
<div class="card">
<h2>① 输入参数</h2>
<div class="grid">
<div>
<label>性别</label>
<div class="radios">
<label><input type="radio" name="sex" value="female" checked>女</label>
<label><input type="radio" name="sex" value="male">男</label>
</div>
</div>
<div><label>年龄(岁)</label><input type="number" id="age" value="30" min="10" max="90"></div>
<div><label>身高(cm)</label><input type="number" id="height" value="165" min="120" max="220"></div>
<div><label>体重(kg)</label><input type="number" id="weight" value="51" min="30" max="200" step="0.1"></div>
<div><label>每日步数</label><input type="number" id="steps" value="10000" min="0" max="50000" step="500"></div>
<div>
<label>目标</label>
<select id="goal">
<option value="0" selected>维持体重</option>
<option value="200">小幅度增重(+200 kcal)</option>
<option value="300">增重(+300 kcal)</option>
<option value="-300">减脂(−300 kcal)</option>
</select>
</div>
</div>
</div>
<div class="hero">
<div class="desc">每日建议摄入热量</div>
<div class="big"><span id="targetKcal">1800</span> <span class="unit">kcal / 天</span></div>
<div class="chips">
<div class="chip">BMI<b id="bmi">18.7</b></div>
<div class="chip">基础代谢 BMR<b id="bmr">1230</b></div>
<div class="chip">步行能耗<b id="walk">300</b></div>
<div class="chip">总消耗 TDEE<b id="tdee">1776</b></div>
</div>
</div>
<div class="card">
<h2>② 三大产能营养素分配</h2>
<div class="macro-bar">
<span id="barP" style="background:#0d9488"></span>
<span id="barF" style="background:#f59e0b"></span>
<span id="barC" style="background:#3b82f6"></span>
</div>
<div class="legend" style="margin-bottom:14px">
<span><i class="dot" style="background:#0d9488"></i>蛋白质 16.7%</span>
<span><i class="dot" style="background:#f59e0b"></i>脂肪 27.5%</span>
<span><i class="dot" style="background:#3b82f6"></i>碳水化合物 55.8%</span>
</div>
<table>
<thead>
<tr><th>营养素</th><th class="num">每日推荐</th><th class="num">能量系数</th><th class="num">提供能量</th><th class="num">供能比</th></tr>
</thead>
<tbody id="macroBody"></tbody>
</table>
</div>
<div class="card">
<h2>③ 七大营养素全景</h2>
<table>
<thead>
<tr><th>#</th><th>营养素</th><th>是否产能</th><th class="num">每日推荐量</th><th class="num">能量</th></tr>
</thead>
<tbody id="sevenBody"></tbody>
</table>
<div class="note">
蛋白质/脂肪/碳水为产能营养素;膳食纤维 25–30 g 建议量,能量按 2 kcal/g 计(通常并入碳水账目);<br>
维生素、矿物质、水不产能,其参考摄入量见下表。
</div>
</div>
<div class="card">
<h2>④ 微量营养素参考摄入量</h2>
<div class="cols">
<table>
<thead><tr><th>维生素</th><th class="num">每日量</th></tr></thead>
<tbody>
<tr><td>维生素 A</td><td class="num">660 μg RAE</td></tr>
<tr><td>维生素 D</td><td class="num">10 μg</td></tr>
<tr><td>维生素 E</td><td class="num">14 mg α-TE</td></tr>
<tr><td>维生素 K</td><td class="num">80 μg</td></tr>
<tr><td>维生素 B1</td><td class="num">1.2 mg</td></tr>
<tr><td>维生素 B2</td><td class="num">1.2 mg</td></tr>
<tr><td>烟酸 (B3)</td><td class="num">12 mg NE</td></tr>
<tr><td>维生素 B6</td><td class="num">1.4 mg</td></tr>
<tr><td>叶酸 (B9)</td><td class="num">400 μg DFE</td></tr>
<tr><td>维生素 B12</td><td class="num">2.4 μg</td></tr>
<tr><td>维生素 C</td><td class="num">100 mg</td></tr>
</tbody>
</table>
<table>
<thead><tr><th>矿物质 / 水</th><th class="num">每日量</th></tr></thead>
<tbody>
<tr><td>钙</td><td class="num">800 mg</td></tr>
<tr><td>磷</td><td class="num">720 mg</td></tr>
<tr><td>钾</td><td class="num">2000 mg</td></tr>
<tr><td>钠</td><td class="num">1500 mg(盐&lt;5 g)</td></tr>
<tr><td>镁</td><td class="num">330 mg</td></tr>
<tr><td>铁</td><td class="num">18 mg</td></tr>
<tr><td>锌</td><td class="num">8.5 mg</td></tr>
<tr><td>碘</td><td class="num">120 μg</td></tr>
<tr><td>硒</td><td class="num">60 μg</td></tr>
<tr><td>铜 / 锰</td><td class="num">0.8 mg / 4.5 mg</td></tr>
<tr><td>水(饮水)</td><td class="num">1500–1700 mL</td></tr>
</tbody>
</table>
</div>
<div class="note">以上为成年女性 18–49 岁、轻身体活动水平参考值;男性或孕期/哺乳期需上调。公式仅算存在 ±10%~15% 个体差异,建议以 2–4 周体重变化实测校准。</div>
</div>
</div>
<script>
const P_RATIO = 0.167, F_RATIO = 0.275, C_RATIO = 0.558;
function fmt(n, d) { return Number(n).toFixed(d === undefined ? 0 : d); }
function calc() {
const sex = document.querySelector('input[name=sex]:checked').value;
const age = +document.getElementById('age').value || 30;
const h = +document.getElementById('height').value || 165;
const w = +document.getElementById('weight').value || 51;
const steps = +document.getElementById('steps').value || 0;
const goal = +document.getElementById('goal').value;
// 1. BMI
const bmi = w / Math.pow(h / 100, 2);
// 2. Mifflin-St Jeor BMR
let bmr;
if (sex === 'male') {
bmr = 10 * w + 6.25 * h - 5 * age + 5;
} else {
bmr = 10 * w + 6.25 * h - 5 * age - 161;
}
// 3. 步行能耗:MET 3.5,时间 = 步数 / 6000 小时(100 步/分)
const walkHours = steps / 6000;
const walkKcal = 3.5 * w * walkHours;
// 4. TDEE = BMR × 1.2(久坐基底)+ 步行能耗
const tdee = bmr * 1.2 + walkKcal;
// 5. 目标热量
const target = tdee + goal;
// 6. 三大产能营养素
const pG = target * P_RATIO / 4;
const fG = target * F_RATIO / 9;
const cG = target * C_RATIO / 4;
document.getElementById('bmi').textContent = fmt(bmi, 1);
document.getElementById('bmr').textContent = fmt(bmr, 0);
document.getElementById('walk').textContent = fmt(walkKcal, 0);
document.getElementById('tdee').textContent = fmt(tdee, 0);
document.getElementById('targetKcal').textContent = fmt(target, 0);
document.getElementById('barP').style.width = (P_RATIO * 100) + '%';
document.getElementById('barF').style.width = (F_RATIO * 100) + '%';
document.getElementById('barC').style.width = (C_RATIO * 100) + '%';
document.getElementById('macroBody').innerHTML = [
['蛋白质', fmt(pG, 0) + ' g(' + fmt(pG / w, 2) + ' g/kg)', '4 kcal/g', fmt(pG * 4, 0) + ' kcal', (P_RATIO * 100).toFixed(1) + '%'],
['脂肪', fmt(fG, 0) + ' g', '9 kcal/g', fmt(fG * 9, 0) + ' kcal', (F_RATIO * 100).toFixed(1) + '%'],
['碳水化合物', fmt(cG, 0) + ' g', '4 kcal/g', fmt(cG * 4, 0) + ' kcal', (C_RATIO * 100).toFixed(1) + '%']
].map(r => '<tr><td>' + r[0] + '</td><td class="num">' + r[1] + '</td><td class="num">' + r[2] + '</td><td class="num">' + r[3] + '</td><td class="num">' + r[4] + '</td></tr>').join('');
document.getElementById('sevenBody').innerHTML = [
['1', '蛋白质', 'tag-yes', '产能', fmt(pG, 0) + ' g', fmt(pG * 4, 0) + ' kcal'],
['2', '脂肪', 'tag-yes', '产能', fmt(fG, 0) + ' g', fmt(fG * 9, 0) + ' kcal'],
['3', '碳水化合物', 'tag-yes', '产能', fmt(cG, 0) + ' g', fmt(cG * 4, 0) + ' kcal'],
['4', '膳食纤维', 'tag-yes', '微弱', '25–30 g', '约 50–60 kcal'],
['5', '维生素', 'tag-no', '不产能', '见下表(13 种)', '0 kcal'],
['6', '矿物质', 'tag-no', '不产能', '见下表(14 种)', '0 kcal'],
['7', '水', 'tag-no', '不产能', '饮水 1500–1700 mL', '0 kcal']
].map(r =>
'<tr><td>' + r[0] + '</td><td>' + r[1] + '</td>' +
'<td><span class="tag ' + r[2] + '">' + r[3] + '</span></td>' +
'<td class="num">' + r[4] + '</td><td class="num">' + r[5] + '</td></tr>'
).join('');
}
document.querySelectorAll('input, select').forEach(el => {
el.addEventListener('input', calc);
el.addEventListener('change', calc);
});
calc();
</script>
</body>
</html>