diff --git a/src/family/main.tsx b/src/family/main.tsx new file mode 100644 index 0000000..3d6a93b --- /dev/null +++ b/src/family/main.tsx @@ -0,0 +1,241 @@ +import React, { useState, useEffect } from 'react'; +import ReactDOM from 'react-dom/client'; +import { Dashboard } from './pages/Dashboard'; +import { MediaLibrary } from './pages/MediaLibrary'; +import { CarePlan } from './pages/CarePlan'; +import { AlertsAndCare } from './pages/AlertsAndCare'; +import { InteractionHistory } from './pages/InteractionHistory'; +import { FamilyMessages } from './pages/FamilyMessages'; +import { MoodHistory } from './pages/MoodHistory'; +import { ElderProfile } from './components/ElderProfile'; +import { EmergencyAlert } from './components/EmergencyAlert'; +import * as messageService from './services/messageService'; +import { + LayoutDashboard, + MessageSquare, + HeartPulse, + Bell, + MessageCircle, + Image, + Smile, +} from 'lucide-react'; +import '../index.css'; + +type Page = 'dashboard' | 'messages' | 'care' | 'alerts' | 'interaction' | 'media' | 'mood'; + +/** + * 家属端应用 + * 优化为手机浏览器使用 - 底部标签栏导航 + */ +function FamilyApp() { + const [currentPage, setCurrentPage] = useState('dashboard'); + const [showElderProfile, setShowElderProfile] = useState(false); + const [unhandledCount, setUnhandledCount] = useState(0); + const [emergencyAlert, setEmergencyAlert] = useState<{ + id: number; + message: string; + timestamp: string; + } | null>(null); + const [shownEmergencyIds, setShownEmergencyIds] = useState>(new Set()); + const familyId = 'family_001'; // 实际使用时从用户上下文获取 + + // 老人信息数据 + const [elderInfo, setElderInfo] = useState({ + name: '张奶奶', + age: 82, + cognitive_status: 'mild' as const, + hearing_vision: { + hearing: 'mild_loss' as const, + vision: 'ok' as const, + }, + preferences: { + music: ['老歌', '评弹', '京剧'], + avoid_topics: ['医院', '去世的老伴'], + }, + }); + + // 加载未处理通知数量 + const loadUnhandledCount = async () => { + try { + const stats = await messageService.getAlertStats(familyId); + setUnhandledCount(stats.status_stats?.unhandled || 0); + } catch (error) { + console.error('加载未处理通知数量失败:', error); + } + }; + + // 检查是否有新的SOS紧急通知 + const checkEmergencyAlerts = async () => { + try { + const { alerts } = await messageService.getFamilyAlerts(familyId, { + alert_type: 'sos_emergency', + handled: false, + limit: 1, + }); + + if (alerts.length > 0) { + const latestAlert = alerts[0]; + // 只显示未展示过的紧急通知 + if (!shownEmergencyIds.has(latestAlert.id)) { + setEmergencyAlert({ + id: latestAlert.id, + message: latestAlert.message, + timestamp: new Date(latestAlert.created_at).toLocaleString('zh-CN', { + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + }), + }); + // 记录已显示的通知ID + setShownEmergencyIds(prev => new Set(prev).add(latestAlert.id)); + } + } + } catch (error) { + console.error('检查紧急通知失败:', error); + } + }; + + // 定时检查未处理通知和紧急通知 + useEffect(() => { + loadUnhandledCount(); + checkEmergencyAlerts(); + // 每5秒检查一次 + const interval = setInterval(() => { + loadUnhandledCount(); + checkEmergencyAlerts(); + }, 5000); + return () => clearInterval(interval); + }, []); + + // 保存老人信息 + const handleSaveElderInfo = (updatedInfo: any) => { + setElderInfo(updatedInfo); + // TODO: 这里可以添加API调用,将数据保存到后端 + console.log('保存老人信息:', updatedInfo); + }; + + const navigation = [ + { id: 'dashboard' as const, label: '概览', shortLabel: '概览', icon: LayoutDashboard }, + { id: 'messages' as const, label: '家属留言', shortLabel: '留言', icon: MessageSquare }, + { id: 'media' as const, label: '媒体库', shortLabel: '媒体', icon: Image }, + { id: 'care' as const, label: '护理计划', shortLabel: '护理', icon: HeartPulse }, + { id: 'alerts' as const, label: '通知', shortLabel: '通知', icon: Bell }, + { id: 'interaction' as const, label: '交互记录', shortLabel: '交互', icon: MessageCircle }, + ]; + + const renderPage = () => { + switch (currentPage) { + case 'dashboard': + return ; + case 'messages': + return ; + case 'media': + return ; + case 'mood': + return ; + case 'care': + return ; + case 'alerts': + return ; + case 'interaction': + return ; + default: + return ; + } + }; + + return ( +
+ {/* 顶部标题栏 - 手机优化 */} +
+
+
+

KinEcho

+ 亲情回声 +
+

+ Bring family moments to life. / 把家人的声音带到眼前。 +

+
+ +
+ + {/* 主要内容区 - 可滚动 */} +
{renderPage()}
+ + {/* 底部标签栏导航 - 手机原生风格 */} + + + {/* 老人信息弹窗 */} + {showElderProfile && ( + setShowElderProfile(false)} + onSave={handleSaveElderInfo} + /> + )} + + {/* 紧急通知弹窗 */} + {emergencyAlert && ( + { + // 标记为已处理 + await messageService.handleAlert(emergencyAlert.id); + // 关闭弹窗 + setEmergencyAlert(null); + // 跳转到通知页面 + setCurrentPage('alerts'); + // 刷新未处理数量 + loadUnhandledCount(); + }} + /> + )} +
+ ); +} + +ReactDOM.createRoot(document.getElementById('root')!).render( + + + +);