- 按项目书五部分结构做成可填写表单:封面/1.理想热量摄入/2.理想营养摄入/3.真实数据核验/4.方案迭代/5.评价 - 自动计算 BMR(含女性公式 −161)、TDEE、热量目标(维持/减脂/增肌),并显示代入数据的计算过程 - 营养素目标按 14–17 岁参考值自动推荐(碳水 55%、脂肪 25%、蛋白 1.6 g/kg),可手动覆盖 - 3 天真实饮食记录:食物库查表自动算热量与三大营养素,自动生成 3.2 核验对照表、偏差与合格/基本合格/不合格判定 - 核验结果自动汇总到 3.2 与 5.1,支持打印/存 PDF、导出 Markdown、导出/导入 JSON、载入示例数据
1673 lines
89 KiB
HTML
1673 lines
89 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>《我的健康饮食方案》项目书 · 可交互版</title>
|
||
<style>
|
||
:root{
|
||
--teal:#0d9488; --teal-d:#0f766e; --ink:#1f2933; --muted:#6b7280;
|
||
--line:#e3e8ee; --bg:#f4f6f8; --blue:#2563eb; --amber:#b45309;
|
||
--ok:#047857; --okbg:#d1fae5; --midbg:#fef3c7; --badbg:#fee2e2; --bad:#b91c1c;
|
||
}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--ink);
|
||
font:14px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;}
|
||
h1{font-size:22px;margin:0;letter-spacing:.3px}
|
||
h2{font-size:16px;margin:0 0 14px;color:var(--teal-d);display:flex;align-items:center;gap:8px}
|
||
h3{font-size:14px;margin:16px 0 8px}
|
||
p{margin:0 0 10px}
|
||
.app-head{position:sticky;top:0;z-index:20;background:#fff;border-bottom:1px solid var(--line);box-shadow:0 1px 3px rgba(0,0,0,.05)}
|
||
.head-inner{max-width:1040px;margin:0 auto;padding:14px 20px 10px;display:flex;gap:16px;justify-content:space-between;align-items:flex-start;flex-wrap:wrap}
|
||
.sub{color:var(--muted);font-size:12.5px;margin:6px 0 0}
|
||
.actions{display:flex;gap:8px;flex-wrap:wrap}
|
||
.tabs{max-width:1040px;margin:0 auto;padding:0 20px;display:flex;gap:4px;overflow-x:auto}
|
||
.tab{background:none;border:none;border-bottom:2px solid transparent;padding:10px 12px;font:inherit;font-size:13.5px;color:var(--muted);cursor:pointer;white-space:nowrap}
|
||
.tab.active{color:var(--teal-d);border-bottom-color:var(--teal);font-weight:600}
|
||
main{max-width:1040px;margin:0 auto;padding:20px}
|
||
.panel{display:none}
|
||
.panel.active{display:block}
|
||
.card{background:#fff;border-radius:12px;padding:20px;margin-bottom:16px;box-shadow:0 1px 3px rgba(0,0,0,.06)}
|
||
label{display:block;font-size:12px;color:var(--muted);margin-bottom:4px}
|
||
input[type=number],input[type=text],input[type=date],select,textarea{
|
||
width:100%;padding:8px 10px;border:1px solid #d1d5db;border-radius:8px;font-size:14px;
|
||
background:#fff;color:var(--ink);font-family:inherit}
|
||
textarea{resize:vertical;line-height:1.6}
|
||
input:focus,select:focus,textarea:focus{outline:2px solid var(--teal);outline-offset:-1px;border-color:var(--teal)}
|
||
input[readonly]{background:#f9fafb}
|
||
.grid{display:grid;gap:14px}
|
||
.g2{grid-template-columns:1fr 1fr}
|
||
.g3{grid-template-columns:repeat(3,1fr)}
|
||
.g4{grid-template-columns:repeat(4,1fr)}
|
||
.mt{margin-top:14px}
|
||
.radios{display:flex;gap:16px;padding-top:7px}
|
||
.radios label{display:flex;align-items:center;gap:6px;font-size:14px;color:var(--ink);margin:0;cursor:pointer}
|
||
.radios input{width:auto}
|
||
.btn{padding:8px 14px;border:none;border-radius:8px;background:var(--teal);color:#fff;font:inherit;font-size:13.5px;font-weight:500;cursor:pointer}
|
||
.btn:hover{background:var(--teal-d)}
|
||
.btn.ghost{background:#eef2f3;color:#3f4d55}
|
||
.btn.ghost:hover{background:#e2e8ea}
|
||
.btn.danger{background:#fee2e2;color:#b91c1c}
|
||
.btn.danger:hover{background:#fecaca}
|
||
.btn-link{background:none;border:none;color:var(--teal-d);font:inherit;font-size:12.5px;cursor:pointer;padding:2px 0;text-decoration:underline}
|
||
.link-del{background:none;border:none;color:#b91c1c;font:inherit;font-size:12.5px;cursor:pointer;text-decoration:underline}
|
||
table{width:100%;border-collapse:collapse;font-size:13.5px}
|
||
th,td{padding:8px;text-align:left;border-bottom:1px solid #eef1f4;vertical-align:middle}
|
||
th{font-size:12px;color:var(--muted);font-weight:600;background:#fafbfc}
|
||
.num{text-align:right;font-variant-numeric:tabular-nums}
|
||
.small{font-size:12.5px;color:#4b5563}
|
||
.nowrap{white-space:nowrap}
|
||
.empty{color:#9aa5ad;text-align:center;padding:16px 0}
|
||
.note{font-size:12.5px;color:var(--muted);line-height:1.75}
|
||
.hint{font-size:12px;color:#9aa5ad;margin-top:6px;line-height:1.6}
|
||
.hero{background:linear-gradient(135deg,#0f766e,#14b8a6);color:#fff;border-radius:12px;padding:22px;margin-bottom:16px}
|
||
.hero .desc{font-size:13px;opacity:.92}
|
||
.hero .big{font-size:40px;font-weight:700;line-height:1.15;margin-top:2px}
|
||
.hero .unit{font-size:15px;font-weight:400;opacity:.9}
|
||
.hero-sub{font-size:13px;opacity:.95;margin-top:4px}
|
||
.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:12.5px}
|
||
.chip b{display:block;font-size:16px;font-weight:600}
|
||
.tag{display:inline-block;font-size:11px;padding:1px 8px;border-radius:99px;background:#e5e7eb;color:#4b5563}
|
||
.tag.ok{background:var(--okbg);color:var(--ok)}
|
||
.tag.mid{background:var(--midbg);color:var(--amber)}
|
||
.tag.bad{background:var(--badbg);color:var(--bad)}
|
||
.tag.auto{background:#e0f2fe;color:#0369a1}
|
||
.tag.manual{background:#fef3c7;color:#92400e}
|
||
.tag.na{background:#f1f5f9;color:#94a3b8}
|
||
.formula{background:#0f172a;color:#e2e8f0;border-radius:10px;padding:14px 16px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap}
|
||
.formula b{color:#5eead4}
|
||
.formula .cmt{color:#94a3b8}
|
||
.kv th{width:190px;background:#fafbfc;font-size:13px;color:#374151}
|
||
.mini{font-size:12.5px}
|
||
.mini tr.hl td{background:#ecfdf5;font-weight:600}
|
||
.cols{display:grid;grid-template-columns:1fr 1fr;gap:0 28px}
|
||
.row-between{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap}
|
||
.num-in{width:96px;text-align:right;display:inline-block}
|
||
.unit-in{font-size:12px;color:var(--muted);margin-left:4px}
|
||
.inline-num{width:110px;display:inline-block;margin-left:8px}
|
||
.chk{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:#374151;margin:0 0 0 12px}
|
||
.chk input{width:auto}
|
||
.auto-val{font-weight:700;font-size:17px;color:var(--teal-d)}
|
||
.big-num{font-size:20px}
|
||
.auto-text{font-size:13.5px;background:#f8fafc;border-left:3px solid var(--teal);padding:10px 12px;border-radius:0 8px 8px 0}
|
||
.day-tabs{display:flex;gap:6px;margin:4px 0 14px;flex-wrap:wrap}
|
||
.dtab{padding:6px 14px;border:1px solid var(--line);background:#fff;border-radius:99px;font:inherit;font-size:13px;color:var(--muted);cursor:pointer}
|
||
.dtab.active{background:var(--teal);border-color:var(--teal);color:#fff;font-weight:600}
|
||
.day-panel{display:none;border:1px dashed var(--line);border-radius:10px;padding:16px}
|
||
.day-panel.active{display:block}
|
||
.day-head{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:12px}
|
||
.food-add{display:grid;grid-template-columns:110px 1fr 120px 84px;gap:10px;align-items:end;margin-top:12px}
|
||
.msg{font-size:12.5px;min-height:18px;margin-top:6px}
|
||
.msg.ok{color:var(--ok)}
|
||
.msg.err{color:var(--bad)}
|
||
.progress{height:12px;background:#e8edf0;border-radius:99px;overflow:hidden;margin:12px 0 8px}
|
||
.progress i{display:block;height:100%;background:linear-gradient(90deg,#14b8a6,#0d9488);transition:width .25s}
|
||
.progress i.over{background:linear-gradient(90deg,#f59e0b,#dc2626)}
|
||
.prog-label{display:flex;justify-content:space-between;font-size:12.5px;color:#4b5563;font-variant-numeric:tabular-nums;gap:10px;flex-wrap:wrap}
|
||
.macro-bar{height:12px;border-radius:99px;overflow:hidden;display:flex;margin:8px 0 6px;background:#eef1f4}
|
||
.macro-bar span{height:100%}
|
||
.legend-line{font-size:12.5px;color:#4b5563;margin-top:10px}
|
||
.qual-row{display:flex;gap:16px;align-items:center;margin-top:12px;flex-wrap:wrap}
|
||
.qual-row>span.q-label{font-size:12px;color:var(--muted)}
|
||
.qual-row label{display:flex;align-items:center;gap:6px;font-size:12.5px;color:#374151;margin:0}
|
||
.qual-row select{width:auto;padding:5px 8px;font-size:12.5px}
|
||
.q{display:flex;gap:12px;margin-bottom:16px}
|
||
.q-num{flex:0 0 24px;height:24px;border-radius:50%;background:var(--teal);color:#fff;font-size:12.5px;display:flex;align-items:center;justify-content:center;font-weight:600}
|
||
.chips-row{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0}
|
||
.chip-btn{font-size:12.5px;padding:4px 10px;border:1px solid var(--line);border-radius:99px;background:#fff;cursor:pointer;font-family:inherit;color:#374151}
|
||
.chip-btn:hover{background:#f1f5f9}
|
||
.iter{border:1px solid var(--line);border-radius:10px;padding:14px;margin-bottom:14px;background:#fcfdfd}
|
||
.iter-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}
|
||
.inline-flex{display:flex;gap:8px;align-items:center}
|
||
.summary-card{background:#f0fdfa;border:1px solid #99f6e4;border-radius:10px;padding:14px 16px;margin-top:18px}
|
||
.summary-card h3{margin:0 0 8px;color:var(--teal-d)}
|
||
.sum-row{font-size:13px;padding:4px 0;border-bottom:1px dashed #ccfbf1}
|
||
.sum-row:last-child{border-bottom:none}
|
||
.steps{margin:0 0 14px;padding-left:20px;font-size:13.5px;color:#374151}
|
||
.steps li{margin-bottom:4px}
|
||
.check{display:flex;align-items:center;gap:10px;font-size:13.5px;padding:7px 0;border-bottom:1px dashed var(--line)}
|
||
.check:last-child{border-bottom:none}
|
||
.check .mark{width:20px;height:20px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:12px;background:#e5e7eb;color:#6b7280}
|
||
.check.done .mark{background:var(--okbg);color:var(--ok)}
|
||
.check.done{color:var(--ok);font-weight:600}
|
||
.pct-row{display:flex;align-items:center;gap:6px;font-size:13.5px}
|
||
.tiny{width:64px;display:inline-block}
|
||
.verdict-box{margin-top:14px;background:#f8fafc;border-radius:10px;padding:12px 14px;font-size:13px;line-height:1.9}
|
||
.review-table td:first-child{font-size:13px}
|
||
.review-table th:not(:first-child),.review-table td:not(:first-child){width:74px;text-align:center}
|
||
.review-table input[type=radio]{width:auto}
|
||
.toast{position:fixed;left:50%;transform:translateX(-50%);bottom:26px;background:#0f172a;color:#fff;padding:10px 18px;border-radius:99px;font-size:13px;opacity:0;transition:opacity .25s;pointer-events:none;z-index:60}
|
||
.toast.show{opacity:.94}
|
||
dialog{border:none;border-radius:12px;padding:0;max-width:760px;width:92%;box-shadow:0 20px 50px rgba(0,0,0,.25)}
|
||
dialog::backdrop{background:rgba(15,23,42,.5)}
|
||
.dlg-head{padding:16px 20px;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center}
|
||
.dlg-body{padding:16px 20px}
|
||
.dlg-body textarea{height:320px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12.5px}
|
||
.print-only{display:none}
|
||
@media (max-width:760px){
|
||
.g2,.g3,.g4,.cols,.day-head{grid-template-columns:1fr}
|
||
.food-add{grid-template-columns:1fr 1fr}
|
||
.hero .big{font-size:32px}
|
||
}
|
||
@media print{
|
||
body{background:#fff}
|
||
.app-head .actions,.tabs,.noprint{display:none!important}
|
||
.app-head{position:static;box-shadow:none}
|
||
.panel{display:block!important;page-break-after:always}
|
||
.panel:last-child{page-break-after:auto}
|
||
.day-panel{display:block!important;border:none;padding:0;margin-bottom:14px}
|
||
.day-tabs{display:none}
|
||
.card{box-shadow:none;border:1px solid var(--line);page-break-inside:avoid}
|
||
.print-only{display:block;font-size:12.5px;color:#374151;margin-top:8px}
|
||
input,select,textarea{border:none;border-bottom:1px solid #cbd5e1;border-radius:0;padding:2px 4px}
|
||
.btn,.btn-link,.link-del,.chip-btn{display:none!important}
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<header class="app-head">
|
||
<div class="head-inner">
|
||
<div>
|
||
<h1>《我的健康饮食方案》项目书</h1>
|
||
<p class="sub">可交互版 · 边填边算 · 自动汇总到 3.2 与 5.1 · 可直接打印或导出</p>
|
||
<div class="print-only" id="printMeta"></div>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn" id="btnPrint">🖨 打印 / 存为 PDF</button>
|
||
<button class="btn ghost" id="btnMd">查看 Markdown</button>
|
||
<button class="btn ghost" id="btnExport">导出 JSON</button>
|
||
<button class="btn ghost" id="btnImport">导入 JSON</button>
|
||
<button class="btn ghost" id="btnDemo">载入示例数据</button>
|
||
<button class="btn danger" id="btnClear">清空</button>
|
||
<input type="file" id="fileInput" accept=".json,application/json" hidden>
|
||
</div>
|
||
</div>
|
||
<nav class="tabs" id="tabs">
|
||
<button class="tab active" data-tab="ov">封面与进度</button>
|
||
<button class="tab" data-tab="p1">一、理想热量摄入</button>
|
||
<button class="tab" data-tab="p2">二、理想营养摄入</button>
|
||
<button class="tab" data-tab="p3">三、真实数据核验</button>
|
||
<button class="tab" data-tab="p4">四、方案迭代</button>
|
||
<button class="tab" data-tab="p5">五、评价</button>
|
||
</nav>
|
||
</header>
|
||
|
||
<main>
|
||
<!-- ================= 封面与进度 ================= -->
|
||
<section class="panel active" id="tab-ov">
|
||
<div class="card">
|
||
<h2>封面信息</h2>
|
||
<div class="grid g3">
|
||
<div><label>学号</label><input type="text" data-k="meta.sid" placeholder="如 17"></div>
|
||
<div><label>姓名</label><input type="text" data-k="meta.name" placeholder="填写你的姓名"></div>
|
||
<div><label>班级</label><input type="text" data-k="meta.cls" placeholder="如 高一(3)班"></div>
|
||
</div>
|
||
<p class="note" style="margin-top:12px">
|
||
使用说明:本项目书记录你完成《我的健康饮食方案》项目的全过程 ——
|
||
<b>先算出理想目标(第一、二部分)→ 用真实饮食数据核验(第三部分)→ 调整方案并再验证(第四部分)→ 自评与互评(第五部分)</b>。
|
||
带底色的数字是自动算出来的,可以直接改;改过之后会标记为「手动」。不会填的地方先留空,下次课提问。
|
||
</p>
|
||
</div>
|
||
|
||
<div class="hero">
|
||
<div class="desc">我的每日热量摄入目标</div>
|
||
<div class="big"><span id="ovTargetKcal">0</span> <span class="unit">kcal / 天</span></div>
|
||
<div class="hero-sub" id="ovGoalText">—</div>
|
||
<div class="chips">
|
||
<div class="chip">BMI<b id="ovBmi">—</b></div>
|
||
<div class="chip">基础代谢 BMR<b id="ovBmr">—</b></div>
|
||
<div class="chip">总消耗 TDEE<b id="ovTdee">—</b></div>
|
||
<div class="chip">3 天平均摄入<b id="ovAvg">—</b></div>
|
||
<div class="chip">达成率<b id="ovRate">—</b></div>
|
||
<div class="chip">核验判定<b id="ovVerdict">—</b></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>四步流程与填写进度</h2>
|
||
<ol class="steps">
|
||
<li>第一部分(第 1 课):算 BMR → TDEE → 定每日热量目标</li>
|
||
<li>第二部分(第 2 课):定 8 项每日营养目标,并写出依据</li>
|
||
<li>第三部分(第 3 课):连续 3 天真实饮食记录 + 对照 + 结论</li>
|
||
<li>第四部分:一次只改 1–2 个问题,改完再验证 3 天</li>
|
||
<li>第五部分:自评 + 同伴互评</li>
|
||
</ol>
|
||
<div id="progressList"></div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ================= 第一部分 ================= -->
|
||
<section class="panel" id="tab-p1">
|
||
<div class="card">
|
||
<h2>1.1 我的基础数据</h2>
|
||
<div class="grid g4">
|
||
<div><label>年龄(岁)</label><input type="number" data-k="p1.age" min="8" max="90" step="1"></div>
|
||
<div>
|
||
<label>性别</label>
|
||
<div class="radios">
|
||
<label><input type="radio" name="sex" data-k="p1.sex" value="male">男</label>
|
||
<label><input type="radio" name="sex" data-k="p1.sex" value="female">女</label>
|
||
</div>
|
||
</div>
|
||
<div><label>身高(cm)</label><input type="number" data-k="p1.height" min="100" max="220" step="0.5"></div>
|
||
<div><label>体重(kg)</label><input type="number" data-k="p1.weight" min="25" max="200" step="0.1"></div>
|
||
<div class="span2" style="grid-column:span 2">
|
||
<label>日常活动水平</label>
|
||
<select data-k="p1.activity">
|
||
<option value="sedentary">久坐(几乎不运动)</option>
|
||
<option value="light">轻度(每周训练 1–3 次)</option>
|
||
<option value="moderate">中度(每周训练 3–5 次)</option>
|
||
<option value="active">高强度(每周训练 6–7 次)</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<table class="mini mt">
|
||
<thead><tr><th>活动水平</th><th>说明</th><th class="num">活动系数</th></tr></thead>
|
||
<tbody id="actBody"></tbody>
|
||
</table>
|
||
<p class="hint">提示:活动系数直接决定 TDEE,同一组基础数据选「久坐」和选「高强度」可以差 700 kcal 以上 —— 本项目统一使用上表中你选定的这一种。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>1.2 热量计算过程</h2>
|
||
<div class="formula" id="calcFormula">—</div>
|
||
<div class="mt">
|
||
<label>我的计算过程 / 补充说明(可选)</label>
|
||
<textarea data-k="p1.calcNote" rows="3" placeholder="写出公式并代入你的数据,例如:BMR = 10×62 + 6.25×175 − 5×17 + 5 = 1594 kcal;不会填的地方标「?」,下节课问老师。"></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>1.3 我的热量目标</h2>
|
||
<table class="kv">
|
||
<tbody>
|
||
<tr><th>每日总消耗(TDEE)</th>
|
||
<td><span class="auto-val" id="tddeOut">—</span> kcal
|
||
<span class="hint" style="display:inline;margin-left:8px">= BMR × 活动系数</span></td></tr>
|
||
<tr><th>目标方向</th>
|
||
<td>
|
||
<select data-k="p1.goal" style="width:auto;display:inline-block">
|
||
<option value="maintain">维持体重(保持现在的状态)</option>
|
||
<option value="cut">减脂(少吃一点)</option>
|
||
<option value="bulk">增肌 / 增重(多吃一点)</option>
|
||
</select>
|
||
<span id="adjustWrap" style="margin-left:12px">调整幅度
|
||
<select data-k="p1.adjust" id="adjustSel" style="width:auto;display:inline-block"></select> kcal
|
||
</span>
|
||
</td></tr>
|
||
<tr><th>每日热量摄入目标</th>
|
||
<td><span class="auto-val big-num" id="kcalOut">—</span> kcal
|
||
<label class="chk"><input type="checkbox" id="chkManual"> 手动设定</label>
|
||
<input type="number" class="inline-num" id="kcalOverride" data-k="p1.kcalOverride" placeholder="kcal">
|
||
</td></tr>
|
||
<tr><th>目标理由</th>
|
||
<td><textarea data-k="p1.reason" rows="2" placeholder="例:BMI 21.4 属正常、体重近半年稳定,所以选择维持;公式估算存在约 ±15% 误差,先按自动算出的数值试 2 周,再按体重变化调整。"></textarea></td></tr>
|
||
</tbody>
|
||
</table>
|
||
<p class="note" style="margin-top:12px">
|
||
关系说明:<b>维持体重 = TDEE;减脂 = TDEE − 300~500 kcal;增肌 = TDEE + 300~500 kcal</b>。<br>
|
||
BMI 参考:< 18.5 偏瘦|18.5–23.9 正常|24–27.9 超重|≥ 28 肥胖。<span id="bmiHint"></span>
|
||
</p>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ================= 第二部分 ================= -->
|
||
<section class="panel" id="tab-p2">
|
||
<div class="card">
|
||
<h2>2.1 每日营养目标</h2>
|
||
<p class="note">人体需要的营养元素很多,我们「抓大放小」:精准追踪三大供能营养素,再盯住青少年最容易缺的几种(钙、铁、维生素 C、膳食纤维、水)。</p>
|
||
<table>
|
||
<thead><tr><th style="width:150px">营养素</th><th class="num" style="width:150px">每日目标</th><th>依据(公式 / 查表)</th><th style="width:110px">状态</th></tr></thead>
|
||
<tbody id="p2Body"></tbody>
|
||
</table>
|
||
<div class="row-between mt">
|
||
<div class="hint">带底色的数字为自动推荐值;直接修改即变为「手动」,可随时点「用推荐值」恢复。</div>
|
||
<button class="btn ghost" data-reset-all>全部采用推荐值</button>
|
||
</div>
|
||
<div class="legend-line"><span>三大营养素供能占比:</span><span id="ratioOut">—</span></div>
|
||
<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>
|
||
<p class="hint">建议参考区间:碳水占总热量 50%–65%,脂肪 20%–30%,蛋白质 10%–20%。如果占比明显跳出区间,说明三大营养素的目标需要重新调整。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>2.2 营养素参考值:为什么要按年龄段取值</h2>
|
||
<div class="cols">
|
||
<table>
|
||
<thead><tr><th>营养素</th><th class="num">14–17 岁</th><th class="num">成人 18–49 岁</th></tr></thead>
|
||
<tbody>
|
||
<tr><td>钙</td><td class="num">1000 mg</td><td class="num">800 mg</td></tr>
|
||
<tr><td>铁</td><td class="num">男 16 / 女 18 mg</td><td class="num">男 12 / 女 18 mg</td></tr>
|
||
<tr><td>维生素 C</td><td class="num">100 mg</td><td class="num">100 mg</td></tr>
|
||
<tr><td>膳食纤维</td><td class="num">25–30 g</td><td class="num">25 g</td></tr>
|
||
<tr><td>水(饮水量)</td><td class="num">男 1700 mL / 女 1500 mL</td><td class="num">同左</td></tr>
|
||
</tbody>
|
||
</table>
|
||
<div>
|
||
<p class="note"><b>本文档面向 14–17 岁中学生</b>:青春期生长发育对钙、铁的需求高于成人,直接套用成人标准会偏低,所以营养素目标按年龄段取值。</p>
|
||
<p class="note"><b>食物换算法(估量用):</b><br>
|
||
1 份蔬菜 ≈ 100 g;1 个中等苹果 ≈ 200 g;1 杯牛奶 ≈ 250 mL;1 个鸡蛋 ≈ 50 g;1 碗米饭 ≈ 150 g;1 勺炒菜油 ≈ 10 g。<br>
|
||
1 杯牛奶(250 mL)≈ 260 mg 钙;100 g 北豆腐 ≈ 138 mg 钙;50 g 瘦猪牛羊肉 ≈ 1.5–3 mg 铁;1 个猕猴桃 ≈ 60 mg 维 C。
|
||
</p>
|
||
<p class="note"><b>关于「水」:</b>表中的目标是<b>饮水量</b>(主动喝进去的水),不含食物和饮料中的水,所以记录时只填喝了多少水。</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ================= 第三部分 ================= -->
|
||
<section class="panel" id="tab-p3">
|
||
<div class="card">
|
||
<h2>3.1 真实饮食记录(连续 3 天)</h2>
|
||
<p class="note">任务:连续记录 3 天真实饮食(建议含 1 天周末),随吃随记、不事后补记。当天结束后合计一次三大营养素。</p>
|
||
<div class="day-tabs" id="dayTabs">
|
||
<button class="dtab active" data-day="0">第 1 天</button>
|
||
<button class="dtab" data-day="1">第 2 天</button>
|
||
<button class="dtab" data-day="2">第 3 天</button>
|
||
</div>
|
||
<div id="dayPanels"></div>
|
||
|
||
<details class="mt">
|
||
<summary style="cursor:pointer;font-size:13px;color:var(--teal-d)">食物库里没有我要的?点这里自己加一条(每 100 g 的营养值)</summary>
|
||
<div class="grid" style="grid-template-columns:repeat(3,1fr);gap:12px;margin-top:12px">
|
||
<div style="grid-column:span 1"><label>食物名称</label><input type="text" id="cName" placeholder="如 妈妈炒的番茄炒蛋"></div>
|
||
<div><label>热量 kcal/100g</label><input type="number" id="cKcal" value="0" min="0" step="0.1"></div>
|
||
<div><label>蛋白质 g/100g</label><input type="number" id="cP" value="0" min="0" step="0.1"></div>
|
||
<div><label>脂肪 g/100g</label><input type="number" id="cF" value="0" min="0" step="0.1"></div>
|
||
<div><label>碳水 g/100g</label><input type="number" id="cC" value="0" min="0" step="0.1"></div>
|
||
<div><label>膳食纤维 g/100g</label><input type="number" id="cFib" value="0" min="0" step="0.1"></div>
|
||
<div style="display:flex;align-items:flex-end"><button class="btn" id="addCustom" style="width:100%">加入食物库</button></div>
|
||
</div>
|
||
<div class="hint">食物成分数据参考《中国食物成分表》与常见包装食品营养标签,为近似值;有营养标签的包装食品请以标签为准(记得换算成 100 g 或 100 mL 再填)。</div>
|
||
</details>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>3.2 核验对照表(自动汇总)</h2>
|
||
<p class="note">把 3 天记录与第二部分的营养目标逐项对照,判定「合格 / 基本合格 / 不合格」,并标出与目标偏差最大的一天。</p>
|
||
<table>
|
||
<thead><tr>
|
||
<th>项目</th><th class="num">我的目标</th><th class="num">第 1 天</th><th class="num">第 2 天</th><th class="num">第 3 天</th>
|
||
<th class="num">3 天平均</th><th class="num">偏差</th><th>判定</th>
|
||
</tr></thead>
|
||
<tbody id="cmpBody"></tbody>
|
||
</table>
|
||
<div class="verdict-box" id="cmpSummary">还没有记录数据 —— 先在 3.1 里添加食物。</div>
|
||
<p class="hint">判定规则:与目标偏差 ≤10% 记「合格」,≤20% 记「基本合格」,超过 20% 记「不合格」;膳食纤维、饮水这类「至少型」目标,达到即为合格。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>3.3 核验结论</h2>
|
||
<div class="q">
|
||
<span class="q-num">1</span>
|
||
<div style="flex:1">
|
||
<b>合格 / 基本合格 / 不合格情况(自动统计)</b>
|
||
<div class="auto-text" id="concl1" style="margin-top:8px">—</div>
|
||
</div>
|
||
</div>
|
||
<div class="q">
|
||
<span class="q-num">2</span>
|
||
<div style="flex:1">
|
||
<b>不达标的主要原因</b><span class="small">(从可行性想:目标定太高?食材难买?时间不够?习惯难改?)</span>
|
||
<div class="chips-row" id="reasonChips">
|
||
<button class="chip-btn" data-ins="目标定得太高,一天很难吃到">目标定得太高</button>
|
||
<button class="chip-btn" data-ins="食堂 / 家里买不到这类食材">食材难买</button>
|
||
<button class="chip-btn" data-ins="课业紧张,没时间准备和处理食材">时间不够</button>
|
||
<button class="chip-btn" data-ins="长期形成的饮食习惯很难一下子改掉">习惯难改</button>
|
||
<button class="chip-btn" data-ins="外卖 / 外食的油、盐、糖很难控制">外食难控制</button>
|
||
<button class="chip-btn" data-ins="记不清食物的分量,估算误差较大">分量估不准</button>
|
||
<button class="chip-btn" data-ins="忘记记录,事后补记导致数据不准">忘记记录</button>
|
||
</div>
|
||
<textarea data-k="p33.reason" rows="3" placeholder="例:脂肪超标 14%,主要是炒菜用油和五花肉太多;水只喝到 800 mL,因为上课期间不方便接水。"></textarea>
|
||
</div>
|
||
</div>
|
||
<div class="q">
|
||
<span class="q-num">3</span>
|
||
<div style="flex:1">
|
||
<b>做得好的部分</b><span class="small">(哪些做到了?为什么能做到?)</span>
|
||
<textarea data-k="p33.good" rows="3" placeholder="例:早餐每天都吃到了鸡蛋和牛奶,因为前一晚就把食材放好在冰箱,早上只用 5 分钟。"></textarea>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ================= 第四部分 ================= -->
|
||
<section class="panel" id="tab-p4">
|
||
<div class="card">
|
||
<h2>4.1 迭代记录</h2>
|
||
<p class="note">针对 3.3 的结论调整方案。<b>一次只改 1–2 个问题</b>,改完执行 3 天后再记录结果;如需要多轮迭代,复制本表继续写。</p>
|
||
<div id="iterBox"></div>
|
||
<button class="btn ghost" id="addIter">+ 添加一轮迭代</button>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>4.2 我的最终版健康饮食方案</h2>
|
||
<div class="grid g2">
|
||
<div>
|
||
<label>1. 每日热量目标</label>
|
||
<div><span class="auto-val big-num" id="finalKcal">—</span> kcal <span class="small" id="finalKcalSrc"></span></div>
|
||
</div>
|
||
<div>
|
||
<label>三餐分配(百分比,合计应为 100%)</label>
|
||
<div class="pct-row">
|
||
早 <input type="number" class="tiny" data-k="p42.bp" min="0" max="100" step="1"> %
|
||
午 <input type="number" class="tiny" data-k="p42.lp" min="0" max="100" step="1"> %
|
||
晚 <input type="number" class="tiny" data-k="p42.dp" min="0" max="100" step="1"> %
|
||
</div>
|
||
<div class="hint" id="pctHint"></div>
|
||
</div>
|
||
</div>
|
||
<div class="mt">
|
||
<label>2. 每日必做的 3 件事</label>
|
||
<input type="text" data-k="p42.must0" placeholder="① 例:早餐一定有 1 个鸡蛋 + 250 mL 牛奶" style="margin-bottom:8px">
|
||
<input type="text" data-k="p42.must1" placeholder="② 例:午餐和晚餐各吃 1 拳头的蔬菜" style="margin-bottom:8px">
|
||
<input type="text" data-k="p42.must2" placeholder="③ 例:全天喝水不低于 1500 mL,含糖饮料换成水">
|
||
</div>
|
||
<div class="mt">
|
||
<label>3. 需要避免的饮食习惯</label>
|
||
<textarea data-k="p42.avoid" rows="2" placeholder="例:晚餐后吃薯片;把奶茶当水喝;炒菜油放太多。"></textarea>
|
||
</div>
|
||
<div class="mt">
|
||
<label>4. 「理想」与「现实」的取舍(哪些坚持、哪些妥协,为什么)</label>
|
||
<textarea data-k="p42.tradeoff" rows="3" placeholder="例:坚持早餐和饮水两条;食堂菜偏油,改为过一遍热水再吃,先不要求完全水煮 —— 可行性优先,能长期做到比一时达标更重要。"></textarea>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ================= 第五部分 ================= -->
|
||
<section class="panel" id="tab-p5">
|
||
<div class="card">
|
||
<h2>5.1 学生自评</h2>
|
||
<table class="review-table">
|
||
<thead><tr><th>评价内容</th><th>完全做到</th><th>基本做到</th><th>未做到</th></tr></thead>
|
||
<tbody>
|
||
<tr><td>我会计算个人的热量需求(BMR、TDEE)</td>
|
||
<td><input type="radio" name="p5.s1" data-k="p5.s1" value="完全做到"></td>
|
||
<td><input type="radio" name="p5.s1" data-k="p5.s1" value="基本做到"></td>
|
||
<td><input type="radio" name="p5.s1" data-k="p5.s1" value="未做到"></td></tr>
|
||
<tr><td>我设计出了合理的营养素目标</td>
|
||
<td><input type="radio" name="p5.s2" data-k="p5.s2" value="完全做到"></td>
|
||
<td><input type="radio" name="p5.s2" data-k="p5.s2" value="基本做到"></td>
|
||
<td><input type="radio" name="p5.s2" data-k="p5.s2" value="未做到"></td></tr>
|
||
<tr><td>我坚持完成了 3 天真实记录</td>
|
||
<td><input type="radio" name="p5.s3" data-k="p5.s3" value="完全做到"></td>
|
||
<td><input type="radio" name="p5.s3" data-k="p5.s3" value="基本做到"></td>
|
||
<td><input type="radio" name="p5.s3" data-k="p5.s3" value="未做到"></td></tr>
|
||
<tr><td>我能分析方案与现实差距的原因</td>
|
||
<td><input type="radio" name="p5.s4" data-k="p5.s4" value="完全做到"></td>
|
||
<td><input type="radio" name="p5.s4" data-k="p5.s4" value="基本做到"></td>
|
||
<td><input type="radio" name="p5.s4" data-k="p5.s4" value="未做到"></td></tr>
|
||
<tr><td>我迭代了方案,并做了再验证</td>
|
||
<td><input type="radio" name="p5.s5" data-k="p5.s5" value="完全做到"></td>
|
||
<td><input type="radio" name="p5.s5" data-k="p5.s5" value="基本做到"></td>
|
||
<td><input type="radio" name="p5.s5" data-k="p5.s5" value="未做到"></td></tr>
|
||
</tbody>
|
||
</table>
|
||
<div class="mt">
|
||
<label>我最大的收获</label>
|
||
<textarea data-k="p5.gain" rows="3" placeholder="例:原来以为「吃够热量」很难,实际加一杯牛奶 + 一小把坚果就够了;反倒是「少油」最难。"></textarea>
|
||
</div>
|
||
<div class="summary-card">
|
||
<h3>自动汇总(来自 3.2 核验结果)</h3>
|
||
<div id="p5Summary">—</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>5.2 同伴互评</h2>
|
||
<p class="note">说明:项目完成后,与同伴(同班 / 小组内成员)交换项目书,通读对方全部内容后如实填写。评价别人的过程也是学习的过程。</p>
|
||
<div class="grid g3">
|
||
<div><label>评价人</label><input type="text" data-k="peer.who" placeholder="姓名"></div>
|
||
<div><label>与被评价人的关系</label>
|
||
<select data-k="peer.rel">
|
||
<option value="">请选择</option><option>同班</option><option>同组</option><option>其他</option>
|
||
</select></div>
|
||
<div><label>评价日期</label><input type="date" data-k="peer.date"></div>
|
||
</div>
|
||
<table class="review-table mt">
|
||
<thead><tr><th>评价内容</th><th>优秀</th><th>良好</th><th>合格</th><th>待改进</th></tr></thead>
|
||
<tbody>
|
||
<tr><td>热量计算过程完整、有依据(公式与代入数据都对)</td>
|
||
<td><input type="radio" name="peer.i1" data-k="peer.i1" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i1" data-k="peer.i1" value="良好"></td>
|
||
<td><input type="radio" name="peer.i1" data-k="peer.i1" value="合格"></td>
|
||
<td><input type="radio" name="peer.i1" data-k="peer.i1" value="待改进"></td></tr>
|
||
<tr><td>营养素目标设置合理(有换算依据,符合年龄段标准)</td>
|
||
<td><input type="radio" name="peer.i2" data-k="peer.i2" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i2" data-k="peer.i2" value="良好"></td>
|
||
<td><input type="radio" name="peer.i2" data-k="peer.i2" value="合格"></td>
|
||
<td><input type="radio" name="peer.i2" data-k="peer.i2" value="待改进"></td></tr>
|
||
<tr><td>3 天真实饮食记录完整、可信(有日期、有分量)</td>
|
||
<td><input type="radio" name="peer.i3" data-k="peer.i3" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i3" data-k="peer.i3" value="良好"></td>
|
||
<td><input type="radio" name="peer.i3" data-k="peer.i3" value="合格"></td>
|
||
<td><input type="radio" name="peer.i3" data-k="peer.i3" value="待改进"></td></tr>
|
||
<tr><td>核验结论的原因分析具体、符合实际</td>
|
||
<td><input type="radio" name="peer.i4" data-k="peer.i4" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i4" data-k="peer.i4" value="良好"></td>
|
||
<td><input type="radio" name="peer.i4" data-k="peer.i4" value="合格"></td>
|
||
<td><input type="radio" name="peer.i4" data-k="peer.i4" value="待改进"></td></tr>
|
||
<tr><td>迭代调整有针对性,且做了再验证</td>
|
||
<td><input type="radio" name="peer.i5" data-k="peer.i5" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i5" data-k="peer.i5" value="良好"></td>
|
||
<td><input type="radio" name="peer.i5" data-k="peer.i5" value="合格"></td>
|
||
<td><input type="radio" name="peer.i5" data-k="peer.i5" value="待改进"></td></tr>
|
||
<tr><td>项目书整体填写完整、工整</td>
|
||
<td><input type="radio" name="peer.i6" data-k="peer.i6" value="优秀"></td>
|
||
<td><input type="radio" name="peer.i6" data-k="peer.i6" value="良好"></td>
|
||
<td><input type="radio" name="peer.i6" data-k="peer.i6" value="合格"></td>
|
||
<td><input type="radio" name="peer.i6" data-k="peer.i6" value="待改进"></td></tr>
|
||
</tbody>
|
||
</table>
|
||
<div class="mt">
|
||
<label>给同伴最有价值的一点</label>
|
||
<textarea data-k="peer.best" rows="2" placeholder="例:把「一天吃够 100 g 蛋白质」拆成早鸡蛋 + 午鸡胸 + 晚牛肉,比空喊目标有用得多。"></textarea>
|
||
</div>
|
||
<div class="mt">
|
||
<label>我的建议(至少一处,写具体)</label>
|
||
<textarea data-k="peer.advice" rows="2" placeholder="例:3.1 里第 2 天晚餐没有写分量,建议补上「米饭 200 g」这样的数字,否则 3 天平均没法对照。"></textarea>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
|
||
<datalist id="foodList"></datalist>
|
||
<div class="toast" id="toast"></div>
|
||
|
||
<dialog id="dlg">
|
||
<div class="dlg-head">
|
||
<b id="dlgTitle">文本内容</b>
|
||
<button class="btn ghost" id="dlgClose">关闭</button>
|
||
</div>
|
||
<div class="dlg-body">
|
||
<p class="hint" id="dlgHint">如果浏览器拦截了下载,可以在这里全选复制,粘贴到记事本保存。</p>
|
||
<textarea id="dlgText" readonly></textarea>
|
||
</div>
|
||
</dialog>
|
||
|
||
<script>
|
||
/* ==================== 一、食物成分表 ==================== */
|
||
/* 每 100 g 可食部:[热量 kcal, 蛋白质 g, 脂肪 g, 碳水 g, 膳食纤维 g] */
|
||
const FOODS = {
|
||
/* 谷薯主食 */
|
||
'米饭(蒸,熟)':[116,2.6,0.3,25.9,0.3],
|
||
'白粥':[46,1.1,0.3,9.9,0.1],
|
||
'小米粥':[46,1.4,0.7,8.4,0.5],
|
||
'馒头':[223,7.0,1.1,47.0,1.3],
|
||
'面条(煮熟)':[110,2.7,0.2,24.3,0.4],
|
||
'全麦面包':[246,8.8,3.3,45.0,6.0],
|
||
'白吐司面包':[313,8.3,5.1,58.6,2.7],
|
||
'燕麦片(干)':[377,15.0,6.7,61.0,10.6],
|
||
'玉米(鲜,煮)':[112,4.0,1.2,22.8,2.9],
|
||
'红薯(蒸)':[90,1.6,0.2,20.7,1.6],
|
||
'土豆(蒸)':[81,2.0,0.2,17.8,1.2],
|
||
'山药':[57,1.9,0.2,12.4,0.8],
|
||
'方便面(油炸)':[473,9.5,21.1,61.6,0.9],
|
||
/* 肉蛋奶豆 */
|
||
'鸡胸肉':[133,19.4,5.0,2.5,0],
|
||
'鸡腿肉':[181,16.0,13.0,0,0],
|
||
'猪瘦肉':[143,20.3,6.2,1.5,0],
|
||
'猪五花肉':[508,7.7,53.0,2.4,0],
|
||
'牛肉(瘦)':[106,20.2,2.3,1.2,0],
|
||
'羊肉(瘦)':[118,20.5,3.9,0.2,0],
|
||
'鸡蛋':[144,13.3,8.8,2.8,0],
|
||
'草鱼':[113,16.6,5.2,0,0],
|
||
'三文鱼':[139,17.2,7.8,0,0],
|
||
'鲈鱼':[105,18.6,3.4,0,0],
|
||
'对虾':[93,18.6,0.8,2.8,0],
|
||
'火腿肠':[212,14.0,10.4,15.6,0],
|
||
'牛奶(全脂)':[65,3.3,3.6,4.9,0],
|
||
'酸奶(全脂)':[72,2.5,2.7,9.3,0],
|
||
'豆浆(无糖)':[31,3.0,1.6,1.2,1.1],
|
||
'北豆腐':[116,12.2,4.8,4.2,0.5],
|
||
'南豆腐':[87,6.2,2.5,4.8,0.4],
|
||
'豆腐干':[140,16.2,3.6,11.5,0.8],
|
||
'奶酪':[328,25.7,23.5,3.5,0],
|
||
/* 蔬菜 */
|
||
'西兰花':[36,4.1,0.6,4.3,1.6],
|
||
'菠菜':[28,2.6,0.3,4.5,1.7],
|
||
'生菜':[15,1.3,0.3,2.0,0.7],
|
||
'大白菜':[20,1.5,0.1,3.2,0.8],
|
||
'番茄':[20,0.9,0.2,4.0,0.5],
|
||
'黄瓜':[16,0.8,0.2,2.9,0.5],
|
||
'胡萝卜':[39,1.0,0.2,8.8,1.1],
|
||
'茄子':[23,1.1,0.2,4.9,1.3],
|
||
'青椒':[22,1.4,0.3,5.4,1.4],
|
||
'香菇(鲜)':[26,2.2,0.3,5.2,3.3],
|
||
'木耳(干)':[265,12.1,1.5,65.6,29.9],
|
||
/* 水果 */
|
||
'苹果':[53,0.2,0.2,13.5,2.4],
|
||
'香蕉':[93,1.4,0.2,22.0,1.2],
|
||
'橙子':[48,0.8,0.2,11.1,0.6],
|
||
'葡萄':[45,0.5,0.2,10.3,0.4],
|
||
'西瓜':[31,0.5,0.3,7.0,0.2],
|
||
'桃':[51,0.4,0.2,13.3,3.1],
|
||
'猕猴桃':[61,0.8,0.6,14.5,2.6],
|
||
'草莓':[32,1.0,0.2,7.1,1.1],
|
||
'梨':[51,0.4,0.2,13.3,3.1],
|
||
/* 坚果、油脂、零食饮料 */
|
||
'花生(炒)':[601,21.7,48.0,23.8,6.3],
|
||
'核桃':[646,14.9,58.8,19.1,9.5],
|
||
'巴旦木(杏仁)':[578,22.5,45.4,27.5,8.0],
|
||
'葵花子(炒)':[616,22.6,52.8,12.5,4.8],
|
||
'植物油(大豆油)':[899,0,99.9,0,0],
|
||
'黄油':[888,1.4,98.0,0,0],
|
||
'可乐':[43,0,0,10.8,0],
|
||
'珍珠奶茶':[90,1.0,2.5,15.0,0],
|
||
'薯片':[548,6.4,35.2,51.9,4.4],
|
||
'巧克力':[586,4.3,40.1,53.4,1.5],
|
||
'蛋糕(奶油)':[378,5.5,16.0,54.0,0.6],
|
||
'辣条':[470,12.0,25.0,48.0,2.0]
|
||
};
|
||
|
||
/* ==================== 二、常量 ==================== */
|
||
const ACTIVITY = {
|
||
sedentary:{name:'久坐', desc:'几乎不运动', f:1.2},
|
||
light:{name:'轻度', desc:'每周训练 1–3 次', f:1.375},
|
||
moderate:{name:'中度', desc:'每周训练 3–5 次', f:1.55},
|
||
active:{name:'高强度', desc:'每周训练 6–7 次', f:1.725}
|
||
};
|
||
const NUTRIENTS = [
|
||
{key:'carb', label:'碳水化合物', unit:'g'},
|
||
{key:'protein', label:'蛋白质', unit:'g'},
|
||
{key:'fat', label:'脂肪', unit:'g'},
|
||
{key:'water', label:'水(饮水量)', unit:'mL'},
|
||
{key:'fiber', label:'膳食纤维', unit:'g'},
|
||
{key:'ca', label:'钙', unit:'mg'},
|
||
{key:'fe', label:'铁', unit:'mg'},
|
||
{key:'vc', label:'维生素 C', unit:'mg'}
|
||
];
|
||
const QUAL = ['充足','基本充足','不足'];
|
||
const LS = 'healthy-diet-projectbook.v1';
|
||
|
||
/* ==================== 三、状态 ==================== */
|
||
function defState(){
|
||
return {
|
||
meta:{sid:'',name:'',cls:''},
|
||
p1:{age:17,sex:'male',height:175,weight:62,activity:'moderate',goal:'maintain',adjust:0,kcalOverride:'',calcNote:'',reason:''},
|
||
p2:{auto:{carb:true,protein:true,fat:true,water:true,fiber:true,ca:true,fe:true,vc:true},
|
||
val:{carb:0,protein:0,fat:0,water:0,fiber:0,ca:0,fe:0,vc:0}},
|
||
days:[mkDay(),mkDay(),mkDay()],
|
||
p33:{reason:'',good:''},
|
||
p4:{rows:[{q:'',before:'',after:'',why:'',res:''}]},
|
||
p42:{bp:30,lp:40,dp:30,must0:'',must1:'',must2:'',avoid:'',tradeoff:''},
|
||
p5:{s1:'',s2:'',s3:'',s4:'',s5:'',gain:''},
|
||
peer:{who:'',rel:'',date:'',i1:'',i2:'',i3:'',i4:'',i5:'',i6:'',best:'',advice:''}
|
||
};
|
||
}
|
||
function mkDay(){ return {date:'',weekend:'',water:'',ca:'',fe:'',vc:'',note:'',meals:[]}; }
|
||
let S = defState();
|
||
|
||
/* ==================== 四、工具函数 ==================== */
|
||
const $ = s => document.querySelector(s);
|
||
const $$ = s => Array.from(document.querySelectorAll(s));
|
||
function num(v,d){ const n = typeof v==='number' ? v : parseFloat(v); return isNaN(n) ? (d===undefined?0:d) : n; }
|
||
function fmt(n,d){ return num(n,0).toFixed(d===undefined?0:d); }
|
||
function esc(s){ return String(s==null?'':s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
|
||
function getPath(o,p){ return p.split('.').reduce((a,k)=> (a==null?undefined:a[k]), o); }
|
||
function setPath(o,p,v){
|
||
const ks = p.split('.'), last = ks.pop();
|
||
let cur = o;
|
||
ks.forEach(k=>{ if(cur[k]==null) cur[k] = {}; cur = cur[k]; });
|
||
cur[last] = v;
|
||
}
|
||
let toastTimer = null;
|
||
function toast(msg){
|
||
const t = $('#toast'); t.textContent = msg; t.classList.add('show');
|
||
clearTimeout(toastTimer); toastTimer = setTimeout(()=>t.classList.remove('show'), 1800);
|
||
}
|
||
|
||
/* ==================== 五、计算 ==================== */
|
||
function p1calc(){
|
||
const age = num(S.p1.age,17), h = num(S.p1.height,0), w = num(S.p1.weight,0);
|
||
const sex = S.p1.sex === 'female' ? 'female' : 'male';
|
||
const bmi = h > 0 ? w / Math.pow(h/100, 2) : 0;
|
||
const bmr = sex === 'male'
|
||
? 10*w + 6.25*h - 5*age + 5
|
||
: 10*w + 6.25*h - 5*age - 161;
|
||
const act = ACTIVITY[S.p1.activity] || ACTIVITY.moderate;
|
||
const tdee = bmr * act.f;
|
||
const goal = S.p1.goal || 'maintain';
|
||
const sign = goal === 'cut' ? -1 : (goal === 'bulk' ? 1 : 0);
|
||
const adj = num(S.p1.adjust,0) * sign;
|
||
const autoTarget = tdee + adj;
|
||
const manual = !(S.p1.kcalOverride === '' || S.p1.kcalOverride == null);
|
||
const target = manual ? num(S.p1.kcalOverride, autoTarget) : autoTarget;
|
||
return {age,sex,h,w,bmi,bmr,tdee,act,goal,sign,adj,autoTarget,manual,target};
|
||
}
|
||
function recTargets(){
|
||
const p1 = p1calc();
|
||
return {
|
||
carb: p1.target * 0.55 / 4,
|
||
protein: num(S.p1.weight,0) * 1.6,
|
||
fat: p1.target * 0.25 / 9,
|
||
water: p1.sex === 'female' ? 1500 : 1700,
|
||
fiber: 25,
|
||
ca: 1000,
|
||
fe: p1.sex === 'female' ? 18 : 16,
|
||
vc: 100
|
||
};
|
||
}
|
||
function ensureP2(){
|
||
const rec = recTargets();
|
||
Object.keys(rec).forEach(k=>{ if(S.p2.auto[k]) S.p2.val[k] = Math.round(rec[k]); });
|
||
}
|
||
function basisText(key, p1, rec){
|
||
switch(key){
|
||
case 'carb': return '占总热量 50%–65%,取中值 55%;1 g 碳水 = 4 kcal<br>= ' + fmt(p1.target,0) + ' × 55% ÷ 4 = <b>' + fmt(rec.carb,0) + ' g</b>';
|
||
case 'protein': return '青少年 1.2–2.0 g/kg,取 1.6 g/kg<br>= ' + fmt(num(S.p1.weight,0),0) + ' kg × 1.6 = <b>' + fmt(rec.protein,0) + ' g</b>';
|
||
case 'fat': return '占总热量 20%–30%,取中值 25%;1 g 脂肪 = 9 kcal<br>= ' + fmt(p1.target,0) + ' × 25% ÷ 9 = <b>' + fmt(rec.fat,0) + ' g</b>';
|
||
case 'water': return '《中国居民膳食指南》14–17 岁饮水量:男 1700 mL / 女 1500 mL<br>注意:<b>只指喝水</b>,不含食物与饮料中的水';
|
||
case 'fiber': return '14–17 岁推荐 25–30 g,取 25 g<br>来源:全谷物、蔬菜、水果、豆类';
|
||
case 'ca': return '14–17 岁推荐 1000 mg(成人 800 mg)<br>参考:1 杯牛奶(250 mL)≈ 260 mg 钙';
|
||
case 'fe': return '14–17 岁:男 16 mg / 女 18 mg(青春期女生需求更高)';
|
||
case 'vc': return '14–17 岁推荐 100 mg<br>参考:1 个猕猴桃 ≈ 60 mg,1 个橙子 ≈ 50 mg';
|
||
}
|
||
return '';
|
||
}
|
||
function dayTotals(i){
|
||
const t = {kcal:0,p:0,f:0,c:0,fib:0};
|
||
(S.days[i].meals||[]).forEach(m=>{
|
||
const per = FOODS[m.name]; if(!per) return;
|
||
const k = num(m.grams,0)/100;
|
||
t.kcal += per[0]*k; t.p += per[1]*k; t.f += per[2]*k; t.c += per[3]*k; t.fib += per[4]*k;
|
||
});
|
||
return t;
|
||
}
|
||
function findFood(raw){
|
||
const s = String(raw||'').trim();
|
||
if(!s) return null;
|
||
if(FOODS[s]) return s;
|
||
const keys = Object.keys(FOODS);
|
||
const base = s.replace(/[((][^))]*[))]/g,'').trim();
|
||
let hit = keys.find(k => k.replace(/[((][^))]*[))]/g,'').trim() === base);
|
||
if(hit) return hit;
|
||
if(base.length >= 2){
|
||
hit = keys.find(k => k.indexOf(base) !== -1);
|
||
if(hit) return hit;
|
||
hit = keys.find(k => base.indexOf(k.replace(/[((][^))]*[))]/g,'').trim()) !== -1);
|
||
if(hit) return hit;
|
||
}
|
||
return null;
|
||
}
|
||
function judge(target, avg, isMin){
|
||
if(target == null || avg == null || !target) return {t:'—', c:'na'};
|
||
if(isMin){
|
||
if(avg >= target) return {t:'合格', c:'ok'};
|
||
if(avg >= target*0.8) return {t:'基本合格', c:'mid'};
|
||
return {t:'不合格', c:'bad'};
|
||
}
|
||
const dev = Math.abs(avg - target) / target;
|
||
if(dev <= 0.10) return {t:'合格', c:'ok'};
|
||
if(dev <= 0.20) return {t:'基本合格', c:'mid'};
|
||
return {t:'不合格', c:'bad'};
|
||
}
|
||
|
||
/* ==================== 六、绑定 ==================== */
|
||
function collectBindings(){
|
||
$$('[data-k]').forEach(el=>{
|
||
const k = el.dataset.k;
|
||
if(el.type === 'radio'){
|
||
const v = getPath(S,k);
|
||
const want = (v == null) ? false : (String(v) === el.value);
|
||
if(el.checked !== want) el.checked = want;
|
||
return;
|
||
}
|
||
if(el.type === 'checkbox'){
|
||
const want = !!getPath(S,k);
|
||
if(el.checked !== want) el.checked = want;
|
||
return;
|
||
}
|
||
const v = getPath(S,k);
|
||
const str = (v == null) ? '' : String(v);
|
||
if(el.value !== str) el.value = str;
|
||
});
|
||
}
|
||
function onField(e){
|
||
const el = e.target.closest('[data-k],[data-i]');
|
||
if(!el) return;
|
||
let val;
|
||
if(el.type === 'radio') val = el.value;
|
||
else if(el.type === 'checkbox') val = el.checked;
|
||
else if(el.type === 'number') val = (el.value === '') ? '' : num(el.value,0);
|
||
else val = el.value;
|
||
|
||
if(el.dataset.i !== undefined){
|
||
const i = +el.dataset.i, f = el.dataset.f;
|
||
if(S.p4.rows[i]) S.p4.rows[i][f] = val;
|
||
} else {
|
||
const k = el.dataset.k;
|
||
setPath(S, k, val);
|
||
if(k.indexOf('p2.val.') === 0) S.p2.auto[k.split('.')[2]] = false;
|
||
if(k === 'p1.goal') onGoalChange();
|
||
}
|
||
render(); save();
|
||
}
|
||
function onGoalChange(){
|
||
const g = S.p1.goal;
|
||
if(g === 'maintain') S.p1.adjust = 0;
|
||
else if(!S.p1.adjust) S.p1.adjust = 400;
|
||
buildAdjustOptions();
|
||
}
|
||
|
||
/* ==================== 七、渲染 ==================== */
|
||
function render(){
|
||
ensureP2();
|
||
collectBindings();
|
||
updateActivityTable();
|
||
updateP1Out();
|
||
updateP2Status();
|
||
updateDays();
|
||
updateCompare();
|
||
updateFinal();
|
||
updateOverview();
|
||
updateP5Summary();
|
||
updatePrintMeta();
|
||
}
|
||
|
||
function updateActivityTable(){
|
||
$('#actBody').innerHTML = Object.keys(ACTIVITY).map(k=>{
|
||
const a = ACTIVITY[k];
|
||
return '<tr class="' + (k === S.p1.activity ? 'hl' : '') + '"><td>' + a.name + '</td><td class="small">' + a.desc +
|
||
'</td><td class="num">' + a.f + '</td></tr>';
|
||
}).join('');
|
||
}
|
||
|
||
function buildAdjustOptions(){
|
||
const g = S.p1.goal || 'maintain';
|
||
const sel = $('#adjustSel');
|
||
const opts = g === 'maintain' ? [0] : [300,400,500];
|
||
sel.innerHTML = opts.map(v => '<option value="' + v + '">' + v + '</option>').join('');
|
||
if(opts.indexOf(num(S.p1.adjust,0)) === -1) S.p1.adjust = opts[0];
|
||
sel.value = String(S.p1.adjust);
|
||
$('#adjustWrap').style.opacity = (g === 'maintain') ? .5 : 1;
|
||
sel.disabled = (g === 'maintain');
|
||
}
|
||
|
||
function updateP1Out(){
|
||
const p1 = p1calc();
|
||
const sexTxt = p1.sex === 'male' ? '男' : '女';
|
||
const sexSign = p1.sex === 'male' ? '+ 5' : '− 161';
|
||
const goalTxt = {maintain:'维持体重', cut:'减脂', bulk:'增肌 / 增重'}[p1.goal] || '维持体重';
|
||
const adjTxt = p1.sign === 0 ? '(不加不减)' : (p1.sign > 0 ? '+ ' + Math.abs(p1.adj) : '− ' + Math.abs(p1.adj)) + ' kcal';
|
||
$('#calcFormula').innerHTML =
|
||
'<span class="cmt">基础代谢率(BMR,Mifflin-St Jeor 公式,' + sexTxt + ')</span>\n' +
|
||
'BMR = 10 × 体重 + 6.25 × 身高 − 5 × 年龄 ' + sexSign + '\n' +
|
||
' = 10 × ' + fmt(p1.w,0) + ' + 6.25 × ' + fmt(p1.h,0) + ' − 5 × ' + fmt(p1.age,0) + ' ' + sexSign + '\n' +
|
||
' = <b>' + fmt(p1.bmr,1) + ' kcal</b>\n\n' +
|
||
'<span class="cmt">每日总消耗(TDEE)= BMR × 活动系数(' + p1.act.name + ' ' + p1.act.f + ')</span>\n' +
|
||
' = ' + fmt(p1.bmr,1) + ' × ' + p1.act.f + ' ≈ <b>' + fmt(p1.tdee,0) + ' kcal</b>\n\n' +
|
||
'<span class="cmt">每日热量摄入目标:' + goalTxt + ' ' + adjTxt + '</span>\n' +
|
||
' = ' + fmt(p1.tdee,0) + ' ' + (p1.sign < 0 ? '−' : (p1.sign > 0 ? '+' : '±')) + ' ' + Math.abs(p1.adj) + ' = <b>' + fmt(p1.autoTarget,0) + ' kcal</b>' +
|
||
(p1.manual ? '\n<span class="cmt">(你已手动设定为 ' + fmt(p1.target,0) + ' kcal)</span>' : '');
|
||
|
||
$('#tddeOut').textContent = fmt(p1.tdee,0);
|
||
$('#kcalOut').textContent = fmt(p1.target,0);
|
||
const ko = $('#kcalOverride');
|
||
ko.disabled = !p1.manual;
|
||
$('#chkManual').checked = p1.manual;
|
||
const cat = p1.bmi < 18.5 ? '偏瘦' : (p1.bmi < 24 ? '正常' : (p1.bmi < 28 ? '超重' : '肥胖'));
|
||
$('#bmiHint').innerHTML = p1.bmi > 0 ? '你的 BMI = <b>' + fmt(p1.bmi,1) + '</b>,属于「' + cat + '」。' : '';
|
||
}
|
||
|
||
function renderP2Body(){
|
||
const p1 = p1calc(), rec = recTargets();
|
||
$('#p2Body').innerHTML = NUTRIENTS.map(n =>
|
||
'<tr>' +
|
||
'<td><b>' + n.label + '</b></td>' +
|
||
'<td class="num"><input class="num-in" type="number" min="0" step="1" data-k="p2.val.' + n.key + '">' +
|
||
' <span class="unit-in">' + n.unit + '</span></td>' +
|
||
'<td class="small" data-p2basis="' + n.key + '">' + basisText(n.key, p1, rec) + '</td>' +
|
||
'<td class="nowrap"><span class="tag auto" data-p2tag="' + n.key + '">自动</span><br>' +
|
||
'<button class="btn-link" data-reset="' + n.key + '">用推荐值</button></td>' +
|
||
'</tr>').join('');
|
||
}
|
||
|
||
function updateP2Status(){
|
||
const p1 = p1calc(), rec = recTargets();
|
||
NUTRIENTS.forEach(n=>{
|
||
const tag = document.querySelector('[data-p2tag="' + n.key + '"]');
|
||
if(tag){
|
||
const a = !!S.p2.auto[n.key];
|
||
tag.textContent = a ? '自动' : '手动';
|
||
tag.className = 'tag ' + (a ? 'auto' : 'manual');
|
||
}
|
||
const b = document.querySelector('[data-p2basis="' + n.key + '"]');
|
||
if(b) b.innerHTML = basisText(n.key, p1, rec);
|
||
});
|
||
const v = S.p2.val;
|
||
const ep = num(v.protein)*4, ef = num(v.fat)*9, ec = num(v.carb)*4;
|
||
const tot = ep + ef + ec;
|
||
if(tot > 0){
|
||
$('#barP').style.width = (ep/tot*100) + '%';
|
||
$('#barF').style.width = (ef/tot*100) + '%';
|
||
$('#barC').style.width = (ec/tot*100) + '%';
|
||
$('#ratioOut').innerHTML = '蛋白质 ' + fmt(ep/tot*100,0) + '%|脂肪 ' + fmt(ef/tot*100,0) +
|
||
'%|碳水 ' + fmt(ec/tot*100,0) + '%(合计 ' + fmt(tot,0) + ' kcal,占目标热量 ' +
|
||
fmt(tot/Math.max(1,p1.target)*100,0) + '%)';
|
||
} else {
|
||
$('#ratioOut').textContent = '—';
|
||
$('#barP').style.width = $('#barF').style.width = $('#barC').style.width = '0%';
|
||
}
|
||
}
|
||
|
||
/* ---------- 3.1 每日记录 ---------- */
|
||
function buildDayPanels(){
|
||
$('#dayPanels').innerHTML = S.days.map((d,i)=>
|
||
'<div class="day-panel' + (i === 0 ? ' active' : '') + '" data-day="' + i + '">' +
|
||
'<div class="day-head">' +
|
||
'<div><label>日期</label><input type="date" data-k="days.' + i + '.date"></div>' +
|
||
'<div><label>工作日 / 周末</label><select data-k="days.' + i + '.weekend"><option value="">—</option><option>工作日</option><option>周末</option></select></div>' +
|
||
'<div><label>饮水量(mL,只算喝水)</label><input type="number" min="0" step="50" placeholder="如 1200" data-k="days.' + i + '.water"></div>' +
|
||
'</div>' +
|
||
'<div class="food-add">' +
|
||
'<select id="meal-sel-' + i + '"><option>早餐</option><option>午餐</option><option>晚餐</option><option>加餐</option></select>' +
|
||
'<input type="text" id="food-in-' + i + '" list="foodList" placeholder="食物名称,如:米饭(蒸,熟)">' +
|
||
'<input type="number" id="food-g-' + i + '" value="100" min="1" step="1">' +
|
||
'<button class="btn" data-add="' + i + '">添加</button>' +
|
||
'</div>' +
|
||
'<div class="hint">参考分量:1 碗米饭 ≈ 150 g|1 个鸡蛋 ≈ 50 g|1 个中等苹果 ≈ 200 g|1 杯牛奶 ≈ 250 mL|1 勺炒菜油 ≈ 10 g。按「熟了之后的重量」填。</div>' +
|
||
'<div class="msg" id="food-msg-' + i + '"></div>' +
|
||
'<div id="day-table-' + i + '"></div>' +
|
||
'<div class="qual-row">' +
|
||
'<span class="q-label">定性记录(钙 / 铁 / 维 C 不便逐项计算,可按当天饮食判断,可留空):</span>' +
|
||
'<label>钙 <select data-k="days.' + i + '.ca"><option value="">—</option>' + QUAL.map(q=>'<option>'+q+'</option>').join('') + '</select></label>' +
|
||
'<label>铁 <select data-k="days.' + i + '.fe"><option value="">—</option>' + QUAL.map(q=>'<option>'+q+'</option>').join('') + '</select></label>' +
|
||
'<label>维 C <select data-k="days.' + i + '.vc"><option value="">—</option>' + QUAL.map(q=>'<option>'+q+'</option>').join('') + '</select></label>' +
|
||
'</div>' +
|
||
'<div style="margin-top:12px"><label>这一天的特别说明(外食、聚餐、体育课、忘记录…)</label>' +
|
||
'<input type="text" data-k="days.' + i + '.note"></div>' +
|
||
'<div class="row-between" style="margin-top:12px"><span class="hint">数据自动保存在本机浏览器里,刷新不丢。</span>' +
|
||
'<button class="btn ghost" data-clear="' + i + '">清空第 ' + (i+1) + ' 天</button></div>' +
|
||
'<div class="hint">依据:食物成分表为近似值,包装食品请以营养标签为准。</div>' +
|
||
'</div>').join('');
|
||
|
||
$('#foodList').innerHTML = Object.keys(FOODS).map(k => '<option value="' + esc(k) + '"></option>').join('');
|
||
collectBindings();
|
||
}
|
||
|
||
function setMsg(el, text, ok){ el.textContent = text; el.className = 'msg ' + (ok ? 'ok' : 'err'); }
|
||
|
||
function renderDayTable(i){
|
||
const box = document.getElementById('day-table-' + i);
|
||
if(!box) return;
|
||
const meals = S.days[i].meals || [];
|
||
const t = dayTotals(i);
|
||
let rows = '';
|
||
if(!meals.length){
|
||
rows = '<tr><td colspan="9" class="empty">还没有记录 —— 在上面输入食物名称和分量,点「添加」。</td></tr>';
|
||
} else {
|
||
rows = meals.map((m,idx)=>{
|
||
const per = FOODS[m.name] || [0,0,0,0,0];
|
||
const k = num(m.grams,0)/100;
|
||
return '<tr><td>' + esc(m.meal) + '</td><td>' + esc(m.name) + '</td>' +
|
||
'<td class="num">' + fmt(m.grams,0) + '</td>' +
|
||
'<td class="num">' + fmt(per[0]*k,0) + '</td>' +
|
||
'<td class="num">' + fmt(per[1]*k,1) + '</td>' +
|
||
'<td class="num">' + fmt(per[2]*k,1) + '</td>' +
|
||
'<td class="num">' + fmt(per[3]*k,1) + '</td>' +
|
||
'<td class="num">' + fmt(per[4]*k,1) + '</td>' +
|
||
'<td><button class="link-del" data-del="' + i + '-' + idx + '">删除</button></td></tr>';
|
||
}).join('');
|
||
}
|
||
const foot = meals.length
|
||
? '<tfoot><tr><td colspan="3">当日合计</td>' +
|
||
'<td class="num">' + fmt(t.kcal,0) + ' kcal</td>' +
|
||
'<td class="num">' + fmt(t.p,1) + ' g</td>' +
|
||
'<td class="num">' + fmt(t.f,1) + ' g</td>' +
|
||
'<td class="num">' + fmt(t.c,1) + ' g</td>' +
|
||
'<td class="num">' + fmt(t.fib,1) + ' g</td><td></td></tr></tfoot>'
|
||
: '';
|
||
let extra = '';
|
||
const p1 = p1calc();
|
||
if(meals.length && p1.target > 0){
|
||
const pct = t.kcal / p1.target * 100;
|
||
extra = '<div class="progress"><i class="' + (pct > 110 ? 'over' : '') + '" style="width:' + Math.min(100,pct) + '%"></i></div>' +
|
||
'<div class="prog-label"><span>已摄入 <b>' + fmt(t.kcal,0) + '</b> kcal / 目标 ' + fmt(p1.target,0) + ' kcal</span>' +
|
||
'<span>' + (t.kcal >= p1.target ? '超出 ' : '还差 ') + '<b>' + fmt(Math.abs(p1.target - t.kcal),0) +
|
||
'</b> kcal(' + fmt(pct,0) + '%)</span></div>';
|
||
}
|
||
box.innerHTML = '<table><thead><tr>' +
|
||
'<th>餐次</th><th>食物</th><th class="num">分量(g)</th><th class="num">热量</th><th class="num">蛋白</th>' +
|
||
'<th class="num">脂肪</th><th class="num">碳水</th><th class="num">纤维</th><th></th></tr></thead>' +
|
||
'<tbody>' + rows + '</tbody>' + foot + '</table>' + extra;
|
||
}
|
||
|
||
function updateDays(){ [0,1,2].forEach(renderDayTable); }
|
||
|
||
function addFood(i){
|
||
const nameEl = document.getElementById('food-in-' + i);
|
||
const gEl = document.getElementById('food-g-' + i);
|
||
const mealEl = document.getElementById('meal-sel-' + i);
|
||
const msgEl = document.getElementById('food-msg-' + i);
|
||
const raw = nameEl.value.trim();
|
||
const grams = num(gEl.value, 0);
|
||
if(!raw){ setMsg(msgEl, '请先输入食物名称。', false); return; }
|
||
if(grams <= 0){ setMsg(msgEl, '分量要大于 0 g。', false); return; }
|
||
const key = findFood(raw);
|
||
if(!key){ setMsg(msgEl, '食物库里没有「' + raw + '」,换个写法(如「米饭」),或用下方「加入食物库」自己添加。', false); return; }
|
||
S.days[i].meals.push({meal:mealEl.value, name:key, grams:grams});
|
||
nameEl.value = ''; nameEl.focus();
|
||
setMsg(msgEl, '已添加:' + key + ' ' + fmt(grams,0) + ' g ≈ ' + fmt(FOODS[key][0]*grams/100,0) + ' kcal', true);
|
||
render(); save();
|
||
}
|
||
|
||
/* ---------- 3.2 对照表 ---------- */
|
||
function dayValue(row, i){
|
||
if(row.dayKey){
|
||
const v = S.days[i].water;
|
||
return (v === '' || v == null) ? null : num(v,0);
|
||
}
|
||
if(!(S.days[i].meals || []).length) return null;
|
||
return dayTotals(i)[row.key];
|
||
}
|
||
function compareData(){
|
||
const p1 = p1calc();
|
||
const rows = [
|
||
{label:'总热量(kcal)', key:'kcal', target:num(p1.target), dec:0},
|
||
{label:'蛋白质(g)', key:'protein', target:num(S.p2.val.protein), dec:1},
|
||
{label:'脂肪(g)', key:'fat', target:num(S.p2.val.fat), dec:1},
|
||
{label:'碳水化合物(g)', key:'carb', target:num(S.p2.val.carb), dec:1},
|
||
{label:'膳食纤维(g)', key:'fib', target:num(S.p2.val.fiber), dec:1, min:true},
|
||
{label:'饮水(mL)', key:'water', target:num(S.p2.val.water), dec:0, min:true, dayKey:true}
|
||
];
|
||
rows.forEach(r=>{
|
||
r.vals = [0,1,2].map(i => dayValue(r, i));
|
||
const vals = r.vals.filter(v => v != null);
|
||
r.avg = vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : null;
|
||
r.j = judge(r.target, r.avg, r.min);
|
||
r.dev = (r.avg == null || !r.target) ? null : (r.avg - r.target) / r.target;
|
||
});
|
||
return {p1, rows};
|
||
}
|
||
function updateCompare(){
|
||
const {p1, rows} = compareData();
|
||
let html = '';
|
||
rows.forEach(r=>{
|
||
const devTxt = (r.dev == null) ? '—' : ((r.dev >= 0 ? '+' : '−') + fmt(Math.abs(r.dev)*100,0) + '%');
|
||
const devCls = (r.dev == null) ? '' : (Math.abs(r.dev) <= 0.10 ? '' : (Math.abs(r.dev) <= 0.20 ? 'style="color:#b45309"' : 'style="color:#b91c1c;font-weight:600"'));
|
||
html += '<tr><td>' + r.label + '</td>' +
|
||
'<td class="num">' + (r.target ? fmt(r.target, r.dec) : '—') + '</td>' +
|
||
[0,1,2].map(i => '<td class="num">' + (r.vals[i] == null ? '—' : fmt(r.vals[i], r.dec)) + '</td>').join('') +
|
||
'<td class="num"><b>' + (r.avg == null ? '—' : fmt(r.avg, r.dec)) + '</b></td>' +
|
||
'<td class="num" ' + devCls + '>' + devTxt + '</td>' +
|
||
'<td><span class="tag ' + r.j.c + '">' + r.j.t + '</span></td></tr>';
|
||
});
|
||
/* 钙 / 铁 / 维 C:定性行 */
|
||
const qualRows = [
|
||
{label:'钙(mg)', target:num(S.p2.val.ca), key:'ca', hint:'奶、豆制品、深绿色蔬菜'},
|
||
{label:'铁(mg)', target:num(S.p2.val.fe), key:'fe', hint:'红肉、动物肝脏、动物血'},
|
||
{label:'维生素 C(mg)', target:num(S.p2.val.vc), key:'vc', hint:'新鲜蔬菜、水果'}
|
||
];
|
||
qualRows.forEach(q=>{
|
||
const vals = [0,1,2].map(i => S.days[i][q.key] || '');
|
||
const filled = vals.filter(Boolean);
|
||
let main = '';
|
||
if(filled.length){
|
||
const cnt = {};
|
||
filled.forEach(v => cnt[v] = (cnt[v]||0)+1);
|
||
main = Object.keys(cnt).sort((a,b)=>cnt[b]-cnt[a])[0];
|
||
}
|
||
const cls = main === '充足' ? 'ok' : (main === '基本充足' ? 'mid' : (main === '不足' ? 'bad' : 'na'));
|
||
html += '<tr><td>' + q.label + '<div class="hint" style="margin:0">' + q.hint + '</div></td>' +
|
||
'<td class="num">' + fmt(q.target,0) + '</td>' +
|
||
vals.map(v => '<td class="num" style="font-size:12.5px">' + (v || '—') + '</td>').join('') +
|
||
'<td class="num">定性</td><td class="num">—</td>' +
|
||
'<td><span class="tag ' + cls + '">' + (main || '未填') + '</span></td></tr>';
|
||
});
|
||
$('#cmpBody').innerHTML = html;
|
||
|
||
/* 汇总 */
|
||
const counted = rows.filter(r => r.avg != null && r.target);
|
||
const ok = counted.filter(r => r.j.c === 'ok').length;
|
||
const mid = counted.filter(r => r.j.c === 'mid').length;
|
||
const bad = counted.filter(r => r.j.c === 'bad').length;
|
||
let overall = '数据不足';
|
||
if(counted.length){
|
||
if(bad === 0 && ok >= Math.ceil(counted.length/2)) overall = '合格';
|
||
else if(bad <= 1) overall = '基本合格';
|
||
else overall = '不合格';
|
||
}
|
||
/* 与目标偏差最大的一天(按总热量) */
|
||
let worstDay = null, worstDev = 0;
|
||
if(p1.target > 0){
|
||
[0,1,2].forEach(i=>{
|
||
const v = dayValue(rows[0], i);
|
||
if(v == null) return;
|
||
const d = Math.abs(v - p1.target);
|
||
if(d > worstDev){ worstDev = d; worstDay = i; }
|
||
});
|
||
}
|
||
const sum = $('#cmpSummary');
|
||
if(!counted.length){
|
||
sum.innerHTML = '还没有记录数据 —— 先在 3.1 里添加食物。';
|
||
} else {
|
||
const r0 = rows[0];
|
||
sum.innerHTML =
|
||
'<div>3 天平均摄入 <b>' + fmt(r0.avg,0) + ' kcal</b>,目标 <b>' + fmt(p1.target,0) + ' kcal</b>,达成率 <b>' +
|
||
fmt(r0.avg/p1.target*100,0) + '%</b>。</div>' +
|
||
'<div>判定:合格 <b>' + ok + '</b> 项、基本合格 <b>' + mid + '</b> 项、不合格 <b>' + bad + '</b> 项 → 总体:<span class="tag ' +
|
||
(overall === '合格' ? 'ok' : (overall === '基本合格' ? 'mid' : 'bad')) + '">' + overall + '</span></div>' +
|
||
(worstDay == null ? '' :
|
||
'<div>与目标偏差最大的一天:<b>第 ' + (worstDay+1) + ' 天</b>(' + fmt(dayValue(rows[0], worstDay),0) +
|
||
' kcal,偏差 ' + fmt(Math.abs(dayValue(rows[0], worstDay) - p1.target)/p1.target*100,0) + '%)。</div>');
|
||
}
|
||
/* 3.3 结论 1 */
|
||
const c1 = $('#concl1');
|
||
if(!counted.length){
|
||
c1.textContent = '还没有数据 —— 填好 3.1 的记录后这里会自动统计。';
|
||
} else {
|
||
let worstRow = null;
|
||
counted.forEach(r=>{ if(r.dev != null && (!worstRow || Math.abs(r.dev) > Math.abs(worstRow.dev))) worstRow = r; });
|
||
c1.innerHTML = '合格 <b>' + ok + '</b> 项,基本合格 <b>' + mid + '</b> 项,不合格 <b>' + bad + '</b> 项。' +
|
||
(worstRow ? '差距最大的是 <b>' + worstRow.label + '</b>:3 天平均 ' + fmt(worstRow.avg, worstRow.dec) +
|
||
',目标 ' + fmt(worstRow.target, worstRow.dec) + ',偏差 ' + (worstRow.dev >= 0 ? '+' : '−') +
|
||
fmt(Math.abs(worstRow.dev)*100,0) + '%。' : '') +
|
||
(worstDay == null ? '' : ' 与目标偏差最大的一天是第 ' + (worstDay+1) + ' 天。');
|
||
}
|
||
window.__cmp = {rows, ok, mid, bad, overall, p1, worstDay};
|
||
}
|
||
|
||
/* ---------- 4.2 / 5.1 汇总 ---------- */
|
||
function updateFinal(){
|
||
const p1 = p1calc();
|
||
$('#finalKcal').textContent = fmt(p1.target,0);
|
||
$('#finalKcalSrc').textContent = p1.manual
|
||
? '(手动设定)'
|
||
: '(= BMR ' + fmt(p1.bmr,0) + ' × ' + p1.act.f + ' ' + (p1.sign === 0 ? '± 0' : (p1.sign > 0 ? '+ ' : '− ') + Math.abs(p1.adj)) + ')';
|
||
const bp = num(S.p42.bp,0), lp = num(S.p42.lp,0), dp = num(S.p42.dp,0), tot = bp + lp + dp;
|
||
const hint = $('#pctHint');
|
||
if(tot === 100){
|
||
hint.innerHTML = '<span style="color:#047857">合计 100% ✓ 早餐 ' + fmt(p1.target*bp/100,0) + ' kcal / 午餐 ' +
|
||
fmt(p1.target*lp/100,0) + ' kcal / 晚餐 ' + fmt(p1.target*dp/100,0) + ' kcal</span>';
|
||
} else {
|
||
hint.innerHTML = '<span style="color:#b91c1c">合计 ' + fmt(tot,0) + '%,应为 100%(差 ' + fmt(100-tot,0) + '%)。</span> ' +
|
||
'按现在的比例,早餐 ' + fmt(p1.target*bp/100,0) + ' / 午餐 ' + fmt(p1.target*lp/100,0) + ' / 晚餐 ' + fmt(p1.target*dp/100,0) + ' kcal';
|
||
}
|
||
}
|
||
|
||
function updateP5Summary(){
|
||
if(!window.__cmp) updateCompare();
|
||
const c = window.__cmp;
|
||
const box = $('#p5Summary');
|
||
if(!c || !c.rows.length){ box.textContent = '—'; return; }
|
||
const r0 = c.rows[0], p = c.p1;
|
||
const rP = c.rows.find(r=>r.key==='protein'), rF = c.rows.find(r=>r.key==='fat'), rC = c.rows.find(r=>r.key==='carb');
|
||
const iter = S.p4.rows.filter(r => (r.before||r.after||r.q));
|
||
const tdee = p.tdee;
|
||
box.innerHTML =
|
||
'<div class="sum-row"><b>能量目标</b>:BMR ' + fmt(p.bmr,0) + ' × 活动系数 ' + p.act.f + ' = TDEE ' + fmt(tdee,0) +
|
||
' kcal;按「' + ({maintain:'维持',cut:'减脂',bulk:'增肌'}[p.goal]||'维持') + '」调整后每日目标 <b>' + fmt(p.target,0) + ' kcal</b>。</div>' +
|
||
'<div class="sum-row"><b>3 天平均摄入</b>:' + (r0.avg == null ? '—' : fmt(r0.avg,0) + ' kcal,达成率 ' + fmt(r0.avg/p.target*100,0) + '%') + '。</div>' +
|
||
'<div class="sum-row"><b>三大营养素平均</b>:蛋白质 ' + (rP&&rP.avg!=null?fmt(rP.avg,1):'—') + ' g(目标 ' + fmt(S.p2.val.protein,0) +
|
||
' g)/脂肪 ' + (rF&&rF.avg!=null?fmt(rF.avg,1):'—') + ' g(目标 ' + fmt(S.p2.val.fat,0) +
|
||
' g)/碳水 ' + (rC&&rC.avg!=null?fmt(rC.avg,1):'—') + ' g(目标 ' + fmt(S.p2.val.carb,0) + ' g)。</div>' +
|
||
'<div class="sum-row"><b>核验判定</b>:合格 ' + c.ok + ' 项、基本合格 ' + c.mid + ' 项、不合格 ' + c.bad + ' 项 → 总体 <b>' + c.overall + '</b>。</div>' +
|
||
'<div class="sum-row"><b>迭代情况</b>:' + (iter.length ? '已完成 ' + iter.length + ' 轮;最近一轮针对:' + esc((iter[iter.length-1].q||'(未填写)').slice(0,60)) : '还没有填写迭代记录。') + '</div>';
|
||
}
|
||
|
||
function updateOverview(){
|
||
const p1 = p1calc();
|
||
const c = window.__cmp;
|
||
const r0 = c && c.rows[0];
|
||
$('#ovTargetKcal').textContent = fmt(p1.target,0);
|
||
const goalTxt = {maintain:'维持体重', cut:'减脂(TDEE − ' + Math.abs(p1.adj) + ')', bulk:'增肌(TDEE + ' + Math.abs(p1.adj) + ')'}[p1.goal] || '维持体重';
|
||
$('#ovGoalText').textContent = goalTxt + ' | BMR ' + fmt(p1.bmr,0) + ' kcal × 活动系数 ' + p1.act.f + '(' + p1.act.name + ')';
|
||
$('#ovBmi').textContent = p1.bmi > 0 ? fmt(p1.bmi,1) : '—';
|
||
$('#ovBmr').textContent = fmt(p1.bmr,0);
|
||
$('#ovTdee').textContent = fmt(p1.tdee,0);
|
||
if(r0 && r0.avg != null){
|
||
$('#ovAvg').textContent = fmt(r0.avg,0);
|
||
$('#ovRate').textContent = fmt(r0.avg/p1.target*100,0) + '%';
|
||
} else { $('#ovAvg').textContent = '—'; $('#ovRate').textContent = '—'; }
|
||
const vEl = $('#ovVerdict');
|
||
if(c && r0 && r0.avg != null){
|
||
vEl.textContent = c.overall;
|
||
} else { vEl.textContent = '待核验'; }
|
||
|
||
const daysCount = S.days.filter(d => (d.meals||[]).length > 0).length;
|
||
const p2ok = NUTRIENTS.every(n => num(S.p2.val[n.key]) > 0);
|
||
const iterOk = S.p4.rows.some(r => (r.before || r.after)) || !!S.p42.must0;
|
||
const selfOk = ['s1','s2','s3','s4','s5'].every(k => S.p5[k]);
|
||
const items = [
|
||
['第一部分:基础数据 + 热量目标', num(S.p1.weight) > 0 && num(S.p1.height) > 0 && p1.target > 0],
|
||
['第二部分:8 项营养目标 + 依据', p2ok],
|
||
['第三部分:连续 3 天记录与核验(已完成 ' + daysCount + '/3 天)', daysCount >= 3],
|
||
['第四部分:至少 1 轮迭代 / 最终版方案', iterOk],
|
||
['第五部分:自评 5 项 + 同伴互评', selfOk]
|
||
];
|
||
$('#progressList').innerHTML = items.map(it =>
|
||
'<div class="check ' + (it[1] ? 'done' : '') + '"><span class="mark">' + (it[1] ? '✓' : '○') + '</span>' + it[0] + '</div>').join('');
|
||
}
|
||
|
||
function updatePrintMeta(){
|
||
$('#printMeta').textContent = '学号:' + (S.meta.sid || '___') + ' 姓名:' + (S.meta.name || '___') + ' 班级:' + (S.meta.cls || '___');
|
||
}
|
||
|
||
/* ---------- 4.1 迭代块 ---------- */
|
||
function renderIter(){
|
||
$('#iterBox').innerHTML = S.p4.rows.map((r,i)=>
|
||
'<div class="iter">' +
|
||
'<div class="iter-head"><b>第 ' + (i+1) + ' 轮迭代</b>' +
|
||
(S.p4.rows.length > 1 ? '<button class="link-del" data-deliter="' + i + '">删除这一轮</button>' : '') + '</div>' +
|
||
'<label>要解决的问题(来自 3.3)</label>' +
|
||
'<div class="inline-flex"><input type="text" data-i="' + i + '" data-f="q" value="' + esc(r.q) + '" placeholder="例:脂肪 3 天平均超标 14%,主要来自炒菜油和五花肉">' +
|
||
'<button class="btn ghost nowrap" data-fill="' + i + '">带入最差项</button></div>' +
|
||
'<div class="grid g2" style="margin-top:12px">' +
|
||
'<div><label>调整前</label><textarea data-i="' + i + '" data-f="before" rows="2" placeholder="例:每天炒菜用油约 40 g,晚餐常有五花肉">' + esc(r.before) + '</textarea></div>' +
|
||
'<div><label>调整后</label><textarea data-i="' + i + '" data-f="after" rows="2" placeholder="例:炒菜油减到 25 g;五花肉改成每周 1 次、每次 60 g">' + esc(r.after) + '</textarea></div>' +
|
||
'</div>' +
|
||
'<div style="margin-top:12px"><label>调整理由</label><textarea data-i="' + i + '" data-f="why" rows="2" placeholder="例:脂肪超标主要是烹调油,减油最容易做到;红肉保留但减量,不影响蛋白质达标">' + esc(r.why) + '</textarea></div>' +
|
||
'<div style="margin-top:12px"><label>再验证结果(调整后执行几天?结果如何)</label><textarea data-i="' + i + '" data-f="res" rows="2" placeholder="例:执行 3 天后,脂肪平均 71 g,与目标偏差 5%,判定合格">' + esc(r.res) + '</textarea></div>' +
|
||
'</div>').join('');
|
||
}
|
||
function worstProblemText(){
|
||
if(!window.__cmp) updateCompare();
|
||
const c = window.__cmp;
|
||
if(!c) return '';
|
||
const bad = c.rows.filter(r => r.j.c === 'bad' || r.j.c === 'mid').sort((a,b)=>Math.abs(b.dev||0)-Math.abs(a.dev||0));
|
||
if(!bad.length) return '';
|
||
const r = bad[0];
|
||
return r.label.replace(/(.*?)/,'') + ':3 天平均 ' + fmt(r.avg, r.dec) + ',目标 ' + fmt(r.target, r.dec) +
|
||
',偏差 ' + (r.dev >= 0 ? '+' : '−') + fmt(Math.abs(r.dev)*100,0) + '%';
|
||
}
|
||
|
||
/* ==================== 八、存储 / 导出 ==================== */
|
||
function save(){
|
||
try{ localStorage.setItem(LS, JSON.stringify(S)); }catch(e){}
|
||
}
|
||
function load(){
|
||
try{
|
||
const raw = localStorage.getItem(LS);
|
||
if(!raw) return;
|
||
const o = JSON.parse(raw);
|
||
hydrate(o, S);
|
||
}catch(e){}
|
||
}
|
||
function hydrate(src, dst){
|
||
if(!src || typeof src !== 'object') return dst;
|
||
Object.keys(dst).forEach(k=>{
|
||
if(src[k] === undefined) return;
|
||
if(Array.isArray(dst[k])){
|
||
if(Array.isArray(src[k])) dst[k] = src[k];
|
||
return;
|
||
}
|
||
if(dst[k] && typeof dst[k] === 'object' && !Array.isArray(dst[k])){
|
||
Object.keys(dst[k]).forEach(kk=>{
|
||
if(src[k] && src[k][kk] !== undefined){
|
||
if(dst[k][kk] && typeof dst[k][kk] === 'object' && !Array.isArray(dst[k][kk])) Object.assign(dst[k][kk], src[k][kk]);
|
||
else dst[k][kk] = src[k][kk];
|
||
}
|
||
});
|
||
} else {
|
||
dst[k] = src[k];
|
||
}
|
||
});
|
||
return dst;
|
||
}
|
||
function downloadText(fname, text, mime){
|
||
try{
|
||
const blob = new Blob([text], {type: (mime||'text/plain') + ';charset=utf-8'});
|
||
const url = URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.href = url; a.download = fname;
|
||
document.body.appendChild(a); a.click();
|
||
setTimeout(()=>{ URL.revokeObjectURL(url); a.remove(); }, 1500);
|
||
toast('已导出:' + fname);
|
||
}catch(e){
|
||
showText('导出内容(请复制保存)', text);
|
||
}
|
||
}
|
||
function showText(title, text){
|
||
$('#dlgTitle').textContent = title;
|
||
$('#dlgText').value = text;
|
||
const d = $('#dlg');
|
||
if(d.showModal) d.showModal(); else alert(text);
|
||
}
|
||
|
||
function buildMarkdown(){
|
||
const p1 = p1calc();
|
||
const L = [];
|
||
const nm = S.meta.name || '____';
|
||
L.push('# 《我的健康饮食方案》项目书');
|
||
L.push('');
|
||
L.push('- 学号:' + (S.meta.sid || '__') + ' 姓名:' + nm + ' 班级:' + (S.meta.cls || '__'));
|
||
L.push('');
|
||
L.push('## 第一部分:理想热量摄入方案');
|
||
L.push('### 1.1 我的基础数据');
|
||
L.push('| 项目 | 值 |');
|
||
L.push('| --- | --- |');
|
||
L.push('| 年龄 / 性别 | ' + num(S.p1.age,0) + ' 岁 / ' + (p1.sex === 'male' ? '男' : '女') + ' |');
|
||
L.push('| 身高 / 体重 | ' + num(S.p1.height,0) + ' cm / ' + num(S.p1.weight,0) + ' kg |');
|
||
L.push('| 日常活动水平 | ' + p1.act.name + '(' + p1.act.desc + ',系数 ' + p1.act.f + ') |');
|
||
L.push('| BMI | ' + fmt(p1.bmi,1) + ' |');
|
||
L.push('');
|
||
L.push('### 1.2 热量计算过程');
|
||
L.push('```');
|
||
L.push('BMR = 10 × ' + fmt(p1.w,0) + ' + 6.25 × ' + fmt(p1.h,0) + ' − 5 × ' + fmt(p1.age,0) + (p1.sex === 'male' ? ' + 5' : ' − 161') + ' = ' + fmt(p1.bmr,1) + ' kcal');
|
||
L.push('TDEE = ' + fmt(p1.bmr,1) + ' × ' + p1.act.f + ' = ' + fmt(p1.tdee,0) + ' kcal');
|
||
L.push('目标摄入 = ' + fmt(p1.tdee,0) + (p1.sign === 0 ? ' ± 0' : (p1.sign > 0 ? ' + ' : ' − ') + Math.abs(p1.adj)) + ' = ' + fmt(p1.target,0) + ' kcal');
|
||
L.push('```');
|
||
if(S.p1.calcNote) L.push('补充说明:' + S.p1.calcNote);
|
||
L.push('');
|
||
L.push('### 1.3 我的热量目标');
|
||
L.push('- 每日总消耗(TDEE):' + fmt(p1.tdee,0) + ' kcal');
|
||
L.push('- 目标方向:' + ({maintain:'维持体重', cut:'减脂', bulk:'增肌'}[p1.goal] || '维持体重') + ',调整 ' + (p1.sign === 0 ? 0 : Math.abs(p1.adj)) + ' kcal');
|
||
L.push('- 每日热量摄入目标:**' + fmt(p1.target,0) + ' kcal**');
|
||
L.push('- 目标理由:' + (S.p1.reason || '(未填写)'));
|
||
L.push('');
|
||
L.push('## 第二部分:理想营养摄入方案');
|
||
L.push('### 2.1 每日营养目标');
|
||
L.push('| 营养素 | 每日目标 | 依据 |');
|
||
L.push('| --- | --- | --- |');
|
||
const p2basis = {
|
||
carb:'占总热量 50%–65%(取 55%),1 g = 4 kcal',
|
||
protein:'1.6 g/kg × 体重(青少年 1.2–2.0 g/kg)',
|
||
fat:'占总热量 20%–30%(取 25%),1 g = 9 kcal',
|
||
water:'14–17 岁饮水量(男 1700 / 女 1500 mL),仅指喝水',
|
||
fiber:'14–17 岁推荐 25–30 g',
|
||
ca:'14–17 岁推荐 1000 mg',
|
||
fe:'14–17 岁推荐:男 16 / 女 18 mg',
|
||
vc:'14–17 岁推荐 100 mg'
|
||
};
|
||
NUTRIENTS.forEach(n=>{
|
||
L.push('| ' + n.label + ' | ' + fmt(S.p2.val[n.key],0) + ' ' + n.unit + ' | ' + (p2basis[n.key]||'') + ' |');
|
||
});
|
||
const v = S.p2.val;
|
||
const ep = num(v.protein)*4, ef = num(v.fat)*9, ec = num(v.carb)*4, tot = ep+ef+ec;
|
||
if(tot > 0) L.push('\n三大营养素供能占比:蛋白质 ' + fmt(ep/tot*100,0) + '% / 脂肪 ' + fmt(ef/tot*100,0) + '% / 碳水 ' + fmt(ec/tot*100,0) + '%。');
|
||
L.push('');
|
||
L.push('## 第三部分:真实数据核验');
|
||
L.push('### 3.1 真实饮食记录');
|
||
S.days.forEach((d,i)=>{
|
||
L.push('');
|
||
L.push('**第 ' + (i+1) + ' 天**' + (d.date ? '(' + d.date + ')' : '') + (d.weekend ? '(' + d.weekend + ')' : ''));
|
||
L.push('| 餐次 | 食物及分量 | 热量(kcal) | 蛋白(g) | 脂肪(g) | 碳水(g) | 纤维(g) |');
|
||
L.push('| --- | --- | --- | --- | --- | --- | --- |');
|
||
(d.meals||[]).forEach(m=>{
|
||
const per = FOODS[m.name] || [0,0,0,0,0], k = num(m.grams,0)/100;
|
||
L.push('| ' + m.meal + ' | ' + m.name + ' ' + fmt(m.grams,0) + ' g | ' + fmt(per[0]*k,0) + ' | ' + fmt(per[1]*k,1) +
|
||
' | ' + fmt(per[2]*k,1) + ' | ' + fmt(per[3]*k,1) + ' | ' + fmt(per[4]*k,1) + ' |');
|
||
});
|
||
const t = dayTotals(i);
|
||
L.push('| **当日合计** | 饮水量 ' + (d.water===''||d.water==null ? '—' : num(d.water,0) + ' mL') + ' | **' + fmt(t.kcal,0) + '** | **' + fmt(t.p,1) +
|
||
'** | **' + fmt(t.f,1) + '** | **' + fmt(t.c,1) + '** | **' + fmt(t.fib,1) + '** |');
|
||
L.push('钙 / 铁 / 维 C 定性:' + (d.ca||'—') + ' / ' + (d.fe||'—') + ' / ' + (d.vc||'—') + (d.note ? ' 特别说明:' + d.note : ''));
|
||
});
|
||
L.push('');
|
||
L.push('### 3.2 核验对照表');
|
||
if(!window.__cmp) updateCompare();
|
||
const c = window.__cmp;
|
||
L.push('| 项目 | 我的目标 | 第 1 天 | 第 2 天 | 第 3 天 | 3 天平均 | 偏差 | 判定 |');
|
||
L.push('| --- | --- | --- | --- | --- | --- | --- | --- |');
|
||
c.rows.forEach(r=>{
|
||
L.push('| ' + r.label + ' | ' + fmt(r.target,r.dec) + ' | ' +
|
||
r.vals.map(x => x==null ? '—' : fmt(x,r.dec)).join(' | ') + ' | ' +
|
||
(r.avg==null?'—':fmt(r.avg,r.dec)) + ' | ' +
|
||
(r.dev==null?'—':((r.dev>=0?'+':'−') + fmt(Math.abs(r.dev)*100,0) + '%')) + ' | ' + r.j.t + ' |');
|
||
});
|
||
L.push('\n总体判定:合格 ' + c.ok + ' 项、基本合格 ' + c.mid + ' 项、不合格 ' + c.bad + ' 项 → **' + c.overall + '**。');
|
||
L.push('');
|
||
L.push('### 3.3 核验结论');
|
||
L.push('1. ' + ($('#concl1').textContent || ''));
|
||
L.push('2. 不达标的主要原因:' + (S.p33.reason || '(未填写)'));
|
||
L.push('3. 做得好的部分:' + (S.p33.good || '(未填写)'));
|
||
L.push('');
|
||
L.push('## 第四部分:方案迭代');
|
||
L.push('### 4.1 迭代记录');
|
||
S.p4.rows.forEach((r,i)=>{
|
||
if(!(r.q||r.before||r.after||r.why||r.res)) return;
|
||
L.push('');
|
||
L.push('**第 ' + (i+1) + ' 轮**');
|
||
L.push('- 要解决的问题:' + (r.q||'—'));
|
||
L.push('- 调整前:' + (r.before||'—'));
|
||
L.push('- 调整后:' + (r.after||'—'));
|
||
L.push('- 调整理由:' + (r.why||'—'));
|
||
L.push('- 再验证结果:' + (r.res||'—'));
|
||
});
|
||
L.push('');
|
||
L.push('### 4.2 我的最终版健康饮食方案');
|
||
L.push('- 每日热量目标:' + fmt(p1.target,0) + ' kcal');
|
||
L.push('- 三餐分配:早 ' + num(S.p42.bp,0) + '% / 午 ' + num(S.p42.lp,0) + '% / 晚 ' + num(S.p42.dp,0) + '%');
|
||
L.push('- 每日必做的 3 件事:① ' + (S.p42.must0||'—') + ' ② ' + (S.p42.must1||'—') + ' ③ ' + (S.p42.must2||'—'));
|
||
L.push('- 需要避免的饮食习惯:' + (S.p42.avoid||'—'));
|
||
L.push('- 「理想」与「现实」的取舍:' + (S.p42.tradeoff||'—'));
|
||
L.push('');
|
||
L.push('## 第五部分:评价');
|
||
L.push('### 5.1 学生自评');
|
||
const selfItems = ['我会计算个人的热量需求(BMR、TDEE)','我设计出了合理的营养素目标','我坚持完成了 3 天真实记录','我能分析方案与现实差距的原因','我迭代了方案,并做了再验证'];
|
||
selfItems.forEach((t,i)=>{ L.push('- ' + t + ':' + (S.p5['s'+(i+1)] || '(未选)')); });
|
||
L.push('- 我最大的收获:' + (S.p5.gain||'(未填写)'));
|
||
L.push('');
|
||
L.push('### 5.2 同伴互评');
|
||
L.push('- 评价人:' + (S.peer.who||'___') + ' 与被评价人的关系:' + (S.peer.rel||'—') + ' 日期:' + (S.peer.date||'—'));
|
||
const peerItems = ['热量计算过程完整、有依据','营养素目标设置合理','3 天真实饮食记录完整、可信','核验结论的原因分析具体、符合实际','迭代调整有针对性,且做了再验证','项目书整体填写完整、工整'];
|
||
peerItems.forEach((t,i)=>{ L.push('- ' + t + ':' + (S.peer['i'+(i+1)] || '(未选)')); });
|
||
L.push('- 给同伴最有价值的一点:' + (S.peer.best||'(未填写)'));
|
||
L.push('- 我的建议:' + (S.peer.advice||'(未填写)'));
|
||
L.push('');
|
||
L.push('---');
|
||
L.push('*生成时间:' + new Date().toLocaleString('zh-CN') + ' (本文件由《我的健康饮食方案》可交互项目书导出)*');
|
||
return L.join('\n');
|
||
}
|
||
|
||
/* ==================== 九、示例数据 ==================== */
|
||
function loadDemo(){
|
||
const d = defState();
|
||
d.meta = {sid:'17', name:'张小明', cls:'高一(3)班'};
|
||
d.p1.activity = 'moderate';
|
||
d.days[0] = {date:'', weekend:'工作日', water:1200, ca:'基本充足', fe:'基本充足', vc:'充足', note:'',
|
||
meals:[
|
||
{meal:'早餐', name:'馒头', grams:100}, {meal:'早餐', name:'鸡蛋', grams:50}, {meal:'早餐', name:'牛奶(全脂)', grams:250},
|
||
{meal:'午餐', name:'米饭(蒸,熟)', grams:200}, {meal:'午餐', name:'鸡胸肉', grams:100}, {meal:'午餐', name:'西兰花', grams:150},
|
||
{meal:'晚餐', name:'米饭(蒸,熟)', grams:200}, {meal:'晚餐', name:'猪瘦肉', grams:80}, {meal:'晚餐', name:'菠菜', grams:150},
|
||
{meal:'加餐', name:'香蕉', grams:100}
|
||
]};
|
||
d.days[1] = {date:'', weekend:'工作日', water:1500, ca:'基本充足', fe:'不足', vc:'基本充足', note:'',
|
||
meals:[
|
||
{meal:'早餐', name:'燕麦片(干)', grams:60}, {meal:'早餐', name:'牛奶(全脂)', grams:250}, {meal:'早餐', name:'鸡蛋', grams:50},
|
||
{meal:'午餐', name:'面条(煮熟)', grams:250}, {meal:'午餐', name:'猪瘦肉', grams:80}, {meal:'午餐', name:'番茄', grams:150},
|
||
{meal:'晚餐', name:'米饭(蒸,熟)', grams:150}, {meal:'晚餐', name:'草鱼', grams:120}, {meal:'晚餐', name:'生菜', grams:100},
|
||
{meal:'加餐', name:'酸奶(全脂)', grams:150}, {meal:'加餐', name:'核桃', grams:15}
|
||
]};
|
||
d.days[2] = {date:'', weekend:'周末', water:800, ca:'不足', fe:'基本充足', vc:'不足', note:'周末在家,饮料和零食偏多',
|
||
meals:[
|
||
{meal:'早餐', name:'全麦面包', grams:100}, {meal:'早餐', name:'鸡蛋', grams:100}, {meal:'早餐', name:'牛奶(全脂)', grams:250},
|
||
{meal:'午餐', name:'米饭(蒸,熟)', grams:250}, {meal:'午餐', name:'猪五花肉', grams:80}, {meal:'午餐', name:'大白菜', grams:150},
|
||
{meal:'晚餐', name:'米饭(蒸,熟)', grams:200}, {meal:'晚餐', name:'三文鱼', grams:120}, {meal:'晚餐', name:'西兰花', grams:150},
|
||
{meal:'加餐', name:'可乐', grams:330}, {meal:'加餐', name:'薯片', grams:50}
|
||
]};
|
||
d.p33.reason = '';
|
||
d.p33.good = '早餐每天都吃到了鸡蛋和牛奶,因为前一晚就把食材放好在冰箱,早上只用 5 分钟。';
|
||
d.p4.rows[0] = {
|
||
q:'脂肪超标,主要来自炒菜油、五花肉和零食',
|
||
before:'炒菜用油约 40 g/天;周末吃五花肉 80 g;加餐是薯片和可乐',
|
||
after:'炒菜油减到 25 g/天;五花肉改成每周 1 次、每次 60 g;加餐换成水果或无糖酸奶',
|
||
why:'脂肪超标的主要来源是烹调油和零食,这两项最容易改,而且不影响蛋白质达标',
|
||
res:'调整后执行 3 天:脂肪平均 71 g,与目标偏差 5%,判定合格'
|
||
};
|
||
d.p42 = {bp:30, lp:40, dp:30, must0:'早餐一定有 1 个鸡蛋 + 250 mL 牛奶', must1:'午晚餐各吃 1 拳头蔬菜',
|
||
must2:'全天喝水不低于 1500 mL,含糖饮料换成水', avoid:'晚餐后吃薯片、把奶茶当水喝',
|
||
tradeoff:'坚持早餐和饮水两条;食堂菜偏油就先过一遍热水再吃,不强求完全水煮。'};
|
||
d.p5 = {s1:'完全做到', s2:'基本做到', s3:'完全做到', s4:'基本做到', s5:'基本做到',
|
||
gain:'原来以为「吃够热量」很难,实际加一杯牛奶 + 一小把坚果就够了;反倒是「少油」最难。'};
|
||
d.peer = {who:'李华', rel:'同班', date:'', i1:'优秀', i2:'良好', i3:'优秀', i4:'良好', i5:'合格', i6:'优秀',
|
||
best:'把「一天吃够蛋白质」拆成早鸡蛋、午鸡胸、晚瘦牛肉,比空喊目标有用得多。',
|
||
advice:'第 2 天的晚餐没有写分量,建议补上「米饭 200 g」这样的数字,否则 3 天平均没法对照。'};
|
||
S = d;
|
||
buildAdjustOptions();
|
||
renderP2Body();
|
||
buildDayPanels();
|
||
renderIter();
|
||
render(); save();
|
||
toast('已载入示例数据 —— 可直接改,也可以点「清空」重新填');
|
||
}
|
||
|
||
/* ==================== 十、事件与初始化 ==================== */
|
||
function initEvents(){
|
||
document.addEventListener('input', onField);
|
||
document.addEventListener('change', onField);
|
||
|
||
/* 标签页 */
|
||
$('#tabs').addEventListener('click', e=>{
|
||
const b = e.target.closest('.tab'); if(!b) return;
|
||
$$('.tab').forEach(t=>t.classList.toggle('active', t === b));
|
||
$$('.panel').forEach(p=>p.classList.toggle('active', p.id === 'tab-' + b.dataset.tab));
|
||
window.scrollTo({top:0, behavior:'smooth'});
|
||
});
|
||
|
||
/* 日期:第 1 天为今天 */
|
||
$('#dayTabs').addEventListener('click', e=>{
|
||
const b = e.target.closest('.dtab'); if(!b) return;
|
||
const i = b.dataset.day;
|
||
$$('.dtab').forEach(t=>t.classList.toggle('active', t === b));
|
||
$$('.day-panel').forEach(p=>p.classList.toggle('active', p.dataset.day === i));
|
||
});
|
||
|
||
/* 添加 / 删除食物 */
|
||
$('#dayPanels').addEventListener('click', e=>{
|
||
const add = e.target.closest('[data-add]');
|
||
if(add){ addFood(+add.dataset.add); return; }
|
||
const clr = e.target.closest('[data-clear]');
|
||
if(clr){
|
||
const i = +clr.dataset.clear;
|
||
if(confirm('确定清空第 ' + (i+1) + ' 天的所有食物记录?')){
|
||
S.days[i].meals = []; render(); save(); toast('已清空第 ' + (i+1) + ' 天');
|
||
}
|
||
return;
|
||
}
|
||
const del = e.target.closest('[data-del]');
|
||
if(del){
|
||
const [i, idx] = del.dataset.del.split('-').map(Number);
|
||
S.days[i].meals.splice(idx,1); render(); save();
|
||
}
|
||
});
|
||
$('#dayPanels').addEventListener('keydown', e=>{
|
||
if(e.key !== 'Enter') return;
|
||
const t = e.target;
|
||
if(t.id && t.id.indexOf('food-in-') === 0){ e.preventDefault(); addFood(+t.id.replace('food-in-','')); }
|
||
else if(t.id && t.id.indexOf('food-g-') === 0){ e.preventDefault(); addFood(+t.id.replace('food-g-','')); }
|
||
});
|
||
|
||
/* 自定义食物 */
|
||
$('#addCustom').addEventListener('click', ()=>{
|
||
const name = $('#cName').value.trim();
|
||
if(!name){ toast('请先填写食物名称'); return; }
|
||
const kcal = num($('#cKcal').value,0);
|
||
if(kcal <= 0){ toast('请填写该食物每 100 g 的热量'); return; }
|
||
FOODS[name] = [kcal, num($('#cP').value,0), num($('#cF').value,0), num($('#cC').value,0), num($('#cFib').value,0)];
|
||
$('#foodList').innerHTML = Object.keys(FOODS).map(k => '<option value="' + esc(k) + '"></option>').join('');
|
||
$('#cName').value = '';
|
||
toast('已加入食物库:' + name);
|
||
});
|
||
|
||
/* 营养素:恢复推荐值 */
|
||
document.addEventListener('click', e=>{
|
||
const rst = e.target.closest('[data-reset]');
|
||
if(rst){
|
||
const k = rst.dataset.reset;
|
||
S.p2.auto[k] = true; ensureP2(); render(); save();
|
||
toast('已恢复推荐值');
|
||
return;
|
||
}
|
||
if(e.target.closest('[data-reset-all]')){
|
||
NUTRIENTS.forEach(n => S.p2.auto[n.key] = true);
|
||
ensureP2(); render(); save();
|
||
toast('全部恢复推荐值');
|
||
return;
|
||
}
|
||
const fill = e.target.closest('[data-fill]');
|
||
if(fill){
|
||
const i = +fill.dataset.fill;
|
||
const txt = worstProblemText();
|
||
if(!txt){ toast('暂时没有明显不达标项(或还没记录数据)'); return; }
|
||
S.p4.rows[i].q = txt;
|
||
renderIter(); save();
|
||
toast('已带入最差项');
|
||
return;
|
||
}
|
||
const di = e.target.closest('[data-deliter]');
|
||
if(di){
|
||
S.p4.rows.splice(+di.dataset.deliter,1);
|
||
if(!S.p4.rows.length) S.p4.rows.push({q:'',before:'',after:'',why:'',res:''});
|
||
renderIter(); save();
|
||
return;
|
||
}
|
||
const ins = e.target.closest('[data-ins]');
|
||
if(ins){
|
||
const ta = $('[data-k="p33.reason"]');
|
||
const add = (ta.value ? ';' : '') + ins.dataset.ins;
|
||
ta.value = ta.value + add;
|
||
S.p33.reason = ta.value; save();
|
||
return;
|
||
}
|
||
});
|
||
|
||
/* 手动设定热量目标 */
|
||
$('#chkManual').addEventListener('change', ()=>{
|
||
if($('#chkManual').checked){
|
||
S.p1.kcalOverride = Math.round(p1calc().autoTarget);
|
||
render(); save();
|
||
$('#kcalOverride').focus();
|
||
} else {
|
||
S.p1.kcalOverride = '';
|
||
render(); save();
|
||
}
|
||
});
|
||
|
||
/* 迭代 */
|
||
$('#addIter').addEventListener('click', ()=>{
|
||
S.p4.rows.push({q:'',before:'',after:'',why:'',res:''});
|
||
renderIter(); save();
|
||
});
|
||
|
||
/* 工具按钮 */
|
||
$('#btnPrint').addEventListener('click', ()=>window.print());
|
||
$('#btnMd').addEventListener('click', ()=>showText('项目书 Markdown(可复制保存为 .md 交作业)', buildMarkdown()));
|
||
$('#btnExport').addEventListener('click', ()=>{
|
||
downloadText('我的健康饮食方案_项目书数据.json', JSON.stringify(S, null, 2), 'application/json');
|
||
});
|
||
$('#btnImport').addEventListener('click', ()=>$('#fileInput').click());
|
||
$('#fileInput').addEventListener('change', e=>{
|
||
const f = e.target.files[0]; if(!f) return;
|
||
const r = new FileReader();
|
||
r.onload = () => {
|
||
try{
|
||
const o = JSON.parse(r.result);
|
||
hydrate(o, S);
|
||
buildAdjustOptions(); renderP2Body(); buildDayPanels(); renderIter(); render(); save();
|
||
toast('已导入数据');
|
||
}catch(err){ toast('文件格式不对,请选择导出的 JSON 文件'); }
|
||
};
|
||
r.readAsText(f);
|
||
e.target.value = '';
|
||
});
|
||
$('#btnDemo').addEventListener('click', ()=>{
|
||
if(confirm('载入示例数据会覆盖当前内容,继续吗?')) loadDemo();
|
||
});
|
||
$('#btnClear').addEventListener('click', ()=>{
|
||
if(!confirm('确定清空全部内容,重新开始吗?')) return;
|
||
try{ localStorage.removeItem(LS); }catch(e){}
|
||
S = defState();
|
||
buildAdjustOptions(); renderP2Body(); buildDayPanels(); renderIter(); render(); save();
|
||
toast('已清空');
|
||
});
|
||
$('#dlgClose').addEventListener('click', ()=>$('#dlg').close());
|
||
}
|
||
|
||
function init(){
|
||
load();
|
||
buildAdjustOptions();
|
||
renderP2Body();
|
||
buildDayPanels();
|
||
renderIter();
|
||
render();
|
||
initEvents();
|
||
}
|
||
|
||
init();
|
||
</script>
|
||
</body>
|
||
</html>
|