import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Card } from '@/components/common/Card'; import { Empty } from '@/components/common/Empty'; import { Badge } from '@/components/common/Badge'; import { PageHeader } from '@/components/layout/PageHeader'; import { useAuth } from '@/hooks/useAuth'; import { useNotificationStore } from '@/stores/notification.store'; import * as healthService from '@/services/health.service'; import { MEASUREMENT_TYPES, HEALTH_TIPS } from '@/utils/constants'; import { getBPRiskLevel } from '@/utils/format'; import type { HealthStats } from '@/types'; import styles from './HomePage.module.css'; const QUICK_ACTIONS = [ { label: '测血压', icon: '💓', path: '/health/records?type=blood_pressure' }, { label: '记用药', icon: '💊', path: '/health/medications' }, { label: '在线问诊', icon: '👨‍⚕️', path: '/services/consultation' }, { label: '报告解读', icon: '📋', path: '/services/reports' }, { label: '健康日历', icon: '📅', path: '/health/calendar' }, { label: '运动饮食', icon: '🏃', path: '/health/exercise-diet' }, ]; export function HomePage() { const navigate = useNavigate(); const { user } = useAuth(); const { unreadCount, fetchNotifications } = useNotificationStore(); const [stats, setStats] = useState([]); const [tipIndex, setTipIndex] = useState(0); useEffect(() => { healthService.getLatestStats().then(setStats); fetchNotifications(); }, [fetchNotifications]); const bpStats = stats.find((s) => s.type === 'blood_pressure'); const hrStats = stats.find((s) => s.type === 'heart_rate'); const bpValue = bpStats?.latest?.value; const systolic = typeof bpValue === 'object' ? bpValue.systolic : null; const diastolic = typeof bpValue === 'object' ? bpValue.diastolic : null; const riskLevel = systolic && diastolic ? getBPRiskLevel(systolic, diastolic) : null; return (
navigate('/notifications')}> 🔔 {unreadCount > 0 && } } /> {/* Health Overview */} {bpStats?.latest && hrStats?.latest ? (
健康概览 最新记录
血压
{systolic} / {diastolic}
mmHg
心率 {Number(hrStats.latest.value)} bpm
) : ( )} {/* Quick Actions */}
{QUICK_ACTIONS.map((action) => ( ))}
{/* Health Tip */} setTipIndex((prev) => (prev + 1) % HEALTH_TIPS.length)} >
💡 健康小贴士 点击换一条

{HEALTH_TIPS[tipIndex]}

); }