Files

340 lines
14 KiB
HTML
Raw Permalink 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>每日热量需求计算器 | BMI · BMR · PAL · TDEE / EER</title>
<style>
:root {
--bg: #f4f7fb;
--card: #ffffff;
--pri: #2f6fed;
--pri-dark: #1f4fb8;
--txt: #1f2937;
--muted: #6b7280;
--line: #e5e7eb;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
background: var(--bg);
color: var(--txt);
line-height: 1.6;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 28px 16px 64px; }
h1 { font-size: 22px; margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.sub a { color: var(--pri); font-weight: 600; text-decoration: none; }
.card {
background: var(--card);
border-radius: 14px;
padding: 20px;
box-shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 10px 28px rgba(15, 23, 42, .05);
margin-bottom: 16px;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input, select {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 9px;
font-size: 15px;
background: #fff;
color: var(--txt);
font-family: inherit;
}
input:focus, select:focus {
outline: none;
border-color: var(--pri);
box-shadow: 0 0 0 3px rgba(47, 111, 237, .15);
}
button {
width: 100%;
margin-top: 18px;
padding: 13px;
border: none;
border-radius: 10px;
background: var(--pri);
color: #fff;
font-size: 16px;
font-weight: 600;
cursor: pointer;
font-family: inherit;
}
button:hover { background: var(--pri-dark); }
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; min-height: 18px; }
.result { display: none; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero .big { font-size: 38px; font-weight: 800; color: var(--pri); line-height: 1.1; }
.hero .cap { font-size: 13px; color: var(--muted); }
.tag { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.tag.thin { background: #dbeafe; color: #1e40af; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.over { background: #fef3c7; color: #92400e; }
.tag.obese { background: #fee2e2; color: #991b1b; }
.metric { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px dashed var(--line); gap: 12px; }
.metric:last-child { border-bottom: none; }
.metric .k { color: var(--muted); font-size: 14px; }
.metric .v { font-weight: 700; font-size: 16px; text-align: right; }
h2 { font-size: 15px; margin: 4px 0 12px; }
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.plan { border: 1px solid var(--line); border-radius: 10px; padding: 12px 8px; text-align: center; }
.plan.active { border-color: var(--pri); background: #f0f5ff; }
.plan.off { opacity: .45; }
.plan .t { font-size: 13px; color: var(--muted); }
.plan .n { font-size: 19px; font-weight: 800; }
.plan .u { font-size: 11px; color: var(--muted); }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin: 14px 0 6px; }
.bar span { display: block; height: 100%; }
.b1 { background: #93c5fd; width: 18.5%; }
.b2 { background: #86efac; width: 5.5%; }
.b3 { background: #fcd34d; width: 4%; }
.b4 { background: #fca5a5; flex: 1; }
.scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.footer-link { text-align: center; font-size: 13.5px; color: var(--muted); padding: 4px 0 8px; }
.footer-link a { color: var(--pri); font-weight: 600; text-decoration: none; }
@media (max-width: 520px) {
.grid, .plans { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="wrap">
<h1>每日热量需求计算器</h1>
<div class="sub">输入身高体重与日常活动量,估算 BMI、BMR、PAL 与 TDEE(成人)/ EER(青少年),并给出每日建议摄入热量。需要增重?看 <a href="meal-plan.html">一周增重食谱 →</a></div>
<div class="card">
<div class="grid">
<div>
<label for="sex">性别</label>
<select id="sex">
<option value="female">女</option>
<option value="male">男</option>
</select>
</div>
<div>
<label for="age">年龄(岁)</label>
<input id="age" type="number" min="9" max="100" step="1" value="16" />
</div>
<div>
<label for="height">身高(cm)</label>
<input id="height" type="number" min="100" max="230" step="0.1" placeholder="例如 162" />
</div>
<div>
<label for="weight">体重(kg)</label>
<input id="weight" type="number" min="25" max="200" step="0.1" placeholder="例如 45.5" />
</div>
<div class="full">
<label for="pal">日常活动量</label>
<select id="pal">
<option value="1.2" selected>几乎没有 / 久坐(基本不运动,以坐为主)</option>
<option value="1.375">轻度活动(每周 1–3 次轻量运动或经常散步)</option>
<option value="1.55">中度活动(每周 3–5 次中等强度运动)</option>
<option value="1.725">高度活动(每周 6–7 次高强度运动)</option>
<option value="1.9">极高活动(体力劳动或一天两练)</option>
</select>
</div>
</div>
<button id="calc">计算</button>
<div class="note" id="msg"></div>
</div>
<div class="card result" id="result">
<div class="hero">
<div>
<div class="cap">你的 BMI</div>
<div class="big" id="bmiVal">–</div>
</div>
<div style="text-align:right">
<div class="cap">体型判定</div>
<div id="bmiTag" class="tag ok" style="margin-top:6px">正常</div>
</div>
</div>
<div class="bar">
<span class="b1"></span><span class="b2"></span><span class="b3"></span><span class="b4"></span>
</div>
<div class="scale">
<span>偏瘦 18.5</span><span>正常 24</span><span>超重 28</span><span>肥胖</span>
</div>
<div class="note" id="bmiNote"></div>
<div style="margin-top:16px">
<div class="metric"><span class="k">基础代谢 BMR(Mifflin-St Jeor,参考)</span><span class="v" id="bmrVal">–</span></div>
<div class="metric"><span class="k" id="palLabel">活动系数 PAL</span><span class="v" id="palVal">–</span></div>
<div class="metric"><span class="k" id="tdeeLabel">每日总消耗 TDEE = BMR × PAL</span><span class="v" id="tdeeVal">–</span></div>
</div>
<div class="note" id="methodNote"></div>
<h2 style="margin-top:20px">每日建议摄入热量</h2>
<div class="plans">
<div class="plan" id="planCut">
<div class="t">减脂</div>
<div class="n" id="cutVal">–</div>
<div class="u">kcal / 天</div>
</div>
<div class="plan" id="planKeep">
<div class="t">维持体重</div>
<div class="n" id="keepVal">–</div>
<div class="u">kcal / 天</div>
</div>
<div class="plan" id="planGain">
<div class="t">增重</div>
<div class="n" id="gainVal">–</div>
<div class="u">kcal / 天</div>
</div>
</div>
<div class="note" id="advice"></div>
<div class="metric" style="margin-top:16px"><span class="k">蛋白质参考(1.2 g/kg)</span><span class="v" id="protVal">–</span></div>
<div class="metric"><span class="k">饮水参考(30 ml/kg)</span><span class="v" id="waterVal">–</span></div>
<div class="note">
公式:成人(≥18 岁)用 BMR(男 = 10×体重 + 6.25×身高 − 5×年龄 + 5;女 = …− 161)再乘 PAL;
青少年(9–18 岁)用 IOM EER 公式(已含 25 kcal 生长发育所需)。BMI 分级采用中国成人标准
(&lt;18.5 偏瘦,18.5–23.9 正常,24–27.9 超重,≥28 肥胖);未满 18 岁请以年龄别标准为准。
以上为估算值,个体差异约 ±10%。如有疾病或特殊状况,请咨询医生或注册营养师。
</div>
</div>
<div class="footer-link">想知道具体怎么吃?<a href="meal-plan.html">查看一周增重食谱 + 三大营养素拆分 →</a></div>
</div>
<script>
(function () {
var $ = function (id) { return document.getElementById(id); };
// 青少年(9–18 岁)IOM 公式:把活动量下拉框映射到 PA 等级
var PA_INDEX = { "1.2": 0, "1.375": 1, "1.55": 2, "1.725": 3, "1.9": 3 };
var PA_GIRL = [1.00, 1.16, 1.31, 1.56];
var PA_BOY = [1.00, 1.13, 1.26, 1.42];
var PA_NAME = ["久坐", "轻度活动", "中度活动", "高度活动"];
function round(n) { return Math.round(n); }
function classify(bmi) {
if (bmi < 18.5) return { label: "偏瘦", cls: "thin" };
if (bmi < 24) return { label: "正常", cls: "ok" };
if (bmi < 28) return { label: "超重", cls: "over" };
return { label: "肥胖", cls: "obese" };
}
function bmrMifflin(sex, w, h, age) {
var base = 10 * w + 6.25 * h - 5 * age;
return sex === "male" ? base + 5 : base - 161;
}
// IOM(美国医学研究院)9–18 岁青少年能量需要量,含 25 kcal 生长所需
function eerIOM(sex, age, w, h, paIdx) {
var pa = (sex === "male" ? PA_BOY : PA_GIRL)[paIdx];
if (sex === "male") {
return 88.5 - 61.9 * age + pa * (26.7 * w + 903 * (h / 100)) + 25;
}
return 135.3 - 30.8 * age + pa * (10.0 * w + 934 * (h / 100)) + 25;
}
function calc() {
var sex = $("sex").value;
var age = parseFloat($("age").value);
var h = parseFloat($("height").value);
var w = parseFloat($("weight").value);
var palKey = $("pal").value;
var pal = parseFloat(palKey);
var msg = $("msg");
if (!(age > 0) || !(h > 0) || !(w > 0)) {
msg.textContent = "请填写有效的年龄、身高与体重。";
$("result").style.display = "none";
return;
}
msg.textContent = "";
var isTeen = age < 18;
var bmi = w / Math.pow(h / 100, 2);
var bmr = bmrMifflin(sex, w, h, age);
var tdee, palText, bmiNote;
if (isTeen) {
var paIdx = PA_INDEX[palKey] || 0;
tdee = eerIOM(sex, age, w, h, paIdx);
var coef = (sex === "male" ? PA_BOY : PA_GIRL)[paIdx];
palText = PA_NAME[paIdx] + "(PA " + coef.toFixed(2) + ")";
$("tdeeLabel").textContent = "每日能量需要量 EER(IOM 青少年公式,含生长)";
$("palLabel").textContent = "活动等级(IOM PA)";
$("methodNote").textContent = "你未满 18 岁,因此采用 IOM 9–18 岁青少年 EER 公式(含 25 kcal 生长发育所需),比成人公式更贴合长身体阶段的真实需要。";
bmiNote = "注意:青少年(<18 岁)的 BMI 应按年龄别、性别标准(如中国 WS/T 586-2018)判定,此处成人分级仅供参考。";
} else {
tdee = bmr * pal;
palText = pal.toFixed(3);
$("tdeeLabel").textContent = "每日总消耗 TDEE = BMR × PAL";
$("palLabel").textContent = "活动系数 PAL";
$("methodNote").textContent = "采用成人公式:Mifflin-St Jeor 基础代谢率 × 活动系数 PAL。";
bmiNote = "";
}
var cut = tdee - 400;
var keep = tdee;
var gain = tdee + 300;
var c = classify(bmi);
$("bmiVal").textContent = bmi.toFixed(1);
var tag = $("bmiTag");
tag.textContent = c.label;
tag.className = "tag " + c.cls;
$("bmiNote").textContent = bmiNote;
$("bmrVal").textContent = round(bmr) + " kcal";
$("palVal").textContent = palText;
$("tdeeVal").textContent = round(tdee) + " kcal";
$("cutVal").textContent = round(cut);
$("keepVal").textContent = round(keep);
$("gainVal").textContent = round(gain);
$("planCut").className = "plan";
$("planKeep").className = "plan";
$("planGain").className = "plan";
var advice = "";
if (bmi < 18.5) {
$("planGain").className = "plan active";
advice = "你的 BMI 低于 18.5(偏瘦)。建议以「增重 / 长身体」为目标,在需要量基础上每天多吃约 300 kcal,配合力量训练与充足蛋白。";
} else if (bmi < 19.5) {
$("planGain").className = "plan active";
advice = "BMI 虽在正常范围,但已贴近偏瘦边缘,建议按「需要量 ~ 需要量+300 kcal」来吃,避免继续掉秤。";
} else if (bmi < 24) {
$("planKeep").className = "plan active";
advice = "BMI 处于正常范围,按「维持体重」摄入即可。";
} else if (bmi < 28) {
$("planCut").className = "plan active";
advice = "BMI 属于超重,建议以「减脂」为目标(需要量减 300–500 kcal),并配合运动。";
} else {
$("planCut").className = "plan active";
advice = "BMI 属于肥胖,建议在专业指导下控制热量并增加运动。";
}
if (isTeen) {
advice += " 你还是青少年,正处于生长发育期,不建议节食减重;如需调整体重,请在家长与医生/营养师指导下进行。";
$("planCut").className = "plan off";
}
$("advice").textContent = advice;
$("protVal").textContent = (w * 1.2).toFixed(0) + " g";
$("waterVal").textContent = (w * 30 / 1000).toFixed(1) + " L";
$("result").style.display = "block";
}
$("calc").addEventListener("click", calc);
["age", "height", "weight", "sex", "pal"].forEach(function (id) {
$(id).addEventListener("change", function () {
if ($("result").style.display === "block") calc();
});
});
})();
</script>
</body>
</html>