pulse-whoop / sleep.html
CSNET's picture
ช่วยแก้ JS และกราฟ ไม่ให้เพี้ยนที
9539581 verified
Raw History Blame Contribute Delete
12.4 kB
```html
<!DOCTYPE html>
<html lang="th" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>การนอน - ชีพจร</title>
<link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌿</text></svg>">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-900 text-white font-sans pb-20">
<!-- Main Container -->
<div class="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900">
<!-- Header -->
<header class="px-4 pt-12 pb-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-2xl font-bold bg-gradient-to-r from-blue-400 to-indigo-500 bg-clip-text text-transparent">
การนอนหลับ
</h1>
<p class="text-gray-400 text-sm mt-1">วิเคราะห์คุณภาพการนอนของคุณ 🌙</p>
</div>
<button onclick="window.location.href='index.html'" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center">
<i data-feather="arrow-left" class="w-5 h-5"></i>
</button>
</div>
</header>
<!-- Sleep Score -->
<section class="px-4 mb-6">
<div class="glass-card rounded-2xl p-6 border border-gray-700/50 text-center">
<div class="w-24 h-24 mx-auto mb-4 relative">
<vital-circle
type="sleep"
value="78"
color="from-blue-400 to-indigo-500"
label="คะแนนการนอน">
</vital-circle>
</div>
<p class="text-gray-400 text-sm">คุณภาพการนอนอยู่ในระดับดี</p>
<p class="text-xs text-gray-500 mt-1">อัพเดทล่าสุด: 07:00 น.</p>
</div>
</section>
<!-- Sleep Stages Chart -->
<section class="px-4 mb-6">
<div class="glass-card rounded-2xl p-5 border border-gray-700/50">
<h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
<i data-feather="bar-chart-2" class="w-5 h-5 text-blue-400"></i>
ระยะการนอนเมื่อคืน
</h3>
<canvas id="sleepStagesChart" height="200"></canvas>
<div class="grid grid-cols-3 gap-3 mt-4 text-center">
<div>
<p class="text-xs text-gray-400">ลึก</p>
<p class="text-lg font-bold text-blue-400">2.5 ชม.</p>
</div>
<div>
<p class="text-xs text-gray-400">REM</p>
<p class="text-lg font-bold text-purple-400">1.8 ชม.</p>
</div>
<div>
<p class="text-xs text-gray-400">ตื้น</p>
<p class="text-lg font-bold text-gray-400">3.2 ชม.</p>
</div>
</div>
</div>
</section>
<!-- Sleep Trends -->
<section class="px-4 mb-6">
<div class="glass-card rounded-2xl p-5 border border-gray-700/50">
<h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
<i data-feather="trending-up" class="w-5 h-5 text-green-400"></i>
เทรนด์การนอน 7 วัน
</h3>
<canvas id="sleepTrendChart" height="120"></canvas>
</div>
</section>
<!-- Sleep Insights -->
<section class="px-4 mb-6">
<div class="glass-card rounded-2xl p-5 border border-gray-700/50">
<h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
<i data-feather="lightbulb" class="w-5 h-5 text-yellow-400"></i>
ข้อมูลเชิงลึก
</h3>
<div class="space-y-3">
<div class="p-3 bg-blue-500/10 border border-blue-500/30 rounded-xl">
<div class="flex items-center gap-3">
<div class="w-8 h-8 bg-blue-500 rounded-lg flex items-center justify-center">
<i data-feather="clock" class="w-4 h-4 text-white"></i>
</div>
<div class="flex-1">
<p class="text-sm font-medium">เวลานอนสม่ำเสมอ</p>
<p class="text-xs text-gray-400">คุณนอนตรงเวลา 6 จาก 7 วันล่าสุด</p>
</div>
<span class="text-xs text-green-400">ดีมาก</span>
</div>
</div>
<div class="p-3 bg-orange-500/10 border border-orange-500/30 rounded-xl">
<div class="flex items-center gap-3">
<div class="w-8 h-8 bg-orange-500 rounded-lg flex items-center justify-center">
<i data-feather="coffee" class="w-4 h-4 text-white"></i>
</div>
<div class="flex-1">
<p class="text-sm font-medium">คาเฟอีนก่อนนอน</p>
<p class="text-xs text-gray-400">พบว่าดื่มกาแฟหลัง 15:00 วันนี้</p>
</div>
<span class="text-xs text-orange-400">ควรหลีกเลี่ยง</span>
</div>
</div>
</div>
</div>
</section>
<!-- Bedtime Routine -->
<section class="px-4 mb-6">
<div class="glass-card rounded-2xl p-5 border border-gray-700/50">
<h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
<i data-feather="moon" class="w-5 h-5 text-indigo-400"></i>
กิจวัตรก่อนนอน
</h3>
<div class="space-y-2">
<label class="flex items-center gap-3 p-2 rounded-lg hover:bg-gray-800/30">
<input type="checkbox" class="w-4 h-4 text-blue-600 rounded">
<span class="text-sm">งดหน้าจอ 1 ชม. ก่อนนอน</span>
</label>
<label class="flex items-center gap-3 p-2 rounded-lg hover:bg-gray-800/30">
<input type="checkbox" class="w-4 h-4 text-blue-600 rounded">
<span class="text-sm">ดื่มนมอุ่น</span>
</label>
<label class="flex items-center gap-3 p-2 rounded-lg hover:bg-gray-800/30">
<input type="checkbox" class="w-4 h-4 text-blue-600 rounded">
<span class="text-sm">อ่านหนังสือ 15 นาที</span>
</label>
<label class="flex items-center gap-3 p-2 rounded-lg hover:bg-gray-800/30">
<input type="checkbox" class="w-4 h-4 text-blue-600 rounded">
<span class="text-sm">ฝึกสมาธิ 5 นาที</span>
</label>
</div>
</div>
</section>
</div>
<!-- Bottom Navigation -->
<main-navbar></main-navbar>
<!-- Scripts -->
<script src="components/navbar.js"></script>
<script src="components/vital-circle.js"></script>
<script src="script.js"></script>
<script>
// Initialize sleep charts
document.addEventListener('DOMContentLoaded', function() {
// Sleep Stages Chart
const stagesCtx = document.getElementById('sleepStagesChart');
if (stagesCtx) {
new Chart(stagesCtx, {
type: 'doughnut',
data: {
labels: ['หลับลึก', 'หลับ REM', 'หลับตื้น', 'ตื่น'],
datasets: [{
data: [25, 22, 45, 8],
backgroundColor: [
'#3b82f6',
'#a855f7',
'#9ca3af',
'#ef4444'
],
borderWidth: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
padding: 15,
font: { size: 12, family: 'Prompt' },
color: '#e5e7eb'
}
}
}
}
});
}
// Sleep Trend Chart
const trendCtx = document.getElementById('sleepTrendChart');
if (trendCtx) {
new Chart(trendCtx, {
type: 'line',
data: {
labels: ['จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส', 'อา'],
datasets: [{
label: 'ชั่วโมงการนอน',
data: [7.5, 6.8, 8.2, 7.1, 7.8, 8.5, 7.2],
borderColor: '#60a5fa',
backgroundColor: 'rgba(96, 165, 250, 0.1)',
tension: 0.4,
fill: true,
pointRadius: 4,
pointBackgroundColor: '#60a5fa'
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false }
},
scales: {
y: {
beginAtZero: true,
max: 10,
ticks: {
color: '#9ca3af'
},
grid: {
color: 'rgba(75, 85, 99, 0.3)'
}
},
x: {
ticks: {
color: '#9ca3af'
},
grid: {
display: false
}
}
}
}
});
}
// Set active page in navbar
const navbar = document.querySelector('main-navbar');
if (navbar) {
navbar.setActivePage('sleep');
}
// Save to localStorage
localStorage.setItem('lastSleepView', new Date().toISOString());
});
</script>
<script>feather.replace();</script>
</body>
</html>
>>>>>>> REPLACE