diff --git a/src/vitals/web/app.py b/src/vitals/web/app.py
index b30d91a..25694de 100644
--- a/src/vitals/web/app.py
+++ b/src/vitals/web/app.py
@@ -6374,6 +6374,19 @@ def get_sleep_page_html() -> str:
+
+
近 30 天睡眠时长趋势
@@ -6504,6 +6517,9 @@ def get_sleep_page_html() -> str:
backgroundColor: 'rgba(109, 40, 217, 0.2)',
fill: true,
tension: 0.3,
+ pointBackgroundColor: durationData.map(d =>
+ d >= 7 && d <= 9 ? '#10B981' : d < 6 ? '#EF4444' : '#F59E0B'
+ ),
}]
},
options: { responsive: true, scales: { y: { beginAtZero: true } } }
@@ -6572,6 +6588,105 @@ def get_sleep_page_html() -> str:
}
}
+ async function loadSleepAssessment() {
+ try {
+ const res = await fetch('/api/sleep/assessment');
+ const data = await res.json();
+
+ // Render assessment card
+ const assessmentContainer = document.getElementById('sleep-assessment-content');
+ const statusColor = data.status.color;
+ const avgPercent = Math.min(Math.max((data.avg_duration - 4) / 6 * 100, 0), 100);
+
+ assessmentContainer.innerHTML = `
+
+
近 7 天平均睡眠
+
${data.avg_duration} 小时
+
+
+
+
+
+
+
偏少 <5h
+
不足 5-6h
+
理想 7-9h
+
过多 >9h
+
+
+
+
+
+ ${data.status.label}
+ ${data.gap_hours > 0 ? `距理想还差 ${data.gap_hours} 小时/天` : ''}
+
+
+ 本周: 理想 ${data.ideal_days_count}/${data.total_days} 天
+
+
+ `;
+
+ // Render impact card
+ const impactCard = document.getElementById('sleep-impact-card');
+ const impactContainer = document.getElementById('sleep-impact-content');
+
+ const isWarning = data.status.level === 'severe' || data.status.level === 'insufficient';
+ const bgColor = isWarning ? 'rgba(127, 29, 29, 0.2)' : 'rgba(6, 95, 70, 0.2)';
+ const borderColor = isWarning ? 'rgba(239, 68, 68, 0.3)' : 'rgba(16, 185, 129, 0.3)';
+ const titleColor = isWarning ? '#F87171' : '#34D399';
+ const title = isWarning ? '睡眠不足警告' : '睡眠状态良好';
+ const intro = isWarning
+ ? `您近 7 天平均睡眠仅 ${data.avg_duration} 小时,低于健康标准 7 小时。长期睡眠不足会对身体造成以下影响:`
+ : `您近 7 天平均睡眠 ${data.avg_duration} 小时,处于健康范围内!充足睡眠为您带来以下益处:`;
+
+ impactCard.style.display = 'block';
+ impactCard.style.background = bgColor;
+ impactCard.style.border = `1px solid ${borderColor}`;
+
+ const impacts = data.health_impacts;
+ let impactHtml = `
+
${title}
+
${intro}
+
+
+ `;
+
+ Object.values(impacts).forEach(impact => {
+ impactHtml += `
+
+
${impact.title}
+
+ `;
+ impact.effects.forEach(e => {
+ impactHtml += `- ${e}
`;
+ });
+ impactHtml += `
+
+
+ `;
+ });
+
+ impactHtml += `
+
+
+ ${data.suggestion}
+
+ `;
+
+ impactContainer.innerHTML = impactHtml;
+ } catch (e) {
+ console.error('加载睡眠评估失败:', e);
+ document.getElementById('sleep-assessment-content').innerHTML = '
加载失败
';
+ }
+ }
+
async function deleteSleep(id) {
if (!confirm('确定要删除这条睡眠记录吗?')) return;
try {
@@ -6615,6 +6730,7 @@ def get_sleep_page_html() -> str:
document.getElementById('addSleepForm').addEventListener('submit', submitSleepForm);
loadSleepData();
+ loadSleepAssessment();
// 检查管理员状态
const user = JSON.parse(localStorage.getItem('user') || '{}');