1412 lines
59 KiB
HTML
1412 lines
59 KiB
HTML
<!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>
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
:root {
|
||
--brand: #6d5efc;
|
||
--brand2: #9b6dff;
|
||
--ink: #1f2937;
|
||
--muted: #6b7280;
|
||
--line: #e8eaf0;
|
||
--card: #ffffff;
|
||
--soft: #fafbfe;
|
||
--bg1: #eef0ff;
|
||
--bg2: #f7f4ff;
|
||
--bg3: #eafaf4;
|
||
--shadow: rgba(83, 74, 160, .1);
|
||
--ok: #22c55e;
|
||
--warn: #f59e0b;
|
||
--bad: #ef4444;
|
||
--blue: #3b82f6;
|
||
}
|
||
body.dark {
|
||
--ink: #e7e9f2;
|
||
--muted: #9aa1b5;
|
||
--line: #2c3040;
|
||
--card: #191c26;
|
||
--soft: #21242f;
|
||
--bg1: #12141c;
|
||
--bg2: #171922;
|
||
--bg3: #12181a;
|
||
--shadow: rgba(0,0,0,.4);
|
||
}
|
||
body {
|
||
font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
|
||
color: var(--ink);
|
||
background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 45%, var(--bg3) 100%);
|
||
background-attachment: fixed;
|
||
min-height: 100vh;
|
||
padding: 18px 13px 60px;
|
||
-webkit-font-smoothing: antialiased;
|
||
transition: background .3s, color .3s;
|
||
}
|
||
.app { max-width: 780px; margin: 0 auto; }
|
||
|
||
.topbar {
|
||
display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
|
||
}
|
||
.topbar .logo { font-size: 26px; }
|
||
.topbar h1 { font-size: 18px; letter-spacing: .3px; }
|
||
.topbar .spacer { flex: 1; }
|
||
.pill {
|
||
border: 1.5px solid var(--line); background: var(--card); color: var(--muted);
|
||
font-size: 12px; font-weight: 600; padding: 7px 11px; border-radius: 20px;
|
||
cursor: pointer; transition: all .18s; white-space: nowrap;
|
||
}
|
||
.pill:hover { border-color: var(--brand); color: var(--brand); }
|
||
|
||
.tabs { display: flex; gap: 6px; background: var(--card); padding: 6px; border-radius: 14px; margin-bottom: 16px; box-shadow: 0 6px 20px var(--shadow); }
|
||
.tabs button {
|
||
flex: 1; padding: 10px 0; font-size: 13.5px; font-weight: 600; border: none;
|
||
background: none; color: var(--muted); border-radius: 10px; cursor: pointer; transition: all .18s;
|
||
}
|
||
.tabs button.active { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; box-shadow: 0 6px 14px rgba(109,94,252,.28); }
|
||
|
||
.tabpage { display: none; }
|
||
.tabpage.active { display: block; animation: fade .35s ease; }
|
||
@keyframes fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
|
||
|
||
.panel {
|
||
background: var(--card); border-radius: 16px; padding: 19px 19px 21px;
|
||
margin-bottom: 15px; box-shadow: 0 6px 22px var(--shadow);
|
||
border: 1px solid var(--line); transition: background .3s, border-color .3s;
|
||
}
|
||
.panel h2 { font-size: 14.5px; margin-bottom: 15px; display: flex; align-items: center; gap: 8px; }
|
||
.panel h2 .num {
|
||
display: inline-flex; align-items: center; justify-content: center;
|
||
width: 22px; height: 22px; border-radius: 7px; flex: none;
|
||
background: linear-gradient(135deg, var(--brand), var(--brand2));
|
||
color: #fff; font-size: 12px;
|
||
}
|
||
.panel h2 .hint { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-left: auto; }
|
||
|
||
.row { display: flex; gap: 13px; }
|
||
.row + .row { margin-top: 13px; }
|
||
.field { flex: 1; min-width: 0; }
|
||
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
|
||
label .opt { color: var(--muted); opacity: .7; font-weight: 400; font-size: 11px; }
|
||
input[type="number"], input[type="date"] {
|
||
width: 100%; padding: 11px 12px; font-size: 15px; color: var(--ink);
|
||
border: 1.5px solid var(--line); border-radius: 10px; background: var(--soft);
|
||
outline: none; transition: border-color .18s, box-shadow .18s, background .18s;
|
||
font-family: inherit;
|
||
}
|
||
input:focus { border-color: var(--brand); background: var(--card); box-shadow: 0 0 0 3px rgba(109,94,252,.15); }
|
||
input::placeholder { color: var(--muted); opacity: .55; }
|
||
|
||
.seg { display: flex; gap: 7px; }
|
||
.seg button {
|
||
flex: 1; padding: 11px 0; font-size: 13.5px; font-weight: 600; font-family: inherit;
|
||
border: 1.5px solid var(--line); background: var(--soft); color: var(--muted);
|
||
border-radius: 10px; cursor: pointer; transition: all .18s;
|
||
}
|
||
.seg button.active {
|
||
border-color: var(--brand); color: #fff;
|
||
background: linear-gradient(135deg, var(--brand), var(--brand2));
|
||
box-shadow: 0 6px 14px rgba(109,94,252,.28);
|
||
}
|
||
|
||
select {
|
||
width: 100%; padding: 11px 34px 11px 12px; font-size: 14.5px; color: var(--ink);
|
||
border: 1.5px solid var(--line); border-radius: 10px; background: var(--soft);
|
||
outline: none; font-family: inherit; appearance: none;
|
||
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
|
||
background-repeat: no-repeat; background-position: right 12px center;
|
||
}
|
||
select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(109,94,252,.15); }
|
||
|
||
.slider-wrap { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
|
||
input[type="range"] {
|
||
flex: 1; -webkit-appearance: none; height: 6px; border-radius: 4px; outline: none;
|
||
background: linear-gradient(90deg, var(--brand), var(--brand2));
|
||
}
|
||
input[type="range"]::-webkit-slider-thumb {
|
||
-webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
|
||
background: #fff; border: 3px solid var(--brand); cursor: pointer;
|
||
box-shadow: 0 2px 6px rgba(0,0,0,.2);
|
||
}
|
||
.slider-val { font-size: 14px; font-weight: 700; color: var(--brand); min-width: 46px; text-align: right; }
|
||
|
||
.btn-row { display: flex; gap: 10px; margin-bottom: 15px; }
|
||
.main-btn {
|
||
flex: 1; padding: 15px; font-size: 16px; font-weight: 700; font-family: inherit;
|
||
color: #fff; border: none; border-radius: 13px; cursor: pointer;
|
||
background: linear-gradient(135deg, var(--brand), var(--brand2));
|
||
box-shadow: 0 10px 22px rgba(109,94,252,.32);
|
||
transition: transform .15s, box-shadow .2s;
|
||
}
|
||
.main-btn:hover { transform: translateY(-1px); }
|
||
.main-btn:active { transform: translateY(0); }
|
||
.main-btn.ghost {
|
||
background: var(--card); color: var(--muted); border: 1.5px solid var(--line);
|
||
box-shadow: none; font-size: 13.5px; font-weight: 600; padding: 12px;
|
||
}
|
||
.main-btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
|
||
|
||
.err { color: var(--bad); font-size: 13px; margin-bottom: 12px; display: none; }
|
||
.err.show { display: block; }
|
||
|
||
.results { display: none; }
|
||
.results.show { display: block; animation: fade .4s ease; }
|
||
|
||
/* BMI 头部 */
|
||
.bmi-head { text-align: center; padding: 6px 0 2px; }
|
||
.bmi-head .value { font-size: 54px; font-weight: 800; line-height: 1; letter-spacing: -1.5px; }
|
||
.bmi-head .value small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
|
||
.bmi-head .cat {
|
||
display: inline-block; margin-top: 12px; padding: 6px 18px;
|
||
border-radius: 20px; font-size: 13px; font-weight: 700; color: #fff;
|
||
}
|
||
.bmi-head .range { font-size: 12px; color: var(--muted); margin-top: 10px; }
|
||
.badge-row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
|
||
.badge { font-size: 11.5px; padding: 5px 11px; border-radius: 20px; border: 1.5px solid var(--line); color: var(--muted); }
|
||
.badge b { color: var(--ink); }
|
||
|
||
.scale { position: relative; height: 14px; border-radius: 8px; overflow: hidden; margin: 20px 0 5px; display: flex; }
|
||
.scale .seg-bar { height: 100%; }
|
||
.marker {
|
||
position: absolute; top: -6px; width: 4px; height: 26px; border-radius: 3px;
|
||
background: var(--ink); box-shadow: 0 0 0 3px var(--card);
|
||
transition: left .55s cubic-bezier(.34,1.4,.64,1);
|
||
}
|
||
.scale-labels { display: flex; font-size: 10.5px; color: var(--muted); line-height: 1.5; }
|
||
.scale-labels span { text-align: center; }
|
||
|
||
h3.sec { font-size: 13px; font-weight: 700; margin: 24px 0 12px; padding-left: 9px; border-left: 3.5px solid var(--brand); }
|
||
h3.sec:first-child { margin-top: 0; }
|
||
|
||
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
|
||
.stat { background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; }
|
||
.stat .k { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
|
||
.stat .v { font-size: 19px; font-weight: 700; }
|
||
.stat .v small { font-size: 11.5px; font-weight: 500; color: var(--muted); }
|
||
.stat.accent { background: linear-gradient(135deg, rgba(109,94,252,.12), rgba(155,109,255,.08)); border-color: rgba(109,94,252,.3); }
|
||
.stat .tag { display: inline-block; font-size: 10.5px; padding: 2px 8px; border-radius: 20px; color: #fff; margin-top: 5px; }
|
||
|
||
table.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
||
table.cmp th, table.cmp td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--line); }
|
||
table.cmp th { font-size: 11px; color: var(--muted); font-weight: 600; }
|
||
table.cmp td.num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
|
||
table.cmp tr:last-child td { border-bottom: none; }
|
||
table.cmp tr.pick td { color: var(--brand); }
|
||
table.cmp tr.pick td:first-child::after { content: " ★"; }
|
||
|
||
.target {
|
||
text-align: center; padding: 20px; border-radius: 14px;
|
||
background: linear-gradient(135deg, var(--brand), var(--brand2));
|
||
color: #fff;
|
||
}
|
||
.target .k { font-size: 12.5px; opacity: .92; }
|
||
.target .v { font-size: 36px; font-weight: 800; line-height: 1.15; margin: 4px 0; }
|
||
.target .v small { font-size: 14px; font-weight: 600; opacity: .9; }
|
||
.target .sub { font-size: 12px; opacity: .9; line-height: 1.6; }
|
||
|
||
.macro-set { display: flex; gap: 7px; margin-bottom: 15px; flex-wrap: wrap; }
|
||
.macro-set button {
|
||
flex: 1; min-width: 90px; padding: 9px 0; font-size: 12px; font-weight: 600; font-family: inherit;
|
||
border: 1.5px solid var(--line); background: var(--soft); color: var(--muted);
|
||
border-radius: 9px; cursor: pointer; transition: all .18s;
|
||
}
|
||
.macro-set button.active { border-color: var(--brand); background: rgba(109,94,252,.1); color: var(--brand); }
|
||
|
||
.macro-row { margin-bottom: 13px; }
|
||
.macro-row .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
|
||
.bar { height: 9px; border-radius: 6px; background: var(--line); overflow: hidden; }
|
||
.bar > i { display: block; height: 100%; border-radius: 6px; transition: width .5s ease; }
|
||
|
||
.meal { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
|
||
.meal .m { text-align: center; background: var(--soft); border: 1px solid var(--line); border-radius: 11px; padding: 11px 4px; }
|
||
.meal .m .t { font-size: 11px; color: var(--muted); }
|
||
.meal .m .n { font-size: 15px; font-weight: 700; margin-top: 4px; }
|
||
.meal .m .n small { font-size: 10px; color: var(--muted); font-weight: 500; }
|
||
|
||
.tips { font-size: 12.5px; line-height: 1.9; color: var(--ink); }
|
||
.tips li { margin-left: 18px; margin-bottom: 2px; }
|
||
.tips li::marker { color: var(--brand); }
|
||
|
||
canvas { width: 100%; display: block; }
|
||
.hist-empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 24px 0; }
|
||
table.hist { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||
table.hist th, table.hist td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
|
||
table.hist th { font-size: 11px; color: var(--muted); font-weight: 600; white-space: nowrap; }
|
||
table.hist td.num { font-variant-numeric: tabular-nums; }
|
||
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
|
||
.del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 6px; }
|
||
.del:hover { color: var(--bad); background: rgba(239,68,68,.1); }
|
||
|
||
.doc { font-size: 13px; line-height: 1.95; color: var(--ink); }
|
||
.doc h4 { font-size: 13.5px; margin: 18px 0 8px; color: var(--brand); }
|
||
.doc h4:first-child { margin-top: 0; }
|
||
.doc ul { margin-left: 18px; }
|
||
.doc li { margin-bottom: 3px; }
|
||
.doc code { background: var(--soft); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 12px; }
|
||
|
||
.foot-note { font-size: 11.5px; color: var(--muted); line-height: 1.8; margin-top: 18px; text-align: center; }
|
||
|
||
@media (max-width: 470px) {
|
||
.row { flex-direction: column; gap: 13px; }
|
||
.row + .row { margin-top: 13px; }
|
||
.bmi-head .value { font-size: 46px; }
|
||
.meal { grid-template-columns: repeat(2, 1fr); }
|
||
}
|
||
@media print {
|
||
body { background: #fff; padding: 0; }
|
||
.tabs, .btn-row, .main-btn, .topbar .pill { display: none !important; }
|
||
.tabpage { display: block !important; }
|
||
.panel { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="app">
|
||
|
||
<div class="topbar">
|
||
<span class="logo">🩺</span>
|
||
<h1>健康管理工具</h1>
|
||
<span class="spacer"></span>
|
||
<button class="pill" id="unitBtn">单位:公制</button>
|
||
<button class="pill" id="themeBtn">🌙 夜间</button>
|
||
</div>
|
||
|
||
<div class="tabs" id="tabbar">
|
||
<button data-tab="calc" class="active">计算</button>
|
||
<button data-tab="trend">记录与趋势</button>
|
||
<button data-tab="doc">说明</button>
|
||
</div>
|
||
|
||
<!-- ================= 计算 ================= -->
|
||
<div class="tabpage active" id="tab-calc">
|
||
|
||
<section class="panel">
|
||
<h2><span class="num">1</span>基本数据</h2>
|
||
<div class="row">
|
||
<div class="field">
|
||
<label id="hLabel">身高 (cm)</label>
|
||
<input type="number" id="height" placeholder="例如 170" step="0.1" inputmode="decimal">
|
||
</div>
|
||
<div class="field">
|
||
<label id="wLabel">体重 (kg)</label>
|
||
<input type="number" id="weight" placeholder="例如 65" step="0.1" inputmode="decimal">
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="field">
|
||
<label>年龄</label>
|
||
<input type="number" id="age" placeholder="例如 25" step="1" inputmode="numeric">
|
||
</div>
|
||
<div class="field">
|
||
<label>性别</label>
|
||
<div class="seg" id="genderSeg">
|
||
<button type="button" data-g="male" class="active">男</button>
|
||
<button type="button" data-g="female">女</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="panel">
|
||
<h2><span class="num">2</span>围度测量 <span class="hint">选填 · 越全越准</span></h2>
|
||
<div class="row">
|
||
<div class="field">
|
||
<label>腰围 (cm) <span class="opt">肚脐水平</span></label>
|
||
<input type="number" id="waist" placeholder="例如 80" step="0.1" inputmode="decimal">
|
||
</div>
|
||
<div class="field">
|
||
<label>颈围 (cm) <span class="opt">喉结下方</span></label>
|
||
<input type="number" id="neck" placeholder="例如 37" step="0.1" inputmode="decimal">
|
||
</div>
|
||
</div>
|
||
<div class="row" id="hipRow" style="display:none;">
|
||
<div class="field">
|
||
<label>臀围 (cm) <span class="opt">女性填写</span></label>
|
||
<input type="number" id="hip" placeholder="例如 92" step="0.1" inputmode="decimal">
|
||
</div>
|
||
</div>
|
||
<p style="font-size:11.5px;color:var(--muted);margin-top:12px;line-height:1.7;">
|
||
腰围用于评估腹型肥胖与心血管风险;腰围 + 颈围(女性再加臀围)可估算体脂率。
|
||
</p>
|
||
</section>
|
||
|
||
<section class="panel">
|
||
<h2><span class="num">3</span>活动与目标</h2>
|
||
<div class="field">
|
||
<label>日常活动水平</label>
|
||
<select id="activity">
|
||
<option value="1.2">久坐 — 几乎不运动 / 办公室工作</option>
|
||
<option value="1.375">轻度 — 每周运动 1~3 次</option>
|
||
<option value="1.55" selected>中度 — 每周运动 3~5 次</option>
|
||
<option value="1.725">高度 — 每周运动 6~7 次</option>
|
||
<option value="1.9">极高 — 体力劳动 / 每天两练</option>
|
||
</select>
|
||
</div>
|
||
<div class="field" style="margin-top:13px;">
|
||
<label>目标</label>
|
||
<div class="seg" id="goalSeg">
|
||
<button type="button" data-goal="cut">减脂</button>
|
||
<button type="button" data-goal="maintain" class="active">维持</button>
|
||
<button type="button" data-goal="bulk">增肌</button>
|
||
</div>
|
||
</div>
|
||
<div class="slider-wrap" id="adjustWrap" style="display:none;">
|
||
<span style="font-size:12.5px;color:var(--muted);white-space:nowrap;">调整幅度</span>
|
||
<input type="range" id="percent" min="5" max="30" value="15" step="1">
|
||
<span class="slider-val" id="percentVal">15%</span>
|
||
</div>
|
||
<div class="row" style="margin-top:13px;">
|
||
<div class="field">
|
||
<label>目标体重 <span class="opt">选填</span></label>
|
||
<input type="number" id="targetWeight" placeholder="例如 60" step="0.1" inputmode="decimal">
|
||
</div>
|
||
<div class="field">
|
||
<label>期望达成日期 <span class="opt">选填</span></label>
|
||
<input type="date" id="targetDate">
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<div class="err" id="err"></div>
|
||
<div class="btn-row">
|
||
<button class="main-btn" id="calcBtn">开始计算</button>
|
||
<button class="main-btn ghost" id="demoBtn" style="flex:0 0 auto;padding:15px 18px;">示例</button>
|
||
<button class="main-btn ghost" id="resetBtn" style="flex:0 0 auto;padding:15px 18px;">重置</button>
|
||
</div>
|
||
|
||
<section class="results" id="results">
|
||
|
||
<!-- 概览 -->
|
||
<section class="panel">
|
||
<div class="bmi-head">
|
||
<div class="value" id="bmiValue">--</div>
|
||
<div class="cat" id="bmiCat">--</div>
|
||
<div class="range" id="bmiRange"></div>
|
||
<div class="badge-row" id="badgeRow"></div>
|
||
</div>
|
||
<div class="scale" id="scaleBar">
|
||
<div class="seg-bar" style="background:#3b82f6;flex:14;"></div>
|
||
<div class="seg-bar" style="background:#22c55e;flex:22;"></div>
|
||
<div class="seg-bar" style="background:#f59e0b;flex:16;"></div>
|
||
<div class="seg-bar" style="background:#ef4444;flex:48;"></div>
|
||
<div class="marker" id="marker" style="left:30%;"></div>
|
||
</div>
|
||
<div class="scale-labels">
|
||
<span style="flex:14">偏瘦<br><18.5</span>
|
||
<span style="flex:22">正常<br>18.5–24</span>
|
||
<span style="flex:16">超重<br>24–28</span>
|
||
<span style="flex:48">肥胖<br>>28</span>
|
||
</div>
|
||
<p style="font-size:11px;color:var(--muted);margin-top:8px;">分级采用中国成人标准(WS/T 428-2013)</p>
|
||
</section>
|
||
|
||
<!-- 体型指标 -->
|
||
<section class="panel">
|
||
<h3 class="sec">体型与风险指标</h3>
|
||
<div class="grid">
|
||
<div class="stat">
|
||
<div class="k">BMI Prime(BMI ÷ 25)</div>
|
||
<div class="v" id="bmiPrime">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">旁氏指数(kg/m³)</div>
|
||
<div class="v" id="ponderal">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">腰高比 WHtR</div>
|
||
<div class="v" id="whtr">--</div>
|
||
<div id="whtrTag"></div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">腰臀比 WHR</div>
|
||
<div class="v" id="whr">--</div>
|
||
<div id="whrTag"></div>
|
||
</div>
|
||
</div>
|
||
<p style="font-size:11.5px;color:var(--muted);margin-top:10px;line-height:1.7;" id="riskNote"></p>
|
||
</section>
|
||
|
||
<!-- 体脂 -->
|
||
<section class="panel">
|
||
<h3 class="sec">体成分</h3>
|
||
<div class="grid">
|
||
<div class="stat accent">
|
||
<div class="k">体脂率(综合)</div>
|
||
<div class="v" id="bodyFat">--</div>
|
||
<div id="bfTag"></div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">去脂体重</div>
|
||
<div class="v" id="leanMass">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">脂肪重量</div>
|
||
<div class="v" id="fatMass">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">去脂体重指数 FFMI</div>
|
||
<div class="v" id="ffmi">--</div>
|
||
<div id="ffmiTag"></div>
|
||
</div>
|
||
</div>
|
||
<h3 class="sec">体脂率多公式对比</h3>
|
||
<table class="cmp">
|
||
<thead><tr><th>公式</th><th style="text-align:right">体脂率</th></tr></thead>
|
||
<tbody id="bfBody"></tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<!-- 理想体重 -->
|
||
<section class="panel">
|
||
<h3 class="sec">理想体重参考(多公式)</h3>
|
||
<table class="cmp">
|
||
<thead><tr><th>标准</th><th style="text-align:right">理想体重</th></tr></thead>
|
||
<tbody id="iwBody"></tbody>
|
||
</table>
|
||
<p style="font-size:11.5px;color:var(--muted);margin-top:10px;line-height:1.7;">
|
||
Devine / Robinson / Miller / Hamwi 为临床常用公式,多为药物剂量参考;BMI 22 与健康区间更适用于普通人。
|
||
</p>
|
||
</section>
|
||
|
||
<!-- 代谢 -->
|
||
<section class="panel">
|
||
<h3 class="sec">每日能量需求</h3>
|
||
<div class="grid">
|
||
<div class="stat">
|
||
<div class="k">基础代谢 BMR</div>
|
||
<div class="v" id="bmr">-- <small>kcal</small></div>
|
||
</div>
|
||
<div class="stat accent">
|
||
<div class="k">每日总消耗 TDEE</div>
|
||
<div class="v" id="tdee" style="font-size:22px;">-- <small>kcal</small></div>
|
||
</div>
|
||
</div>
|
||
<div class="stat" style="margin-top:11px;">
|
||
<div class="k">TDEE 构成</div>
|
||
<div style="display:flex;height:11px;border-radius:6px;overflow:hidden;margin-top:8px;">
|
||
<i id="barBmr" style="background:#6d5efc;"></i>
|
||
<i id="barTea" style="background:#9b6dff;"></i>
|
||
</div>
|
||
<div style="display:flex;justify-content:space-between;font-size:11px;color:var(--muted);margin-top:7px;">
|
||
<span>基础代谢 <b id="teaBmrTxt">--</b></span>
|
||
<span>活动消耗 <b id="teaTxt">--</b></span>
|
||
</div>
|
||
</div>
|
||
|
||
<h3 class="sec">代谢公式对比</h3>
|
||
<table class="cmp">
|
||
<thead><tr><th>公式</th><th style="text-align:right">BMR</th><th style="text-align:right">TDEE</th></tr></thead>
|
||
<tbody id="cmpBody"></tbody>
|
||
</table>
|
||
<p style="font-size:11.5px;color:var(--muted);margin-top:8px;">★ 为本次采用的结果;有围度数据时自动采用基于体脂的公式。</p>
|
||
</section>
|
||
|
||
<!-- 目标热量 -->
|
||
<section class="panel">
|
||
<h3 class="sec">目标热量建议</h3>
|
||
<div class="target">
|
||
<div class="k" id="targetK">维持体重每日所需</div>
|
||
<div class="v" id="targetV">-- <small>kcal</small></div>
|
||
<div class="sub" id="targetSub"></div>
|
||
</div>
|
||
<div class="grid" style="margin-top:12px;">
|
||
<div class="stat">
|
||
<div class="k">每日热量缺口 / 盈余</div>
|
||
<div class="v" id="deltaKcal" style="font-size:17px">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">按此节奏所需时间</div>
|
||
<div class="v" id="duration" style="font-size:17px">--</div>
|
||
</div>
|
||
</div>
|
||
<p style="font-size:11.5px;color:var(--muted);margin-top:10px;line-height:1.7;" id="planNote"></p>
|
||
</section>
|
||
|
||
<!-- 营养素 -->
|
||
<section class="panel">
|
||
<h3 class="sec">营养素分配</h3>
|
||
<div class="macro-set" id="macroSet">
|
||
<button type="button" data-scheme="balanced" class="active">均衡 30/45/25</button>
|
||
<button type="button" data-scheme="highprotein">高蛋白 40/35/25</button>
|
||
<button type="button" data-scheme="lowcarb">低碳 35/25/40</button>
|
||
</div>
|
||
<div class="macro-row">
|
||
<div class="top"><span>蛋白质</span><b id="pG">-- g</b></div>
|
||
<div class="bar"><i id="pBar" style="background:#ef4444;width:0%"></i></div>
|
||
</div>
|
||
<div class="macro-row">
|
||
<div class="top"><span>碳水化合物</span><b id="cG">-- g</b></div>
|
||
<div class="bar"><i id="cBar" style="background:#f59e0b;width:0%"></i></div>
|
||
</div>
|
||
<div class="macro-row">
|
||
<div class="top"><span>脂肪</span><b id="fG">-- g</b></div>
|
||
<div class="bar"><i id="fBar" style="background:#10b981;width:0%"></i></div>
|
||
</div>
|
||
<p style="font-size:11.5px;color:var(--muted);line-height:1.7;">
|
||
蛋白质约 <b id="proteinPerKg">--</b> g/kg 体重 · 脂肪最低不低于 0.6 g/kg ·
|
||
1g 蛋白/碳水 ≈ 4kcal,1g 脂肪 ≈ 9kcal
|
||
</p>
|
||
|
||
<h3 class="sec">餐次分配(参考)</h3>
|
||
<div class="meal" id="mealBox"></div>
|
||
|
||
<h3 class="sec">每日饮水建议</h3>
|
||
<div class="grid">
|
||
<div class="stat">
|
||
<div class="k">基础饮水</div>
|
||
<div class="v" id="water">--</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="k">运动日额外补水</div>
|
||
<div class="v" id="waterSport">--</div>
|
||
</div>
|
||
</div>
|
||
|
||
<h3 class="sec">个性化建议</h3>
|
||
<ul class="tips" id="tips"></ul>
|
||
</section>
|
||
|
||
<div class="btn-row">
|
||
<button class="main-btn" id="saveBtn">保存本次记录</button>
|
||
<button class="main-btn ghost" id="printBtn" style="flex:0 0 auto;padding:15px 18px;">打印 / PDF</button>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<!-- ================= 趋势 ================= -->
|
||
<div class="tabpage" id="tab-trend">
|
||
<section class="panel">
|
||
<h2><span class="num">📈</span>体重 / BMI 趋势 <span class="hint">最近 20 条</span></h2>
|
||
<div id="chartBox"><canvas id="trendChart"></canvas></div>
|
||
</section>
|
||
<section class="panel">
|
||
<h2><span class="num">📋</span>历史记录</h2>
|
||
<div id="histBox"></div>
|
||
<div class="btn-row" style="margin-top:14px;margin-bottom:0;">
|
||
<button class="main-btn ghost" id="exportBtn">导出 CSV</button>
|
||
<button class="main-btn ghost" id="clearBtn">清空全部</button>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<!-- ================= 说明 ================= -->
|
||
<div class="tabpage" id="tab-doc">
|
||
<section class="panel doc">
|
||
<h4>这个工具算的是什么?</h4>
|
||
<ul>
|
||
<li><b>BMI</b> = 体重(kg) ÷ 身高(m)²,用于粗略评估体重是否健康。肌肉量高的人可能被高估,因此需结合体脂率一起看。</li>
|
||
<li><b>体脂率</b> = 脂肪占体重的比例,比 BMI 更能反映真实胖瘦。</li>
|
||
<li><b>BMR</b> = 完全静息一天消耗的热量;<b>TDEE</b> = BMR × 活动系数,即每日总消耗。</li>
|
||
<li><b>腰高比 / 腰臀比</b> = 评估脂肪分布,腹型肥胖与代谢疾病风险相关。</li>
|
||
</ul>
|
||
|
||
<h4>体脂率公式说明</h4>
|
||
<ul>
|
||
<li><b>美国海军公式</b>:用腰围、颈围(女性加臀围)估算,误差约 ±3%,需测量准确。</li>
|
||
<li><b>RFM(相对脂肪量)</b>:仅用身高与腰围,近年研究认为对多数人较准确。</li>
|
||
<li><b>Deurenberg 公式</b>:由 BMI、年龄、性别推算,没有围度数据时的兜底方案。</li>
|
||
</ul>
|
||
|
||
<h4>代谢公式说明</h4>
|
||
<ul>
|
||
<li><code>Mifflin-St Jeor</code>:目前公认对普通人群最准,无需体脂数据。</li>
|
||
<li><code>Harris-Benedict</code>:经典公式,结果通常比 Mifflin 略高。</li>
|
||
<li><code>Katch-McArdle</code>:基于去脂体重,适合已知体脂率的人。</li>
|
||
<li><code>Cunningham</code>:同样基于去脂体重,常见于运动人群。</li>
|
||
</ul>
|
||
|
||
<h4>参考标准</h4>
|
||
<ul>
|
||
<li>BMI 分级采用中国成人标准:偏瘦 <18.5,正常 18.5–24,超重 24–28,肥胖 ≥28。</li>
|
||
<li>腰高比:<0.4 偏瘦,0.4–0.49 健康,0.5–0.59 风险升高,≥0.6 高风险。</li>
|
||
<li>减脂建议每周减重 0.5%~1% 体重;增肌建议每月 +0.5~1kg。</li>
|
||
</ul>
|
||
|
||
<h4>使用提示</h4>
|
||
<ul>
|
||
<li>测量腰围时自然呼气末测量肚脐水平一周;颈围在喉结下方最细处测量。</li>
|
||
<li>建议每周固定时间(如晨起空腹)测量一次,数据更有可比性。</li>
|
||
<li>记录保存在本机浏览器中,不会上传到任何服务器。</li>
|
||
</ul>
|
||
|
||
<h4>免责声明</h4>
|
||
<p>所有结果均为基于公开公式的估算,仅供日常健康管理参考,<b>不能作为医疗诊断依据</b>。如有肥胖、消瘦、代谢异常等健康问题,请咨询医生或注册营养师。</p>
|
||
</section>
|
||
</div>
|
||
|
||
<p class="foot-note">数据仅保存在本地浏览器 · 结果仅供参考,不能替代专业医疗建议</p>
|
||
</div>
|
||
|
||
<script>
|
||
(function () {
|
||
'use strict';
|
||
|
||
/* ============ 状态 ============ */
|
||
var state = {
|
||
unit: 'metric', // metric | imperial
|
||
gender: 'male',
|
||
goal: 'maintain',
|
||
scheme: 'balanced',
|
||
percent: 15,
|
||
last: null,
|
||
records: []
|
||
};
|
||
|
||
var SCHEMES = {
|
||
balanced: { p: 0.30, c: 0.45, f: 0.25 },
|
||
highprotein: { p: 0.40, c: 0.35, f: 0.25 },
|
||
lowcarb: { p: 0.35, c: 0.25, f: 0.40 }
|
||
};
|
||
|
||
var MEALS = [
|
||
{ name: '早餐', ratio: 0.25 },
|
||
{ name: '午餐', ratio: 0.35 },
|
||
{ name: '晚餐', ratio: 0.30 },
|
||
{ name: '加餐', ratio: 0.10 }
|
||
];
|
||
|
||
var STORE_KEY = 'health_records_v3';
|
||
var $ = function (id) { return document.getElementById(id); };
|
||
|
||
/* ============ 单位 ============ */
|
||
function kgToLb(kg) { return kg * 2.20462; }
|
||
function lbToKg(lb) { return lb / 2.20462; }
|
||
function cmToIn(cm) { return cm / 2.54; }
|
||
function inToCm(i) { return i * 2.54; }
|
||
function round1(x) { return Math.round(x * 10) / 10; }
|
||
|
||
function setUnitLabels() {
|
||
if (state.unit === 'metric') {
|
||
$('hLabel').innerHTML = '身高 (cm)';
|
||
$('wLabel').innerHTML = '体重 (kg)';
|
||
$('unitBtn').textContent = '单位:公制';
|
||
$('height').placeholder = '例如 170';
|
||
$('weight').placeholder = '例如 65';
|
||
} else {
|
||
$('hLabel').innerHTML = '身高 (in)';
|
||
$('wLabel').innerHTML = '体重 (lb)';
|
||
$('unitBtn').textContent = '单位:英制';
|
||
$('height').placeholder = '例如 67';
|
||
$('weight').placeholder = '例如 143';
|
||
}
|
||
}
|
||
|
||
function convertUnitInputs(to) {
|
||
var hEl = $('height'), wEl = $('weight'), twEl = $('targetWeight');
|
||
var h = parseFloat(hEl.value), w = parseFloat(wEl.value), tw = parseFloat(twEl.value);
|
||
var wa = parseFloat($('waist').value), ne = parseFloat($('neck').value), hi = parseFloat($('hip').value);
|
||
|
||
if (to === 'imperial') {
|
||
if (isFinite(h)) hEl.value = round1(cmToIn(h));
|
||
if (isFinite(w)) wEl.value = round1(kgToLb(w));
|
||
if (isFinite(tw)) twEl.value = round1(kgToLb(tw));
|
||
if (isFinite(wa)) $('waist').value = round1(cmToIn(wa));
|
||
if (isFinite(ne)) $('neck').value = round1(cmToIn(ne));
|
||
if (isFinite(hi)) $('hip').value = round1(cmToIn(hi));
|
||
} else {
|
||
if (isFinite(h)) hEl.value = round1(inToCm(h));
|
||
if (isFinite(w)) wEl.value = round1(lbToKg(w));
|
||
if (isFinite(tw)) twEl.value = round1(lbToKg(tw));
|
||
if (isFinite(wa)) $('waist').value = round1(inToCm(wa));
|
||
if (isFinite(ne)) $('neck').value = round1(inToCm(ne));
|
||
if (isFinite(hi)) $('hip').value = round1(inToCm(hi));
|
||
}
|
||
}
|
||
|
||
/* 读取输入并统一转成公制 */
|
||
function readInputs() {
|
||
var f = state.unit === 'metric';
|
||
var h = parseFloat($('height').value);
|
||
var w = parseFloat($('weight').value);
|
||
var tw = parseFloat($('targetWeight').value);
|
||
var wa = parseFloat($('waist').value);
|
||
var ne = parseFloat($('neck').value);
|
||
var hi = parseFloat($('hip').value);
|
||
|
||
if (!f) {
|
||
if (isFinite(h)) h = inToCm(h);
|
||
if (isFinite(w)) w = lbToKg(w);
|
||
if (isFinite(tw)) tw = lbToKg(tw);
|
||
if (isFinite(wa)) wa = inToCm(wa);
|
||
if (isFinite(ne)) ne = inToCm(ne);
|
||
if (isFinite(hi)) hi = inToCm(hi);
|
||
}
|
||
return {
|
||
h: h, w: w, tw: tw, waist: wa, neck: ne, hip: hi,
|
||
age: parseInt($('age').value, 10),
|
||
act: parseFloat($('activity').value),
|
||
targetDate: $('targetDate').value
|
||
};
|
||
}
|
||
|
||
/* ============ 交互 ============ */
|
||
$('unitBtn').addEventListener('click', function () {
|
||
var next = state.unit === 'metric' ? 'imperial' : 'metric';
|
||
convertUnitInputs(next);
|
||
state.unit = next;
|
||
setUnitLabels();
|
||
if (state.last) recalcSilently();
|
||
});
|
||
|
||
$('themeBtn').addEventListener('click', function () {
|
||
document.body.classList.toggle('dark');
|
||
var dark = document.body.classList.contains('dark');
|
||
$('themeBtn').textContent = dark ? '☀️ 日间' : '🌙 夜间';
|
||
if (state.records.length) drawChart();
|
||
});
|
||
|
||
$('tabbar').addEventListener('click', function (e) {
|
||
var b = e.target.closest('button');
|
||
if (!b) return;
|
||
Array.prototype.forEach.call($('tabbar').querySelectorAll('button'), function (x) {
|
||
x.classList.toggle('active', x === b);
|
||
});
|
||
Array.prototype.forEach.call(document.querySelectorAll('.tabpage'), function (p) {
|
||
p.classList.remove('active');
|
||
});
|
||
$('tab-' + b.dataset.tab).classList.add('active');
|
||
if (b.dataset.tab === 'trend') drawChart();
|
||
});
|
||
|
||
$('genderSeg').addEventListener('click', function (e) {
|
||
var b = e.target.closest('button'); if (!b) return;
|
||
state.gender = b.dataset.g;
|
||
activate($('genderSeg'), b);
|
||
$('hipRow').style.display = state.gender === 'female' ? 'flex' : 'none';
|
||
});
|
||
|
||
$('goalSeg').addEventListener('click', function (e) {
|
||
var b = e.target.closest('button'); if (!b) return;
|
||
state.goal = b.dataset.goal;
|
||
activate($('goalSeg'), b);
|
||
$('adjustWrap').style.display = state.goal === 'maintain' ? 'none' : 'flex';
|
||
if (state.last) render(state.last);
|
||
});
|
||
|
||
$('macroSet').addEventListener('click', function (e) {
|
||
var b = e.target.closest('button'); if (!b) return;
|
||
state.scheme = b.dataset.scheme;
|
||
activate($('macroSet'), b);
|
||
if (state.last) render(state.last);
|
||
});
|
||
|
||
$('percent').addEventListener('input', function () {
|
||
state.percent = parseInt(this.value, 10);
|
||
$('percentVal').textContent = state.percent + '%';
|
||
if (state.last) render(state.last);
|
||
});
|
||
|
||
function activate(box, btn) {
|
||
Array.prototype.forEach.call(box.querySelectorAll('button'), function (x) {
|
||
x.classList.toggle('active', x === btn);
|
||
});
|
||
}
|
||
|
||
/* ============ 计算 ============ */
|
||
$('calcBtn').addEventListener('click', function () {
|
||
run(true);
|
||
});
|
||
|
||
function recalcSilently() {
|
||
var d = compute(state.last.in);
|
||
state.last = d;
|
||
render(d);
|
||
}
|
||
|
||
function run(scroll) {
|
||
var inp = readInputs();
|
||
var err = $('err');
|
||
if (!isFinite(inp.h) || !isFinite(inp.w) || !isFinite(inp.age) ||
|
||
inp.h < 50 || inp.h > 260 || inp.w < 10 || inp.w > 400 ||
|
||
inp.age < 1 || inp.age > 120) {
|
||
err.textContent = '请填写有效的身高、体重和年龄(身高 50~260cm,体重 10~400kg,年龄 1~120)。';
|
||
err.classList.add('show');
|
||
$('results').classList.remove('show');
|
||
return;
|
||
}
|
||
err.classList.remove('show');
|
||
var d = compute(inp);
|
||
state.last = d;
|
||
render(d);
|
||
$('results').classList.add('show');
|
||
if (scroll) $('results').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||
}
|
||
|
||
function compute(inp) {
|
||
var h = inp.h, w = inp.w, age = inp.age, act = inp.act;
|
||
var hm = h / 100;
|
||
var bmi = w / (hm * hm);
|
||
var bmiPrime = bmi / 25;
|
||
var ponderal = w / (hm * hm * hm);
|
||
|
||
/* 分级 */
|
||
var cat, color;
|
||
if (bmi < 18.5) { cat = '偏瘦'; color = '#3b82f6'; }
|
||
else if (bmi < 24) { cat = '正常'; color = '#22c55e'; }
|
||
else if (bmi < 28) { cat = '超重'; color = '#f59e0b'; }
|
||
else { cat = '肥胖'; color = '#ef4444'; }
|
||
|
||
/* 腰围指标 */
|
||
var whtr = isFinite(inp.waist) && inp.waist > 0 ? inp.waist / h : null;
|
||
var whr = (isFinite(inp.waist) && isFinite(inp.hip) && inp.hip > 0) ? inp.waist / inp.hip : null;
|
||
|
||
/* --- 体脂率多公式 --- */
|
||
var bfMethods = [];
|
||
var isMale = state.gender === 'male';
|
||
|
||
// 1) 美国海军
|
||
if (isMale && isFinite(inp.waist) && isFinite(inp.neck) && inp.waist > inp.neck) {
|
||
var navy = 495 / (1.0324 - 0.19077 * Math.log10(inp.waist - inp.neck) + 0.15456 * Math.log10(h)) - 450;
|
||
bfMethods.push({ name: '美国海军公式', value: navy, key: 'navy' });
|
||
} else if (!isMale && isFinite(inp.waist) && isFinite(inp.neck) && isFinite(inp.hip) &&
|
||
(inp.waist + inp.hip) > inp.neck) {
|
||
var navyF = 495 / (1.29579 - 0.35004 * Math.log10(inp.waist + inp.hip - inp.neck) + 0.22100 * Math.log10(h)) - 450;
|
||
bfMethods.push({ name: '美国海军公式', value: navyF, key: 'navy' });
|
||
}
|
||
|
||
// 2) RFM
|
||
if (isFinite(inp.waist) && inp.waist > 0) {
|
||
var rfm = isMale ? (64 - 20 * (h / inp.waist)) : (76 - 20 * (h / inp.waist));
|
||
bfMethods.push({ name: 'RFM 相对脂肪量', value: rfm, key: 'rfm' });
|
||
}
|
||
|
||
// 3) Deurenberg(BMI 法)
|
||
var deu = 1.20 * bmi + 0.23 * age - 10.8 * (isMale ? 1 : 0) - 5.4;
|
||
bfMethods.push({ name: 'Deurenberg(BMI 法)', value: deu, key: 'deu' });
|
||
|
||
// 去极端值后取平均
|
||
var valid = bfMethods.filter(function (m) { return isFinite(m.value); });
|
||
var avgBf = valid.reduce(function (a, m) { return a + m.value; }, 0) / (valid.length || 1);
|
||
var bf = Math.max(3, Math.min(65, avgBf));
|
||
|
||
var lean = w * (1 - bf / 100);
|
||
var fatMass = w - lean;
|
||
var ffmi = lean / (hm * hm);
|
||
var ffmiNorm = ffmi + 6.1 * (1.8 - hm);
|
||
|
||
/* --- 代谢公式 --- */
|
||
var s = isMale ? 5 : -161;
|
||
var mifflin = 10 * w + 6.25 * h - 5 * age + s;
|
||
var harris = isMale
|
||
? 88.362 + 13.397 * w + 4.799 * h - 5.677 * age
|
||
: 447.593 + 9.247 * w + 3.098 * h - 4.330 * age;
|
||
var katch = 370 + 21.6 * lean;
|
||
var cunningham = 500 + 22 * lean;
|
||
|
||
var methods = [
|
||
{ name: 'Mifflin-St Jeor', key: 'mifflin', bmr: mifflin },
|
||
{ name: 'Harris-Benedict', key: 'harris', bmr: harris },
|
||
{ name: 'Katch-McArdle', key: 'katch', bmr: katch },
|
||
{ name: 'Cunningham', key: 'cunningham', bmr: cunningham }
|
||
];
|
||
|
||
var hasCircumference = isFinite(inp.waist) || isFinite(inp.neck);
|
||
var pickKey = hasCircumference ? 'katch' : 'mifflin';
|
||
var primary = methods.filter(function (m) { return m.key === pickKey; })[0].bmr;
|
||
|
||
var tdee = primary * act;
|
||
|
||
/* 理想体重 */
|
||
var inOver = Math.max(0, cmToIn(h) - 60);
|
||
var iw = [
|
||
{ n: 'Devine(1974)', v: (isMale ? 50 : 45.5) + 2.3 * inOver },
|
||
{ n: 'Robinson(1983)', v: (isMale ? 52 : 49) + (isMale ? 1.9 : 1.7) * inOver },
|
||
{ n: 'Miller(1983)', v: (isMale ? 56.2 : 53.1) + (isMale ? 1.41 : 1.36) * inOver },
|
||
{ n: 'Hamwi(1964)', v: (isMale ? 48 : 45.5) + (isMale ? 2.7 : 2.2) * inOver },
|
||
{ n: 'BMI 22(健康中枢)', v: 22 * hm * hm }
|
||
];
|
||
var idealMin = 18.5 * hm * hm;
|
||
var idealMax = 23.9 * hm * hm;
|
||
|
||
return {
|
||
in: inp, h: h, w: w, age: age, hm: hm, act: act,
|
||
bmi: bmi, bmiPrime: bmiPrime, ponderal: ponderal, cat: cat, color: color,
|
||
whtr: whtr, whr: whr,
|
||
bfMethods: bfMethods, bf: bf, lean: lean, fatMass: fatMass,
|
||
ffmi: ffmi, ffmiNorm: ffmiNorm,
|
||
methods: methods, pickKey: pickKey, primary: primary,
|
||
mifflin: mifflin, tdee: tdee, katch: katch,
|
||
iw: iw, idealMin: idealMin, idealMax: idealMax
|
||
};
|
||
}
|
||
|
||
/* ============ 渲染 ============ */
|
||
function render(d) {
|
||
var f = state.unit === 'metric';
|
||
var uW = f ? 'kg' : 'lb';
|
||
var convW = function (kg) { return f ? kg : kgToLb(kg); };
|
||
var fmtW = function (kg) { return convW(kg).toFixed(1); };
|
||
|
||
/* BMI 头部 */
|
||
$('bmiValue').innerHTML = d.bmi.toFixed(1) + '<small>kg/m²</small>';
|
||
$('bmiValue').style.color = d.color;
|
||
$('bmiCat').textContent = d.cat;
|
||
$('bmiCat').style.background = d.color;
|
||
$('bmiRange').textContent = '健康体重范围 ' + fmtW(d.idealMin) + ' ~ ' + fmtW(d.idealMax) + ' ' + uW;
|
||
|
||
var pos = Math.max(1.5, Math.min(98.5, (d.bmi - 15) / 25 * 100));
|
||
$('marker').style.left = pos + '%';
|
||
|
||
var risks = [];
|
||
if (d.bmi >= 24) risks.push('<span class="badge">体重相关风险 <b>偏高</b></span>');
|
||
if (d.whtr !== null && d.whtr >= 0.5) risks.push('<span class="badge">腹型肥胖 <b>是</b></span>');
|
||
if (d.whr !== null) {
|
||
var hi = state.gender === 'male' ? 0.9 : 0.85;
|
||
if (d.whr >= hi) risks.push('<span class="badge">腰臀比 <b>偏高</b></span>');
|
||
}
|
||
$('badgeRow').innerHTML = risks.length ? risks.join('') :
|
||
'<span class="badge">主要指标 <b>正常</b></span>';
|
||
|
||
/* 体型指标 */
|
||
$('bmiPrime').textContent = d.bmiPrime.toFixed(2);
|
||
$('ponderal').textContent = d.ponderal.toFixed(1);
|
||
|
||
var whtrEl = $('whtr');
|
||
if (d.whtr === null) { whtrEl.textContent = '—'; $('whtrTag').innerHTML = ''; }
|
||
else {
|
||
whtrEl.textContent = d.whtr.toFixed(2);
|
||
var wt = whtrTag(d.whtr);
|
||
$('whtrTag').innerHTML = '<span class="tag" style="background:' + wt.c + '">' + wt.t + '</span>';
|
||
}
|
||
|
||
var whrEl = $('whr');
|
||
if (d.whr === null) { whrEl.textContent = '—'; $('whrTag').innerHTML = ''; }
|
||
else {
|
||
whrEl.textContent = d.whr.toFixed(2);
|
||
var rt = whrTag(d.whr, state.gender);
|
||
$('whrTag').innerHTML = '<span class="tag" style="background:' + rt.c + '">' + rt.t + '</span>';
|
||
}
|
||
|
||
var notes = [];
|
||
if (d.whtr === null) notes.push('填写腰围可获得腹型肥胖评估(腰高比)。');
|
||
if (d.bmi >= 28) notes.push('BMI 达到肥胖区间,建议关注血压、血糖、血脂并咨询专业医生。');
|
||
else if (d.bmi >= 24) notes.push('BMI 处于超重区间,控制体重有助于降低代谢风险。');
|
||
else if (d.bmi < 18.5) notes.push('体重偏低,注意保证能量与蛋白质摄入。');
|
||
else notes.push('BMI 处于健康区间,继续保持规律饮食与运动。');
|
||
$('riskNote').textContent = notes.join(' ');
|
||
|
||
/* 体成分 */
|
||
$('bodyFat').innerHTML = d.bf.toFixed(1) + '<small> %</small>';
|
||
var fl = fatLevel(d.bf, state.gender);
|
||
$('bfTag').innerHTML = '<span class="tag" style="background:' + fl.color + '">' + fl.label + '</span>';
|
||
$('leanMass').innerHTML = fmtW(d.lean) + ' <small>' + uW + '</small>';
|
||
$('fatMass').innerHTML = fmtW(d.fatMass) + ' <small>' + uW + '</small>';
|
||
$('ffmi').innerHTML = d.ffmiNorm.toFixed(1);
|
||
var ft = ffmiTag(d.ffmiNorm, state.gender);
|
||
$('ffmiTag').innerHTML = '<span class="tag" style="background:' + ft.color + '">' + ft.label + '</span>';
|
||
|
||
var bfRows = '';
|
||
d.bfMethods.forEach(function (m) {
|
||
bfRows += '<tr><td>' + m.name + '</td><td class="num">' + m.value.toFixed(1) + ' %</td></tr>';
|
||
});
|
||
bfRows += '<tr class="pick"><td>综合平均(本次采用)</td><td class="num">' + d.bf.toFixed(1) + ' %</td></tr>';
|
||
$('bfBody').innerHTML = bfRows;
|
||
|
||
/* 理想体重 */
|
||
var iwRows = '';
|
||
d.iw.forEach(function (it) {
|
||
iwRows += '<tr><td>' + it.n + '</td><td class="num">' + fmtW(it.v) + ' ' + uW + '</td></tr>';
|
||
});
|
||
iwRows += '<tr class="pick"><td>健康 BMI 区间(18.5–23.9)</td><td class="num">' +
|
||
fmtW(d.idealMin) + ' ~ ' + fmtW(d.idealMax) + ' ' + uW + '</td></tr>';
|
||
$('iwBody').innerHTML = iwRows;
|
||
|
||
/* 代谢 */
|
||
$('bmr').innerHTML = Math.round(d.primary) + ' <small>kcal</small>';
|
||
$('tdee').innerHTML = Math.round(d.tdee) + ' <small>kcal</small>';
|
||
|
||
var bmrShare = d.primary / d.tdee * 100;
|
||
$('barBmr').style.width = bmrShare.toFixed(1) + '%';
|
||
$('barBmr').style.height = '100%';
|
||
$('barBmr').style.display = 'block';
|
||
$('barTea').style.width = (100 - bmrShare).toFixed(1) + '%';
|
||
$('barTea').style.height = '100%';
|
||
$('barTea').style.display = 'block';
|
||
$('teaBmrTxt').textContent = Math.round(d.primary) + ' kcal(' + bmrShare.toFixed(0) + '%)';
|
||
$('teaTxt').textContent = Math.round(d.tdee - d.primary) + ' kcal(' + (100 - bmrShare).toFixed(0) + '%)';
|
||
|
||
var cmpRows = '';
|
||
d.methods.forEach(function (m) {
|
||
var pick = m.key === d.pickKey ? ' class="pick"' : '';
|
||
cmpRows += '<tr' + pick + '><td>' + m.name + '</td>' +
|
||
'<td class="num">' + Math.round(m.bmr) + '</td>' +
|
||
'<td class="num">' + Math.round(m.bmr * d.act) + '</td></tr>';
|
||
});
|
||
$('cmpBody').innerHTML = cmpRows;
|
||
|
||
/* 目标热量 */
|
||
var target = d.tdee, K = '维持体重每日所需', sub = '', delta = 0;
|
||
if (state.goal === 'cut') {
|
||
target = d.tdee * (1 - state.percent / 100);
|
||
delta = target - d.tdee;
|
||
K = '减脂目标每日摄入';
|
||
sub = '热量缺口 ' + Math.round(-delta) + ' kcal/天';
|
||
} else if (state.goal === 'bulk') {
|
||
target = d.tdee * (1 + state.percent / 100);
|
||
delta = target - d.tdee;
|
||
K = '增肌目标每日摄入';
|
||
sub = '热量盈余 ' + Math.round(delta) + ' kcal/天';
|
||
} else {
|
||
sub = '热量收支平衡';
|
||
}
|
||
$('targetK').textContent = K;
|
||
$('targetV').innerHTML = Math.round(target) + ' <small>kcal</small>';
|
||
$('targetSub').textContent = sub;
|
||
$('deltaKcal').textContent = (delta === 0 ? '0 kcal' :
|
||
(delta > 0 ? '+' + Math.round(delta) : Math.round(delta)) + ' kcal / 天');
|
||
|
||
// 时间估算
|
||
var planNotes = [];
|
||
if (delta !== 0) {
|
||
var weeklyKcal = Math.abs(delta) * 7;
|
||
var weeklyKg = weeklyKcal / 7700;
|
||
var pctPerWeek = weeklyKg / d.w * 100;
|
||
$('duration').textContent = '每周约 ' + (delta < 0 ? '−' : '+') + weeklyKg.toFixed(2) + ' kg';
|
||
planNotes.push('按当前缺口/盈余,每周体重变化约 ' + weeklyKg.toFixed(2) + ' kg(占体重 ' + pctPerWeek.toFixed(1) + '%)。');
|
||
if (pctPerWeek > 1) planNotes.push('⚠️ 减重速度超过每周 1%(或增重过快),建议把幅度调小一些,以保留肌肉与代谢。');
|
||
} else {
|
||
$('duration').textContent = '维持中';
|
||
planNotes.push('维持期建议每 2 周记录一次体重与腰围,若连续变化再调整热量。');
|
||
}
|
||
|
||
// 目标体重倒推
|
||
if (isFinite(d.in.tw) && d.in.tw > 0 && d.in.targetDate) {
|
||
var days = (new Date(d.in.targetDate) - new Date()) / 86400000;
|
||
if (days > 0) {
|
||
var need = (d.in.tw - d.w) * 7700 / days;
|
||
var needCal = d.tdee + need;
|
||
planNotes.push('要在 ' + Math.round(days) + ' 天内达到目标体重 ' + fmtW(d.in.tw) + ' ' + uW +
|
||
',需每天摄入约 ' + Math.round(needCal) + ' kcal(' + (need > 0 ? '盈余' : '缺口') +
|
||
' ' + Math.round(Math.abs(need)) + ' kcal)。');
|
||
if (needCal < d.primary * 0.9) {
|
||
planNotes.push('⚠️ 该热量低于基础代谢的 90%,过于激进,不建议执行,请延长目标时间。');
|
||
}
|
||
} else {
|
||
planNotes.push('目标日期需晚于今天。');
|
||
}
|
||
} else if (isFinite(d.in.tw) && d.in.tw > 0) {
|
||
planNotes.push('填写期望日期可倒推每日所需热量。');
|
||
}
|
||
$('planNote').innerHTML = planNotes.join('<br>');
|
||
|
||
/* 营养素 */
|
||
var sc = SCHEMES[state.scheme];
|
||
var pG = target * sc.p / 4, cG = target * sc.c / 4, fG = target * sc.f / 9;
|
||
$('pG').textContent = Math.round(pG) + ' g';
|
||
$('cG').textContent = Math.round(cG) + ' g';
|
||
$('fG').textContent = Math.round(fG) + ' g';
|
||
$('pBar').style.width = (sc.p / 0.45 * 100) + '%';
|
||
$('cBar').style.width = (sc.c / 0.45 * 100) + '%';
|
||
$('fBar').style.width = (sc.f / 0.45 * 100) + '%';
|
||
var perKg = pG / d.w;
|
||
$('proteinPerKg').textContent = perKg.toFixed(1);
|
||
|
||
var mealHtml = '';
|
||
MEALS.forEach(function (m) {
|
||
mealHtml += '<div class="m"><div class="t">' + m.name + '</div>' +
|
||
'<div class="n">' + Math.round(target * m.ratio) + ' <small>kcal</small></div>' +
|
||
'<div class="t" style="margin-top:3px;">蛋白 ' + Math.round(pG * m.ratio) + 'g</div></div>';
|
||
});
|
||
$('mealBox').innerHTML = mealHtml;
|
||
|
||
/* 饮水 */
|
||
var base = d.w * 35;
|
||
$('water').innerHTML = (base / 1000).toFixed(1) + ' <small>L</small>';
|
||
$('waterSport').innerHTML = d.act >= 1.55 ? '+ 500~800 <small>ml</small>' : '—';
|
||
|
||
/* 建议 */
|
||
$('tips').innerHTML = buildTips(d, target, perKg);
|
||
}
|
||
|
||
function whtrTag(v) {
|
||
if (v < 0.4) return { t: '偏瘦', c: '#3b82f6' };
|
||
if (v < 0.5) return { t: '健康', c: '#22c55e' };
|
||
if (v < 0.6) return { t: '风险升高', c: '#f59e0b' };
|
||
return { t: '高风险', c: '#ef4444' };
|
||
}
|
||
function whrTag(v, gender) {
|
||
if (gender === 'male') {
|
||
if (v < 0.9) return { t: '低风险', c: '#22c55e' };
|
||
if (v < 1.0) return { t: '中风险', c: '#f59e0b' };
|
||
return { t: '高风险', c: '#ef4444' };
|
||
}
|
||
if (v < 0.85) return { t: '低风险', c: '#22c55e' };
|
||
if (v < 0.9) return { t: '中风险', c: '#f59e0b' };
|
||
return { t: '高风险', c: '#ef4444' };
|
||
}
|
||
function fatLevel(bf, gender) {
|
||
if (gender === 'male') {
|
||
if (bf < 6) return { label: '过低', color: '#3b82f6' };
|
||
if (bf < 14) return { label: '运动员', color: '#22c55e' };
|
||
if (bf < 18) return { label: '健康', color: '#22c55e' };
|
||
if (bf < 25) return { label: '偏高', color: '#f59e0b' };
|
||
return { label: '过高', color: '#ef4444' };
|
||
}
|
||
if (bf < 14) return { label: '过低', color: '#3b82f6' };
|
||
if (bf < 21) return { label: '运动员', color: '#22c55e' };
|
||
if (bf < 25) return { label: '健康', color: '#22c55e' };
|
||
if (bf < 32) return { label: '偏高', color: '#f59e0b' };
|
||
return { label: '过高', color: '#ef4444' };
|
||
}
|
||
function ffmiTag(ffmi, gender) {
|
||
if (ffmi < 18) return { label: '偏低', color: '#f59e0b' };
|
||
if (ffmi < 20) return { label: '一般', color: '#f59e0b' };
|
||
if (ffmi < 22) return { label: '良好', color: '#22c55e' };
|
||
if (ffmi < 23) return { label: '优秀', color: '#22c55e' };
|
||
if (ffmi < 26) return { label: '非常优秀', color: '#22c55e' };
|
||
return { label: '极高(需留意)', color: '#ef4444' };
|
||
}
|
||
|
||
function buildTips(d, target, perKg) {
|
||
var t = [];
|
||
if (d.cat === '偏瘦') t.push('体重偏低,建议保证每日蛋白质 1.6~2.0 g/kg,并配合力量训练增肌而非单纯增重。');
|
||
else if (d.cat === '正常') t.push('BMI 处于健康区间,保持规律作息与每周 150 分钟中等强度运动即可。');
|
||
else if (d.cat === '超重') t.push('超重阶段,减掉 5%~10% 体重即可显著改善血压、血糖与血脂。');
|
||
else t.push('BMI 已达肥胖区间,建议在医生或注册营养师指导下制定计划,并筛查相关代谢指标。');
|
||
|
||
if (!d.in.waist) t.push('补充腰围数据可评估腹型肥胖,腹型肥胖比总体肥胖风险更高。');
|
||
|
||
if (state.goal === 'cut') {
|
||
t.push('减脂期:热量缺口控制在 TDEE 的 10%~20%,每周减重不超过体重的 1%。');
|
||
t.push('蛋白质建议 1.6~2.2 g/kg(当前约 ' + perKg.toFixed(1) + ' g/kg),可最大程度保留肌肉。');
|
||
} else if (state.goal === 'bulk') {
|
||
t.push('增肌期:热量盈余 10%~20% 较理想,可减少脂肪堆积。');
|
||
t.push('蛋白质建议 1.6~2.0 g/kg,并配合渐进超负荷的力量训练。');
|
||
} else {
|
||
t.push('维持期:体重稳定即可,可关注腰围与体脂率的变化趋势。');
|
||
}
|
||
|
||
if (d.bf >= (state.gender === 'male' ? 25 : 32)) {
|
||
t.push('体脂率偏高,建议每周 3~5 次有氧(快走、慢跑、游泳)+ 2 次力量训练。');
|
||
}
|
||
if (d.bf < (state.gender === 'male' ? 8 : 15)) {
|
||
t.push('体脂率偏低,注意保证必需脂肪酸摄入(每日脂肪不低于 0.6 g/kg 体重)。');
|
||
}
|
||
t.push('定期监测:每周固定时间测量体重、腰围,趋势比单次数字更重要。');
|
||
t.push('睡眠与压力会显著影响食欲与代谢,保证每晚 7~9 小时睡眠。');
|
||
return '<li>' + t.join('</li><li>') + '</li>';
|
||
}
|
||
|
||
/* ============ 记录与趋势 ============ */
|
||
try { state.records = JSON.parse(localStorage.getItem(STORE_KEY) || '[]'); } catch (e) { state.records = []; }
|
||
|
||
$('saveBtn').addEventListener('click', function () {
|
||
if (!state.last) return;
|
||
var d = state.last;
|
||
state.records.unshift({
|
||
time: new Date().toLocaleString('zh-CN', { hour12: false }),
|
||
bmi: +d.bmi.toFixed(1), cat: d.cat, color: d.color,
|
||
bf: +d.bf.toFixed(1), tdee: Math.round(d.tdee),
|
||
w: round1(d.w), unit: state.unit
|
||
});
|
||
state.records = state.records.slice(0, 60);
|
||
persist();
|
||
renderHistory();
|
||
$('saveBtn').textContent = '✓ 已保存';
|
||
setTimeout(function () { $('saveBtn').textContent = '保存本次记录'; }, 1400);
|
||
});
|
||
|
||
$('clearBtn').addEventListener('click', function () {
|
||
if (!state.records.length) return;
|
||
if (!confirm('确定要清空全部历史记录吗?')) return;
|
||
state.records = [];
|
||
persist();
|
||
renderHistory();
|
||
drawChart();
|
||
});
|
||
|
||
$('exportBtn').addEventListener('click', function () {
|
||
if (!state.records.length) { alert('暂无记录可导出。'); return; }
|
||
var rows = [['时间', '体重(kg)', 'BMI', '分级', '体脂率(%)', 'TDEE(kcal)']];
|
||
state.records.forEach(function (r) {
|
||
rows.push([r.time, r.w, r.bmi, r.cat, r.bf, r.tdee]);
|
||
});
|
||
var csv = rows.map(function (r) { return r.join(','); }).join('\n');
|
||
var blob = new Blob(['\ufeff' + csv], { type: 'text/csv;charset=utf-8;' });
|
||
var a = document.createElement('a');
|
||
a.href = URL.createObjectURL(blob);
|
||
a.download = 'health-records.csv';
|
||
a.click();
|
||
URL.revokeObjectURL(a.href);
|
||
});
|
||
|
||
$('printBtn').addEventListener('click', function () { window.print(); });
|
||
|
||
function persist() {
|
||
try { localStorage.setItem(STORE_KEY, JSON.stringify(state.records)); } catch (e) {}
|
||
}
|
||
|
||
function renderHistory() {
|
||
var box = $('histBox');
|
||
if (!state.records.length) {
|
||
box.innerHTML = '<p class="hist-empty">暂无记录<br>计算后点击"保存本次记录"即可追踪趋势</p>';
|
||
return;
|
||
}
|
||
var html = '<table class="hist"><thead><tr>' +
|
||
'<th>时间</th><th>体重</th><th>BMI</th><th>体脂</th><th>TDEE</th><th></th>' +
|
||
'</tr></thead><tbody>';
|
||
state.records.forEach(function (r, i) {
|
||
html += '<tr>' +
|
||
'<td>' + r.time + '</td>' +
|
||
'<td class="num">' + r.w + ' kg</td>' +
|
||
'<td class="num"><span class="dot" style="background:' + r.color + '"></span>' + r.bmi + '</td>' +
|
||
'<td class="num">' + r.bf + '%</td>' +
|
||
'<td class="num">' + r.tdee + '</td>' +
|
||
'<td><button class="del" data-i="' + i + '">×</button></td>' +
|
||
'</tr>';
|
||
});
|
||
html += '</tbody></table>';
|
||
box.innerHTML = html;
|
||
|
||
Array.prototype.forEach.call(box.querySelectorAll('.del'), function (b) {
|
||
b.addEventListener('click', function () {
|
||
state.records.splice(parseInt(b.dataset.i, 10), 1);
|
||
persist();
|
||
renderHistory();
|
||
drawChart();
|
||
});
|
||
});
|
||
}
|
||
|
||
function drawChart() {
|
||
var cv = $('trendChart');
|
||
if (!cv) return;
|
||
var box = $('chartBox');
|
||
var W = box.clientWidth || 600;
|
||
var H = 220;
|
||
var dpr = window.devicePixelRatio || 1;
|
||
cv.width = W * dpr;
|
||
cv.height = H * dpr;
|
||
cv.style.height = H + 'px';
|
||
var ctx = cv.getContext('2d');
|
||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||
ctx.clearRect(0, 0, W, H);
|
||
|
||
var dark = document.body.classList.contains('dark');
|
||
var gridColor = dark ? '#2c3040' : '#e8eaf0';
|
||
var textColor = dark ? '#9aa1b5' : '#6b7280';
|
||
var lineColor = '#6d5efc';
|
||
|
||
var recs = state.records.slice(0, 20).reverse(); // 时间升序
|
||
if (recs.length < 2) {
|
||
ctx.fillStyle = textColor;
|
||
ctx.font = '13px -apple-system, "PingFang SC", sans-serif';
|
||
ctx.textAlign = 'center';
|
||
ctx.fillText('至少保存 2 条记录后才能显示趋势图', W / 2, H / 2);
|
||
return;
|
||
}
|
||
|
||
var padL = 42, padR = 16, padT = 18, padB = 30;
|
||
var plotW = W - padL - padR;
|
||
var plotH = H - padT - padB;
|
||
|
||
var vals = recs.map(function (r) { return r.w; });
|
||
var min = Math.min.apply(null, vals);
|
||
var max = Math.max.apply(null, vals);
|
||
if (max - min < 1) { max += 0.5; min -= 0.5; }
|
||
var pad = (max - min) * 0.15;
|
||
min -= pad; max += pad;
|
||
|
||
var x = function (i) { return padL + (recs.length === 1 ? plotW / 2 : plotW * i / (recs.length - 1)); };
|
||
var y = function (v) { return padT + plotH - (v - min) / (max - min) * plotH; };
|
||
|
||
// 网格与刻度
|
||
ctx.strokeStyle = gridColor;
|
||
ctx.fillStyle = textColor;
|
||
ctx.lineWidth = 1;
|
||
ctx.font = '10.5px -apple-system, "PingFang SC", sans-serif';
|
||
ctx.textAlign = 'right';
|
||
ctx.textBaseline = 'middle';
|
||
var ticks = 4;
|
||
for (var i = 0; i <= ticks; i++) {
|
||
var v = min + (max - min) * i / ticks;
|
||
var yy = y(v);
|
||
ctx.beginPath();
|
||
ctx.moveTo(padL, yy);
|
||
ctx.lineTo(W - padR, yy);
|
||
ctx.stroke();
|
||
ctx.fillText(v.toFixed(1), padL - 7, yy);
|
||
}
|
||
|
||
// 折线
|
||
ctx.strokeStyle = lineColor;
|
||
ctx.lineWidth = 2.4;
|
||
ctx.lineJoin = 'round';
|
||
ctx.beginPath();
|
||
recs.forEach(function (r, i) {
|
||
if (i === 0) ctx.moveTo(x(i), y(r.w));
|
||
else ctx.lineTo(x(i), y(r.w));
|
||
});
|
||
ctx.stroke();
|
||
|
||
// 渐变填充
|
||
var grad = ctx.createLinearGradient(0, padT, 0, padT + plotH);
|
||
grad.addColorStop(0, 'rgba(109,94,252,.28)');
|
||
grad.addColorStop(1, 'rgba(109,94,252,0)');
|
||
ctx.beginPath();
|
||
ctx.moveTo(x(0), padT + plotH);
|
||
recs.forEach(function (r, i) { ctx.lineTo(x(i), y(r.w)); });
|
||
ctx.lineTo(x(recs.length - 1), padT + plotH);
|
||
ctx.closePath();
|
||
ctx.fillStyle = grad;
|
||
ctx.fill();
|
||
|
||
// 数据点
|
||
recs.forEach(function (r, i) {
|
||
ctx.beginPath();
|
||
ctx.arc(x(i), y(r.w), 4, 0, Math.PI * 2);
|
||
ctx.fillStyle = '#fff';
|
||
ctx.fill();
|
||
ctx.lineWidth = 2.4;
|
||
ctx.strokeStyle = lineColor;
|
||
ctx.stroke();
|
||
});
|
||
|
||
// 首尾标签
|
||
ctx.fillStyle = textColor;
|
||
ctx.textBaseline = 'top';
|
||
ctx.font = '10px -apple-system, "PingFang SC", sans-serif';
|
||
ctx.textAlign = 'left';
|
||
ctx.fillText(recs[0].time.slice(0, 10), padL, H - padB + 8);
|
||
ctx.textAlign = 'right';
|
||
ctx.fillText(recs[recs.length - 1].time.slice(0, 10), W - padR, H - padB + 8);
|
||
}
|
||
|
||
window.addEventListener('resize', function () {
|
||
if ($('tab-trend').classList.contains('active')) drawChart();
|
||
});
|
||
|
||
/* ============ 示例 / 重置 ============ */
|
||
$('demoBtn').addEventListener('click', function () {
|
||
if (state.unit === 'imperial') { state.unit = 'metric'; setUnitLabels(); }
|
||
$('height').value = 170;
|
||
$('weight').value = 72;
|
||
$('age').value = 28;
|
||
$('waist').value = 84;
|
||
$('neck').value = 37;
|
||
$('hip').value = 95;
|
||
state.gender = 'male';
|
||
activate($('genderSeg'), $('genderSeg').querySelector('[data-g="male"]'));
|
||
$('hipRow').style.display = 'none';
|
||
run(true);
|
||
});
|
||
|
||
$('resetBtn').addEventListener('click', function () {
|
||
['height','weight','age','waist','neck','hip','targetWeight','targetDate'].forEach(function (id) {
|
||
$(id).value = '';
|
||
});
|
||
$('results').classList.remove('show');
|
||
$('err').classList.remove('show');
|
||
state.last = null;
|
||
if (state.unit === 'imperial') { state.unit = 'metric'; setUnitLabels(); }
|
||
});
|
||
|
||
/* ============ 初始化 ============ */
|
||
setUnitLabels();
|
||
renderHistory();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|