新增每日热量计算器(BMI 判定 + 每日热量 + 七大营养素)

本次我做出的决策:
- 制作一个自动计算热量的网页小工具
- 以本人数据作为默认输入:男 / 22 岁 / 身高 180cm / 体重 122kg
- 活动量按每天约 1 万步设置
- 目标设为减重
- 在工具中加入 BMI 计算与判定
- 在工具中加入每日七大营养素需求
This commit is contained in:
2026-09-24 00:40:23 +00:00
parent 1454870a8e
commit 31c9ab8974
+690
View File
@@ -0,0 +1,690 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>每日热量计算器 · BMI 与七大营养素</title>
<style>
:root{
--bg:#eef1f6;
--card:#ffffff;
--ink:#1b2430;
--muted:#6c7a8c;
--line:#e2e8f0;
--accent:#0f766e;
--accent-soft:#e5f4f1;
--amber:#b45309;
--amber-soft:#fef6e4;
--red:#b91c1c;
--red-soft:#fdecec;
}
*{box-sizing:border-box}
body{
margin:0;
padding:28px 16px 72px;
background:var(--bg);
color:var(--ink);
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
-webkit-font-smoothing:antialiased;
font-size:15px;
line-height:1.6;
}
.wrap{max-width:940px;margin:0 auto}
header{margin-bottom:20px}
h1{font-size:24px;margin:0 0 4px;letter-spacing:-.3px}
header p{margin:0;color:var(--muted);font-size:13.5px}
.grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
@media(max-width:760px){.grid{grid-template-columns:1fr}}
.card{
background:var(--card);
border-radius:16px;
padding:20px;
box-shadow:0 1px 2px rgba(16,24,40,.04),0 8px 24px rgba(16,24,40,.05);
margin-bottom:16px;
}
h2{font-size:14px;text-transform:uppercase;letter-spacing:.8px;color:var(--muted);margin:0 0 16px;font-weight:600}
.field{margin-bottom:16px}
.field:last-child{margin-bottom:0}
.field > label,.field > .label{display:block;font-size:13px;color:var(--muted);margin-bottom:7px;font-weight:500}
input[type=number],select{
width:100%;
padding:11px 12px;
font-size:15px;
font-family:inherit;
color:var(--ink);
background:#fbfcfe;
border:1px solid var(--line);
border-radius:10px;
outline:none;
transition:border-color .15s,box-shadow .15s;
}
input[type=number]:focus,select:focus{
border-color:var(--accent);
box-shadow:0 0 0 3px var(--accent-soft);
background:#fff;
}
.row3{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-bottom:16px}
.chips{display:flex;gap:8px;flex-wrap:wrap}
.chips label{
flex:1;
min-width:64px;
text-align:center;
padding:10px 8px;
font-size:14px;
border:1px solid var(--line);
border-radius:10px;
background:#fbfcfe;
cursor:pointer;
user-select:none;
transition:.15s;
white-space:nowrap;
}
.chips label:hover{border-color:#c7d2dd}
.chips label.active{
border-color:var(--accent);
background:var(--accent-soft);
color:var(--accent);
font-weight:600;
}
/* 结果区 */
.big{text-align:center;padding:6px 0 18px;border-bottom:1px solid var(--line);margin-bottom:18px}
.big-label{font-size:13px;color:var(--muted);letter-spacing:.5px}
.big-value{font-size:52px;font-weight:700;line-height:1.1;letter-spacing:-1.5px;color:var(--accent);margin:4px 0 2px;font-variant-numeric:tabular-nums}
.big-value .unit{font-size:17px;font-weight:600;color:var(--muted);margin-left:6px;letter-spacing:0}
.big-note{font-size:13px;color:var(--muted)}
.stats{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-bottom:18px}
.stat{background:#fafbfd;border:1px solid var(--line);border-radius:12px;padding:11px 10px;text-align:center}
.stat span{display:block;font-size:11.5px;color:var(--muted);margin-bottom:3px}
.stat strong{display:block;font-size:19px;font-variant-numeric:tabular-nums;letter-spacing:-.4px}
.stat em{font-style:normal;font-size:11px;color:var(--muted)}
/* BMI 条 */
.bmibar{position:relative;display:flex;height:9px;border-radius:6px;overflow:hidden;margin-bottom:6px}
.bmibar .seg{display:block;height:100%}
.s1{background:#93c5fd}
.s2{background:#6ee7b7}
.s3{background:#fbbf24}
.s4{background:#f87171}
.marker{
position:absolute;top:-5px;width:3px;height:19px;
background:var(--ink);border-radius:2px;transform:translateX(-50%);
transition:left .25s ease;
box-shadow:0 0 0 2px #fff;
}
.bmibar-labels{display:flex;font-size:10.5px;color:var(--muted);text-align:center}
.bmibar-labels span{display:block}
.bmimeta{display:flex;justify-content:space-between;font-size:12px;color:var(--muted);margin-top:10px;gap:12px;flex-wrap:wrap}
/* 七大营养素 */
.nutri{display:grid}
.nrow{padding:13px 0;border-bottom:1px solid var(--line);display:flex;gap:13px;align-items:flex-start}
.nrow:first-child{padding-top:0}
.nrow:last-child{border-bottom:none;padding-bottom:0}
.nicon{flex:0 0 32px;height:32px;border-radius:9px;display:flex;align-items:center;justify-content:center;font-size:15px;line-height:1}
.nmain{flex:1;min-width:0}
.ntop{display:flex;justify-content:space-between;align-items:baseline;gap:10px;flex-wrap:wrap}
.nname{font-size:14.5px;font-weight:600}
.nname small{font-weight:400;color:var(--muted);font-size:11.5px;margin-left:5px}
.nval{font-size:15px;font-weight:700;font-variant-numeric:tabular-nums;color:var(--accent);white-space:nowrap}
.nsrc{font-size:12.5px;color:var(--muted);margin-top:3px;line-height:1.6}
.nchips{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}
.nchip{font-size:11.5px;background:#f6f8fb;border:1px solid var(--line);border-radius:6px;padding:3px 7px;color:#3b4b60;white-space:nowrap}
.nchip b{color:var(--ink);font-weight:600}
/* 提示 */
.alert{
border-radius:12px;
padding:12px 14px;
font-size:13px;
line-height:1.65;
margin-top:16px;
display:none;
}
.alert.show{display:block}
.alert.warn{background:var(--amber-soft);color:var(--amber);border:1px solid #f3ddb0}
.alert.danger{background:var(--red-soft);color:var(--red);border:1px solid #f5c9c9}
.alert.info{background:var(--accent-soft);color:var(--accent);border:1px solid #c3e6e0}
/* 步骤 */
.steps{display:grid;gap:10px}
.step{display:flex;gap:12px;font-size:14px;line-height:1.6}
.step .n{
flex:0 0 24px;height:24px;border-radius:50%;
background:var(--accent-soft);color:var(--accent);
font-size:12px;font-weight:700;
display:flex;align-items:center;justify-content:center;
margin-top:1px;
}
.step .body{flex:1}
.step .body b{font-variant-numeric:tabular-nums}
.step code{
display:block;
background:#f6f8fb;
border:1px solid var(--line);
border-radius:8px;
padding:8px 10px;
margin-top:5px;
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
font-size:12.5px;
color:#3b4b60;
overflow-x:auto;
}
.disclaimer{font-size:12px;color:var(--muted);line-height:1.7;text-align:center;margin:8px auto 0;max-width:700px}
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>每日热量计算器</h1>
<p>Mifflin-St Jeor 公式 · BMI 判定 · 七大营养素 · 自动校正肥胖体重偏差</p>
</header>
<div class="grid">
<!-- ======== 输入 ======== -->
<section class="card">
<h2>你的数据</h2>
<div class="field">
<span class="label">性别</span>
<div class="chips" id="genderChips">
<label data-value="male" class="active">男</label>
<label data-value="female">女</label>
</div>
</div>
<div class="row3">
<div class="field">
<label for="age">年龄</label>
<input id="age" type="number" value="22" min="10" max="100" step="1">
</div>
<div class="field">
<label for="height">身高 cm</label>
<input id="height" type="number" value="180" min="120" max="230" step="0.5">
</div>
<div class="field">
<label for="weight">体重 kg</label>
<input id="weight" type="number" value="122" min="30" max="250" step="0.1">
</div>
</div>
<div class="field">
<label for="activity">日常活动量(按步数选)</label>
<select id="activity">
<option value="1.2">久坐 · 几乎不运动,每天少于 3000 步</option>
<option value="1.375">轻度 · 每周运动 1–3 次,约 3000–8000 步</option>
<option value="1.55" selected>中度 · 每天约 8000–12000 步</option>
<option value="1.725">高度 · 每天超过 12000 步或有规律训练</option>
<option value="1.9">极高 · 体力劳动 / 职业运动员</option>
</select>
</div>
<div class="field">
<span class="label">目标</span>
<div class="chips" id="goalChips">
<label data-value="lose" class="active">减重</label>
<label data-value="maintain">维持</label>
<label data-value="gain">增重</label>
</div>
</div>
<div class="field" id="rateField">
<span class="label">减重速度</span>
<div class="chips" id="rateChips">
<label data-value="0.25">0.25 kg/周</label>
<label data-value="0.5" class="active">0.5 kg/周</label>
<label data-value="0.75">0.75 kg/周</label>
<label data-value="1">1 kg/周</label>
</div>
</div>
</section>
<!-- ======== 结果 ======== -->
<section class="card">
<div class="big">
<span class="big-label" id="targetLabel">每日建议摄入</span>
<div class="big-value"><span id="targetVal">—</span><span class="unit">kcal</span></div>
<div class="big-note" id="targetNote"></div>
</div>
<div class="stats">
<div class="stat">
<span>BMI</span>
<strong id="bmiVal">—</strong>
<em id="bmiTag">—</em>
</div>
<div class="stat">
<span>基础代谢</span>
<strong id="bmrVal">—</strong>
<em>kcal</em>
</div>
<div class="stat">
<span>维持热量</span>
<strong id="tdeeVal">—</strong>
<em>kcal</em>
</div>
</div>
<div class="bmibar">
<span class="seg s1" style="flex:3.5"></span>
<span class="seg s2" style="flex:5.5"></span>
<span class="seg s3" style="flex:4"></span>
<span class="seg s4" style="flex:12"></span>
<div class="marker" id="bmiMarker" style="left:50%"></div>
</div>
<div class="bmibar-labels">
<span style="flex:3.5">偏瘦</span>
<span style="flex:5.5">正常</span>
<span style="flex:4">超重</span>
<span style="flex:12">肥胖</span>
</div>
<div class="bmimeta">
<span id="idealWeight">—</span>
<span id="weightGap">—</span>
</div>
<div class="alert" id="alertBox"></div>
</section>
</div>
<!-- ======== 七大营养素 ======== -->
<section class="card">
<h2>每日七大营养素需求</h2>
<div class="nutri" id="nutriList"></div>
<div class="alert info show" id="nutriNote" style="margin-top:16px"></div>
</section>
<!-- ======== 计算过程 ======== -->
<section class="card">
<h2>计算过程(把数字代进去)</h2>
<div class="steps" id="steps"></div>
</section>
<p class="disclaimer">
本工具基于人群公式估算,误差约 ±10%,仅作参考,不构成医学诊断或治疗建议。<br>
维生素、矿物质数值参照《中国居民膳食营养素参考摄入量》,具体请咨询注册营养师或医生。
</p>
</div>
<script>
(function(){
var gender = 'male';
var goal = 'lose';
var rate = 0.5;
function $(id){ return document.getElementById(id); }
function round10(x){ return Math.round(x/10)*10; }
/* ---------- 选项卡 ---------- */
function chipGroup(id, cb){
var box = $(id);
box.addEventListener('click', function(e){
var lbl = e.target.closest('label');
if(!lbl || !box.contains(lbl)) return;
Array.prototype.forEach.call(box.children, function(c){ c.classList.remove('active'); });
lbl.classList.add('active');
cb(lbl.dataset.value);
compute();
});
}
chipGroup('genderChips', function(v){ gender = v; });
chipGroup('goalChips', function(v){
goal = v;
$('rateField').style.display = (v === 'lose') ? '' : 'none';
});
chipGroup('rateChips', function(v){ rate = parseFloat(v); });
['age','height','weight','activity'].forEach(function(id){
$(id).addEventListener('input', compute);
$(id).addEventListener('change', compute);
});
/* ---------- 公式 ---------- */
function mifflin(g, w, h, a){
return 10*w + 6.25*h - 5*a + (g === 'male' ? 5 : -161);
}
function bmiCategory(bmi){
if(bmi < 18.5) return {tag:'偏瘦', cls:'warn'};
if(bmi < 24) return {tag:'正常', cls:'info'};
if(bmi < 28) return {tag:'超重', cls:'warn'};
if(bmi < 35) return {tag:'肥胖 I 度', cls:'danger'};
if(bmi < 40) return {tag:'肥胖 II 度', cls:'danger'};
return {tag:'肥胖 III 度', cls:'danger'};
}
/* ---------- 维生素 / 矿物质 参考值 ---------- */
function vitaminNeeds(g, age){
var vd = (age >= 65) ? '15 μg' : '10 μg';
return [
{n:'维生素A', v:(g === 'male' ? '800' : '700') + ' μg RAE'},
{n:'维生素D', v:vd},
{n:'维生素E', v:'14 mg α-TE'},
{n:'维生素B1', v:(g === 'male' ? '1.4' : '1.2') + ' mg'},
{n:'维生素B2', v:(g === 'male' ? '1.4' : '1.2') + ' mg'},
{n:'维生素C', v:'100 mg'},
{n:'叶酸', v:'400 μg DFE'},
{n:'烟酸', v:(g === 'male' ? '15' : '12') + ' mg NE'}
];
}
function mineralNeeds(g, age){
var iron;
if(g === 'male') iron = '12 mg';
else iron = (age >= 50) ? '12 mg' : '20 mg';
return [
{n:'钙', v:'800 mg'},
{n:'铁', v:iron},
{n:'锌', v:(g === 'male' ? '12.5' : '7.5') + ' mg'},
{n:'镁', v:(g === 'male' ? '330' : '280') + ' mg'},
{n:'钾', v:'2000 mg'},
{n:'钠', v:'<1500 mg'},
{n:'硒', v:'60 μg'},
{n:'碘', v:'120 μg'}
];
}
/* ---------- 生成七大营养素卡片 ---------- */
function renderNutri(ctx){
var kcal = ctx.kcal;
var pBase = ctx.pBase;
var w = ctx.w;
var pLow = Math.round(1.6 * pBase);
var pHigh = Math.round(2.2 * pBase);
var fLow = Math.round(kcal * 0.25 / 9);
var fHigh = Math.round(kcal * 0.30 / 9);
var cLow = Math.max(0, Math.round((kcal - pHigh*4 - fHigh*9) / 4));
var cHigh = Math.max(0, Math.round((kcal - pLow*4 - fLow*9) / 4));
var fibLow = 25;
var fibHigh = Math.max(30, Math.round(14 * kcal / 1000));
var waterW = ctx.useRange ? ctx.adjW : w;
var water = Math.round(waterW * 35 / 50) * 50;
var cups = Math.round(water / 250);
var vits = vitaminNeeds(ctx.gender, ctx.age);
var mins = mineralNeeds(ctx.gender, ctx.age);
var items = [
{
icon:'🥩', bg:'#fee2e2',
name:'蛋白质', sub:'每公斤体重 1.6–2.2 g',
val: pLow + '–' + pHigh + ' g',
src: '减重期最关键的一项:吃不够会掉肌肉,代谢越来越低。',
chips: ['鸡胸 / 鱼虾','鸡蛋','瘦牛肉','豆腐豆浆','牛奶酸奶']
},
{
icon:'🫒', bg:'#fef3c7',
name:'脂肪', sub:'占总热量 25–30%',
val: fLow + '–' + fHigh + ' g',
src: '其中饱和脂肪控制在总热量 10% 以内,反式脂肪尽量为 0。',
chips: ['橄榄油 / 菜籽油','坚果','深海鱼','牛油果','(少吃油炸)']
},
{
icon:'🍚', bg:'#fde68a',
name:'碳水化合物', sub:'剩余热量,优先复合碳水',
val: cLow + '–' + cHigh + ' g',
src: '添加糖建议每天 <25 g(约 6 块方糖)。',
chips: ['糙米 / 燕麦','红薯土豆','杂豆','全麦面包','(少喝甜饮)']
},
{
icon:'🌿', bg:'#d1fae5',
name:'膳食纤维', sub:'按 14 g / 1000 kcal 折算',
val: fibLow + '–' + fibHigh + ' g',
src: '纤维能增加饱腹感、平稳血糖,减重期特别有用。',
chips: ['蔬菜 500 g','水果 200–350 g','全谷杂豆','菌菇海带']
},
{
icon:'🍊', bg:'#ffedd5',
name:'维生素', sub:'参考摄入量(RNI)',
val:'8 项',
src:'颜色吃得越杂越好,深色蔬菜占一半以上。',
chips: vits.map(function(x){ return x.n + ' <b>' + x.v + '</b>'; })
},
{
icon:'🧂', bg:'#e0e7ff',
name:'矿物质', sub:'参考摄入量(RNI / AI)',
val:'8 项',
src:'钠是上限、其余是下限:盐每天 <5 g,奶和豆制品补钙。',
chips: mins.map(function(x){ return x.n + ' <b>' + x.v + '</b>'; })
},
{
icon:'💧', bg:'#dbeafe',
name:'水', sub:'按 35 mL/kg 折算',
val: water + ' mL',
src: '约 ' + cups + ' 杯(250 mL/杯)。白开水或淡茶,分次喝,别一次猛灌。',
chips: ['晨起一杯','餐前一杯','运动后补水','(汤、茶也算)']
}
];
$('nutriList').innerHTML = items.map(function(it){
var chips = it.chips.map(function(c){ return '<span class="nchip">' + c + '</span>'; }).join('');
return '<div class="nrow">'
+ '<div class="nicon" style="background:' + it.bg + '">' + it.icon + '</div>'
+ '<div class="nmain">'
+ '<div class="ntop">'
+ '<span class="nname">' + it.name + '<small>' + it.sub + '</small></span>'
+ '<span class="nval">' + it.val + '</span>'
+ '</div>'
+ '<div class="nsrc">' + it.src + '</div>'
+ '<div class="nchips">' + chips + '</div>'
+ '</div>'
+ '</div>';
}).join('');
$('nutriNote').textContent =
'以上数值按你当前的每日目标摄入 ' + round10(kcal) + ' kcal 换算。'
+ '蛋白质以' + (ctx.useRange ? '调整体重 ' + ctx.adjW.toFixed(1) + ' kg' : '体重 ' + w + ' kg') + '为基准;'
+ '水以' + (ctx.useRange ? '调整体重' : '体重') + ' × 35 mL 计算。'
+ '维生素和矿物质为成年人参考摄入量,孕期、哺乳期、慢性病患者需另作调整。';
}
/* ---------- 主计算 ---------- */
function compute(){
var age = parseFloat($('age').value);
var h = parseFloat($('height').value);
var w = parseFloat($('weight').value);
var act = parseFloat($('activity').value);
if(!(age > 0) || !(h > 0) || !(w > 0)){
$('targetVal').textContent = '—';
$('bmiVal').textContent = '—';
$('bmrVal').textContent = '—';
$('tdeeVal').textContent = '—';
$('bmiTag').textContent = '—';
$('targetNote').textContent = '请填写完整的年龄、身高、体重';
$('steps').innerHTML = '';
$('nutriList').innerHTML = '';
$('nutriNote').textContent = '请先填写完整的年龄、身高、体重。';
$('alertBox').className = 'alert';
$('bmiMarker').style.left = '50%';
$('idealWeight').textContent = '—';
$('weightGap').textContent = '';
return;
}
var hm = h / 100;
var bmi = w / (hm * hm);
/* --- BMR:肥胖时用调整体重做下限 --- */
var idealW = 22 * hm * hm;
var bmrRaw = mifflin(gender, w, h, age);
var useRange = bmi >= 28;
var adjW = idealW + 0.25 * (w - idealW);
var bmrLow = useRange ? mifflin(gender, adjW, h, age) : bmrRaw;
var bmrHigh = bmrRaw;
var bmrMid = (bmrLow + bmrHigh) / 2;
/* --- TDEE --- */
var tdeeLow = bmrLow * act;
var tdeeHigh = bmrHigh * act;
var tdeeMid = (tdeeLow + tdeeHigh) / 2;
/* --- 目标热量 --- */
var delta = 0;
if(goal === 'lose') delta = rate * 7700 / 7;
else if(goal === 'gain') delta = -300;
var tgtMid = tdeeMid - delta;
var tgtLow = tdeeLow - delta;
var tgtHigh = tdeeHigh - delta;
/* --- 安全下限 --- */
var floor = (gender === 'male') ? 1500 : 1200;
var floorHit = tgtMid < floor;
if(floorHit){
tgtMid = floor;
tgtLow = Math.max(tgtLow, floor);
tgtHigh = Math.max(tgtHigh, floor);
}
var show = round10(tgtMid);
/* ---------- 输出:大数字 ---------- */
$('targetLabel').textContent =
goal === 'lose' ? '每日建议摄入(减重)' :
goal === 'gain' ? '每日建议摄入(增重)' : '每日维持热量';
$('targetVal').textContent = show;
$('targetNote').textContent = (useRange || goal !== 'maintain')
? '合理区间 ' + round10(tgtLow) + ' – ' + round10(tgtHigh) + ' kcal'
: '按此摄入,体重基本稳定';
/* ---------- 输出:三格 + BMI ---------- */
var cat = bmiCategory(bmi);
$('bmiVal').textContent = bmi.toFixed(1);
$('bmiTag').textContent = cat.tag;
$('bmrVal').textContent = useRange ? round10(bmrLow) + '–' + round10(bmrHigh) : Math.round(bmrMid);
$('tdeeVal').textContent = useRange ? round10(tdeeLow) + '–' + round10(tdeeHigh) : Math.round(tdeeMid);
/* ---------- BMI 条 ---------- */
var pos = (bmi - 15) / 25 * 100;
pos = Math.max(0, Math.min(100, pos));
$('bmiMarker').style.left = pos + '%';
$('idealWeight').textContent = '健康体重范围:'
+ (18.5*hm*hm).toFixed(1) + ' – ' + (23.9*hm*hm).toFixed(1) + ' kg';
if(bmi > 23.9){
$('weightGap').textContent = '距正常上限还需减:约 ' + (w - 23.9*hm*hm).toFixed(1) + ' kg';
} else if(bmi < 18.5){
$('weightGap').textContent = '距正常下限还需增:约 ' + (18.5*hm*hm - w).toFixed(1) + ' kg';
} else {
$('weightGap').textContent = '已在健康区间内 ✓';
}
/* ---------- 七大营养素 ---------- */
renderNutri({
kcal: tgtMid,
pBase: useRange ? idealW : w,
w: w,
useRange: useRange,
adjW: adjW,
gender: gender,
age: age
});
/* ---------- 提示框 ---------- */
var box = $('alertBox');
box.className = 'alert';
var msgs = [];
var cls = 'info';
if(floorHit){
msgs.push('⚠️ 按目标速度算出的热量低于安全下限(' + floor + ' kcal),已自动上调。缺口过大容易掉肌肉、反弹、并增加胆结石风险,建议把减重速度调到 0.5 kg/周以内。');
cls = 'warn';
}
if(bmi >= 28){
msgs.push('你的 BMI 属于' + cat.tag + ',医学上建议在医生或注册营养师指导下减重。建议做一次基础检查:空腹血糖/糖化血红蛋白、血脂四项、肝功能+腹部超声、血压;若打鼾严重或白天嗜睡,加查睡眠呼吸暂停。');
cls = 'danger';
} else if(bmi >= 24){
msgs.push('BMI 属于超重区间。先减 5–10% 体重(约 ' + (w*0.05).toFixed(1) + ' – ' + (w*0.10).toFixed(1) + ' kg),血压、血糖、血脂就会有明显改善。');
cls = (cls === 'danger') ? 'danger' : 'warn';
} else if(bmi < 18.5){
msgs.push('BMI 偏低,重点不是继续减,而是保证蛋白质与力量训练,把肌肉量撑起来。');
cls = 'warn';
} else {
msgs.push('BMI 在正常区间,保持当前饮食结构即可,建议每周 2–3 次力量训练维持肌肉量。');
}
if(bmi >= 28){
msgs.push('另外记得量腰围(男性 <90 cm,女性 <85 cm)——它和内脏脂肪、糖尿病的关系比 BMI 更直接。');
}
box.textContent = msgs.join(' ');
box.classList.add('show', cls);
/* ---------- 计算过程 ---------- */
var sign = (gender === 'male') ? '+ 5' : '− 161';
var lines = [];
lines.push({
t: '第 1 步 · BMI(体重 ÷ 身高²)',
c: w + ' ÷ (' + hm.toFixed(2) + ' × ' + hm.toFixed(2) + ') = ' + w + ' ÷ ' + (hm*hm).toFixed(4)
+ ' = ' + bmi.toFixed(1) + '\n判定:' + cat.tag
+ '(偏瘦<18.5|正常 18.5–23.9|超重 24–27.9|肥胖 ≥28)'
});
lines.push({
t: '第 2 步 · 基础代谢 BMR(躺着不动一天的消耗)',
c: '10×' + w + ' + 6.25×' + h + ' − 5×' + age + ' ' + sign
+ ' = ' + Math.round(bmrRaw) + ' kcal'
});
if(useRange){
lines.push({
t: '第 3 步 · 肥胖校正(脂肪代谢活性远低于肌肉,直接用实际体重会高估代谢)',
c: '理想体重 = 22 × ' + hm.toFixed(2) + '² = ' + idealW.toFixed(1) + ' kg\n'
+ '调整体重 = ' + idealW.toFixed(1) + ' + 0.25×(' + w + ' − ' + idealW.toFixed(1) + ') = ' + adjW.toFixed(1) + ' kg\n'
+ '按调整体重算 BMR = ' + Math.round(bmrLow) + ' kcal\n'
+ '→ 真实 BMR 取两者之间:' + round10(bmrLow) + ' – ' + round10(bmrHigh) + ' kcal'
});
}
lines.push({
t: (useRange ? '第 4 步' : '第 3 步') + ' · 总消耗 TDEE = BMR × 活动系数 ' + act,
c: useRange
? Math.round(bmrLow) + ' × ' + act + ' ≈ ' + round10(tdeeLow) + ' kcal(下限)\n'
+ Math.round(bmrHigh) + ' × ' + act + ' ≈ ' + round10(tdeeHigh) + ' kcal(上限)\n'
+ '取中值 ≈ ' + round10(tdeeMid) + ' kcal'
: Math.round(bmrMid) + ' × ' + act + ' ≈ ' + round10(tdeeMid) + ' kcal'
});
if(goal !== 'maintain'){
var dir = (goal === 'lose') ? '热量缺口' : '热量盈余';
lines.push({
t: (useRange ? '第 5 步' : '第 4 步') + ' · ' + dir + '(1 kg 脂肪 ≈ 7700 kcal)',
c: (goal === 'lose')
? rate + ' kg/周 × 7700 ÷ 7 天 ≈ ' + Math.round(delta) + ' kcal/天'
: '增重期建议温和盈余:+300 kcal/天'
});
}
lines.push({
t: '每日目标摄入',
c: (goal === 'lose' ? round10(tdeeMid) + ' − ' + Math.round(delta) : goal === 'gain' ? round10(tdeeMid) + ' + 300' : '维持不变')
+ ' ≈ ' + show + ' kcal/天'
+ (floorHit ? '\n(低于安全下限 ' + floor + ' kcal,已上调)' : '')
});
lines.push({
t: '七大营养素换算依据',
c: '蛋白质 = ' + (useRange ? '调整体重 ' + adjW.toFixed(1) : '体重 ' + w) + ' kg × 1.6–2.2 g/kg\n'
+ '脂肪 = ' + show + ' kcal × 25%–30% ÷ 9 kcal/g\n'
+ '碳水 = 总热量 − 蛋白质 − 脂肪(其余热量)\n'
+ '膳食纤维 = 14 g × ' + (show/1000).toFixed(1) + '(千卡)+ 底线 25 g\n'
+ '水 = ' + (useRange ? '调整体重 ' + adjW.toFixed(1) : '体重 ' + w) + ' kg × 35 mL/kg'
});
$('steps').innerHTML = lines.map(function(l, i){
return '<div class="step"><span class="n">' + (i+1) + '</span>'
+ '<span class="body">' + l.t + '<code>' + l.c.replace(/\n/g,'<br>') + '</code></span></div>';
}).join('');
}
compute();
})();
</script>
</body>
</html>