新增每日营养摄入检验表

本次做出以下决策:
- 表格定为 5 列:检验项目、目标值、实际值(3 天均值)、达成率、判定
- 收录 15 个检验项目:总热量、蛋白质、脂肪、碳水化合物、膳食纤维、钙、铁、锌、镁、维生素 A、维生素 C、维生素 B1、维生素 B2、钠、饮水量
- 判定标准定为达成率在目标值 ±10% 以内合格,超过为偏高、低于为偏低
- 钠作为上限指标单独判定,不超过目标 110% 即合格,超过为超标
- 目标值一列可编辑,修改后达成率与判定自动重算
- 底部自动汇总已检验项、合格项、偏高项、偏低项与合格率
- 增加打印样式,支持直接导出 A4 PDF
- 目标值按我的身体数据(175 cm / 55 kg / 16 岁 / 男 / 约 10000 步 / 健康增重)设定
This commit is contained in:
2026-10-08 00:48:54 +00:00
parent 75ee785300
commit 2c4cf41b35
+360
View File
@@ -0,0 +1,360 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>每日营养摄入检验表</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 24px 16px;
background: #f1f5f9;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
color: #1e293b;
-webkit-font-smoothing: antialiased;
}
.page {
max-width: 900px;
margin: 0 auto;
background: #fff;
border-radius: 16px;
padding: 28px;
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
h1 {
font-size: 20px;
margin: 0 0 6px;
letter-spacing: 0.5px;
}
.sub {
font-size: 12px;
color: #64748b;
margin: 0 0 18px;
line-height: 1.7;
}
.meta {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 10px;
padding: 14px;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
margin-bottom: 20px;
}
.meta label {
display: block;
font-size: 11px;
color: #64748b;
margin-bottom: 3px;
}
.meta input {
width: 100%;
border: none;
border-bottom: 1px dashed #cbd5e1;
background: transparent;
font-size: 13px;
font-weight: 600;
color: #1e293b;
padding: 2px 0;
outline: none;
}
.meta input:focus { border-bottom-color: #10b981; }
table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
thead th {
background: #f1f5f9;
color: #475569;
font-weight: 600;
font-size: 12px;
text-align: left;
padding: 10px 12px;
border: 1px solid #e2e8f0;
white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.center { text-align: center; }
tbody td {
padding: 8px 12px;
border: 1px solid #e2e8f0;
vertical-align: middle;
}
tbody tr:nth-child(even) { background: #fcfdfe; }
.name { font-weight: 500; color: #1e293b; }
.unit { font-size: 11px; color: #94a3b8; margin-left: 3px; font-weight: 400; }
td.num { text-align: right; }
td.center { text-align: center; }
input.cell {
width: 100%;
max-width: 110px;
border: 1px solid #e2e8f0;
border-radius: 6px;
padding: 5px 8px;
font-size: 13px;
text-align: right;
color: #1e293b;
outline: none;
background: #fff;
font-variant-numeric: tabular-nums;
}
input.cell:focus { border-color: #10b981; box-shadow: 0 0 0 2px rgba(16,185,129,0.12); }
input.cell.target { background: #f8fafc; color: #475569; font-weight: 600; }
.rate { font-variant-numeric: tabular-nums; font-weight: 600; color: #334155; }
.rate.dim { color: #cbd5e1; font-weight: 400; }
.badge {
display: inline-block;
min-width: 52px;
padding: 3px 10px;
border-radius: 999px;
font-size: 12px;
font-weight: 600;
text-align: center;
}
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.high { background: #fef3c7; color: #b45309; }
.badge.low { background: #e0f2fe; color: #0369a1; }
.badge.bad { background: #ffe4e6; color: #be123c; }
.badge.na { background: #f1f5f9; color: #94a3b8; font-weight: 400; }
.summary {
margin-top: 18px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 10px;
}
.stat {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 10px 12px;
}
.stat .k { font-size: 11px; color: #64748b; margin-bottom: 3px; }
.stat .v { font-size: 19px; font-weight: 700; color: #1e293b; }
.stat .v small { font-size: 12px; font-weight: 400; color: #94a3b8; }
.legend {
margin-top: 16px;
font-size: 11px;
color: #64748b;
line-height: 1.9;
}
.legend b { color: #475569; }
.actions {
margin-top: 20px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.actions button {
padding: 9px 18px;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
border: 1px solid #e2e8f0;
background: #fff;
color: #475569;
transition: all .15s;
}
.actions button:hover { background: #f8fafc; }
.actions button.primary {
background: #10b981;
border-color: #10b981;
color: #fff;
}
.actions button.primary:hover { background: #059669; }
@media print {
body { background: #fff; padding: 0; }
.page { box-shadow: none; border-radius: 0; padding: 0; max-width: 100%; }
.actions { display: none; }
input.cell { border-color: #cbd5e1; }
thead th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
tbody tr:nth-child(even) { background: #fcfdfe !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
</style>
</head>
<body>
<div class="page">
<h1>每日营养摄入检验表</h1>
<p class="sub">
检验方式:连续 3 天记录每日实际摄入,取算术平均值 | 判定标准:<b>达成率在目标值 ±10% 以内为合格</b><br>
达成率 = 实际值 ÷ 目标值 × 100%
</p>
<div class="meta">
<div><label>姓名</label><input value="张老师"></div>
<div><label>性别</label><input value="男"></div>
<div><label>年龄</label><input value="16 岁"></div>
<div><label>身高</label><input value="175 cm"></div>
<div><label>体重</label><input value="55 kg"></div>
<div><label>BMI</label><input value="17.96"></div>
<div><label>日常活动量</label><input value="约 10000 步"></div>
<div><label>营养目标</label><input value="健康增重"></div>
</div>
<table>
<thead>
<tr>
<th style="width:22%">检验项目</th>
<th class="num" style="width:18%">目标值</th>
<th class="num" style="width:22%">实际值(3天均值)</th>
<th class="num" style="width:16%">达成率</th>
<th class="center" style="width:22%">判定</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
<div class="summary">
<div class="stat"><div class="k">已检验项</div><div class="v"><span id="s-total">0</span><small> / 15 项</small></div></div>
<div class="stat"><div class="k">合格项</div><div class="v" style="color:#15803d"><span id="s-ok">0</span><small> 项</small></div></div>
<div class="stat"><div class="k">偏高项</div><div class="v" style="color:#b45309"><span id="s-high">0</span><small> 项</small></div></div>
<div class="stat"><div class="k">偏低项</div><div class="v" style="color:#0369a1"><span id="s-low">0</span><small> 项</small></div></div>
<div class="stat"><div class="k">合格率</div><div class="v"><span id="s-rate">—</span></div></div>
</div>
<div class="legend">
<b>判定规则:</b>达成率 90%–110% → <span class="badge ok">合格</span>;
达成率 &gt;110% → <span class="badge high">偏高</span>;
达成率 &lt;90% → <span class="badge low">偏低</span>。<br>
<b>钠</b>为上限指标,不超过目标的 110% 即判合格,超过则判 <span class="badge bad">超标</span>。
</div>
<div class="actions">
<button class="primary" onclick="window.print()">打印 / 导出 PDF</button>
<button onclick="fillDemo()">填入示例数据</button>
<button onclick="clearAll()">清空实际值</button>
</div>
</div>
<script>
const ROWS = [
{ name: '总热量', unit: 'kcal', target: 2960 },
{ name: '蛋白质', unit: 'g', target: 99 },
{ name: '脂肪', unit: 'g', target: 100 },
{ name: '碳水化合物', unit: 'g', target: 415 },
{ name: '膳食纤维', unit: 'g', target: 27 },
{ name: '钙', unit: 'mg', target: 1200 },
{ name: '铁', unit: 'mg', target: 12 },
{ name: '锌', unit: 'mg', target: 12 },
{ name: '镁', unit: 'mg', target: 400 },
{ name: '维生素 A', unit: 'µg', target: 900 },
{ name: '维生素 C', unit: 'mg', target: 100 },
{ name: '维生素 B1', unit: 'mg', target: 1.4 },
{ name: '维生素 B2', unit: 'mg', target: 1.5 },
{ name: '钠(上限)', unit: 'mg', target: 2000, limit: true },
{ name: '饮水量', unit: 'ml', target: 2925 },
];
const tbody = document.getElementById('tbody');
function buildTable() {
tbody.innerHTML = ROWS.map((row, i) => `
<tr>
<td class="name">${i + 1}. ${row.name}</td>
<td class="num">
<input class="cell target" type="number" step="any" data-i="${i}" data-role="target" value="${row.target}">
<span class="unit">${row.unit}</span>
</td>
<td class="num">
<input class="cell" type="number" step="any" data-i="${i}" data-role="actual" placeholder="—">
<span class="unit">${row.unit}</span>
</td>
<td class="num"><span class="rate dim" id="rate-${i}">—</span></td>
<td class="center"><span class="badge na" id="judge-${i}">未录入</span></td>
</tr>
`).join('');
tbody.addEventListener('input', (e) => {
if (e.target.classList.contains('cell')) recalc();
});
recalc();
}
function judge(ratio, limit) {
if (limit) {
return ratio <= 1.1
? { text: '合格', cls: 'ok' }
: { text: '超标', cls: 'bad' };
}
if (ratio > 1.1) return { text: '偏高', cls: 'high' };
if (ratio < 0.9) return { text: '偏低', cls: 'low' };
return { text: '合格', cls: 'ok' };
}
function recalc() {
let ok = 0, high = 0, low = 0, filled = 0;
ROWS.forEach((row, i) => {
const tEl = document.querySelector(`input[data-role="target"][data-i="${i}"]`);
const aEl = document.querySelector(`input[data-role="actual"][data-i="${i}"]`);
const rEl = document.getElementById(`rate-${i}`);
const jEl = document.getElementById(`judge-${i}`);
const target = parseFloat(tEl.value);
const actual = parseFloat(aEl.value);
if (!isFinite(actual) || aEl.value.trim() === '') {
rEl.textContent = '—';
rEl.className = 'rate dim';
jEl.textContent = '未录入';
jEl.className = 'badge na';
return;
}
filled++;
const ratio = isFinite(target) && target > 0 ? actual / target : 0;
rEl.textContent = (ratio * 100).toFixed(1) + '%';
rEl.className = 'rate';
const v = judge(ratio, row.limit);
jEl.textContent = v.text;
jEl.className = 'badge ' + v.cls;
if (v.cls === 'ok') ok++;
else if (v.cls === 'high' || v.cls === 'bad') high++;
else if (v.cls === 'low') low++;
});
document.getElementById('s-total').textContent = filled;
document.getElementById('s-ok').textContent = ok;
document.getElementById('s-high').textContent = high;
document.getElementById('s-low').textContent = low;
document.getElementById('s-rate').textContent =
filled > 0 ? ((ok / filled) * 100).toFixed(0) + '%' : '—';
}
function fillDemo() {
// 示例:连续 3 天实际摄入均值(高油、膳食纤维与维 C 不足的典型情况)
const demo = [3050, 106, 128, 392, 11, 780, 9.4, 9.1, 310, 640, 22, 1.1, 1.2, 2450, 2100];
ROWS.forEach((row, i) => {
const aEl = document.querySelector(`input[data-role="actual"][data-i="${i}"]`);
aEl.value = demo[i];
});
recalc();
}
function clearAll() {
ROWS.forEach((row, i) => {
document.querySelector(`input[data-role="actual"][data-i="${i}"]`).value = '';
});
recalc();
}
buildTable();
</script>
</body>
</html>