import React, { useState, useEffect } from 'react';
import {
Baby,
Utensils,
Milk,
Droplets,
Pill,
Syringe,
Ruler,
Weight,
Clock,
Calendar,
ChevronRight,
Plus,
Bell,
CheckCircle2,
AlertCircle,
X,
History,
Home,
LineChart,
Download // 新增图标
} from 'lucide-react';
// --- 模拟数据与常量 ---
const ACTION_TYPES = [
{ id: 'milk', label: '喝奶', icon: Milk, color: 'bg-blue-100 text-blue-500', unit: 'ml' },
{ id: 'food', label: '吃饭', icon: Utensils, color: 'bg-orange-100 text-orange-500', unit: 'g' },
{ id: 'water', label: '喝水', icon: Droplets, color: 'bg-cyan-100 text-cyan-500', unit: 'ml' },
{ id: 'poop', label: '便便', icon: Baby, color: 'bg-yellow-100 text-yellow-600', unit: '次' },
{ id: 'medicine', label: '喝药', icon: Pill, color: 'bg-red-100 text-red-500', unit: '次' },
];
const VACCINE_SCHEDULE = [
{ month: 0, name: '乙肝疫苗 (第一针)', completed: true },
{ month: 0, name: '卡介苗', completed: true },
{ month: 1, name: '乙肝疫苗 (第二针)', completed: false },
{ month: 2, name: '脊灰疫苗 (第一针)', completed: false },
{ month: 3, name: '百白破 (第一针)', completed: false },
{ month: 6, name: '乙肝疫苗 (第三针)', completed: false },
];
// --- 组件部分 ---
// 1. 顶部宝宝信息卡片
const BabyHeader = ({ babyInfo }) => {
const [ageDisplay, setAgeDisplay] = useState('');
useEffect(() => {
const calculateAge = () => {
const birth = new Date(babyInfo.birthDate);
const now = new Date();
const diffTime = Math.abs(now - birth);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// 简单计算月龄
const months = Math.floor(diffDays / 30);
const days = diffDays % 30;
setAgeDisplay(`${months}个月 ${days}天`);
};
calculateAge();
}, [babyInfo]);
return (
{/* 这里可以使用上传的图片,暂时用Icon代替 */}
{babyInfo.name}
来到世界: {ageDisplay}
);
};
// 2. 快捷记录网格
const QuickActionGrid = ({ onLogAction }) => {
return (
{ACTION_TYPES.map((action) => (
))}
{/* 这是一个自定义打卡按钮 */}
);
};
// 3. 今日动态列表
const ActivityFeed = ({ logs }) => {
// 只显示今天的
const todayLogs = logs.filter(log => {
const today = new Date().toDateString();
return new Date(log.timestamp).toDateString() === today;
}).sort((a, b) => b.timestamp - a.timestamp); // 倒序
return (
今日动态
共 {todayLogs.length} 条记录
{todayLogs.length === 0 ? (
) : (
{todayLogs.map((log) => {
const actionDef = ACTION_TYPES.find(a => a.id === log.type) || ACTION_TYPES[0];
const timeStr = new Date(log.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return (
{actionDef.label}
{timeStr}
{log.value ? `${log.value}${actionDef.unit}` : '已打卡'}
);
})}
)}
);
};
// 4. 生长记录 & 疫苗
const GrowthAndVaccine = ({ growthData, vaccines }) => {
return (
{/* 身高体重卡片 */}
生长发育
身高
{growthData.height} cm
体重
{growthData.weight} kg
{/* 疫苗卡片 */}
疫苗提醒
本月待接种: 1
{vaccines.map((vac, index) => (
{vac.completed ? (
) : (
)}
{vac.name}
{vac.month}月龄
))}
);
};
// 5. 弹窗组件
const ReminderModal = ({ isOpen, onClose, onConfirm }) => {
if (!isOpen) return null;
return (
宝宝起床了吗?
距离上次记录已经过去很长时间啦。如果宝宝醒了,记得给TA喂点水或者换个尿布哦!
);
};
// 主应用组件
const BabyApp = () => {
const [activeTab, setActiveTab] = useState('home');
const [showWakeupModal, setShowWakeupModal] = useState(false);
// 模拟数据 State
const [babyInfo] = useState({
name: "糯米团子",
birthDate: "2023-11-15",
gender: "female"
});
const [growthData] = useState({
height: 65.5,
weight: 7.2
});
const [logs, setLogs] = useState([
{ id: 1, type: 'milk', value: 120, timestamp: Date.now() - 1000 * 60 * 60 * 2 }, // 2小时前
{ id: 2, type: 'poop', value: 1, timestamp: Date.now() - 1000 * 60 * 60 * 5 }, // 5小时前
]);
// 检查是否需要弹窗提醒 (模拟逻辑:如果上次操作超过4小时,或者为了演示,页面加载时随机触发)
useEffect(() => {
const checkInactivity = () => {
const lastActivityTime = logs.length > 0 ? logs[0].timestamp : 0;
const now = Date.now();
const fourHours = 4 * 60 * 60 * 1000;
// 为了方便演示,这里我们假设如果最后一条记录超过4小时,就弹窗
// 在真实场景中,这会在用户重新打开App时触发
if (now - lastActivityTime > fourHours) {
setShowWakeupModal(true);
}
};
// 延迟1秒检查,模拟App启动过程
const timer = setTimeout(checkInactivity, 1000);
return () => clearTimeout(timer);
}, [logs]);
// 记录操作
const handleLogAction = (actionDef) => {
const newValue = prompt(`请输入${actionDef.label}的数量 (${actionDef.unit})`, "1");
if (newValue) {
const newLog = {
id: Date.now(),
type: actionDef.id,
value: newValue,
timestamp: Date.now()
};
setLogs([newLog, ...logs]);
}
};
// 生成并下载 HTML 报表
const handleExportHtml = () => {
const htmlContent = `
${babyInfo.name} - 成长档案
基本信息
性别: ${babyInfo.gender === 'female' ? '女宝宝' : '男宝宝'}
出生日期: ${babyInfo.birthDate}
当前身高: ${growthData.height} cm
当前体重: ${growthData.weight} kg
📅 近期记录明细
| 时间 |
类型 |
详情 |
${logs.map(log => {
const action = ACTION_TYPES.find(a => a.id === log.type);
return `
| ${new Date(log.timestamp).toLocaleString()} |
${action?.label || log.type}
|
${log.value} ${action?.unit || ''} |
`;
}).join('')}
`;
const blob = new Blob([htmlContent], { type: 'text/html' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `${babyInfo.name}_成长档案_${new Date().toISOString().slice(0,10)}.html`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
return (
{/* 手机容器模拟 */}
{/* 顶部背景装饰 */}
{/* 主要内容区域 */}
{/* 顶部栏 */}
宝宝监护室
{activeTab === 'home' && (
<>
快速打卡
>
)}
{activeTab === 'growth' && (
健康档案
)}
{activeTab === 'profile' && (
设置与账号
当前版本 v1.0.0
)}
{/* 底部导航栏 */}
setActiveTab('home')}
icon={Home}
label="首页"
/>
setActiveTab('growth')}
icon={LineChart}
label="成长"
/>
setActiveTab('profile')}
icon={Baby}
label="我的"
/>
{/* 弹窗 */}
setShowWakeupModal(false)}
onConfirm={() => {
setShowWakeupModal(false);
// 这里可以自动触发一个 'wake up' 的记录或者只是关闭
}}
/>
);
};
// 底部导航按钮组件
const NavButton = ({ active, onClick, icon: Icon, label }) => (
);
export default BabyApp;