From 862927c0a3ec2872a19f3569062f3aa12276c16e Mon Sep 17 00:00:00 2001 From: 15945162479 <15945162479@qq.com> Date: Sat, 13 Dec 2025 14:46:12 +0800 Subject: [PATCH] Add File --- src/elderly/components/MedicationCard.tsx | 116 ++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/elderly/components/MedicationCard.tsx diff --git a/src/elderly/components/MedicationCard.tsx b/src/elderly/components/MedicationCard.tsx new file mode 100644 index 0000000..aee68b3 --- /dev/null +++ b/src/elderly/components/MedicationCard.tsx @@ -0,0 +1,116 @@ +import React, { useState, useEffect } from 'react'; +import { CheckCircle, Clock, XCircle, Info } from 'lucide-react'; + +interface MedicationCardProps { + medicationName: string; + dosage: string; + timing: string; // 例如:"早餐后" 或 "睡前" + graceMinutes?: number; // 宽限期(分钟) + onTaken?: () => void; + onSnooze?: (minutes: number) => void; + onSkip?: () => void; + onInfo?: () => void; +} + +/** + * 用药提醒卡组件 + * 支持确认、稍后提醒、跳过等操作 + */ +export const MedicationCard: React.FC = ({ + medicationName, + dosage, + timing, + graceMinutes = 30, + onTaken, + onSnooze, + onSkip, + onInfo, +}) => { + const [countdown, setCountdown] = useState(graceMinutes * 60); + + useEffect(() => { + const timer = setInterval(() => { + setCountdown((prev) => (prev > 0 ? prev - 1 : 0)); + }, 1000); + + return () => clearInterval(timer); + }, []); + + const formatTime = (seconds: number) => { + const mins = Math.floor(seconds / 60); + const secs = seconds % 60; + return `${mins}:${secs.toString().padStart(2, '0')}`; + }; + + return ( +
+
+ {/* 标题与信息按钮 */} +
+

+ 早药时间到了 +

+ {onInfo && ( + + )} +
+ + {/* 药物信息 */} +
+

+ {medicationName} +

+

+ 剂量:{dosage} +

+

+ 服用时间:{timing} +

+
+ + {/* 倒计时 */} + {countdown > 0 && ( +
+ +

+ 宽限时间剩余:{formatTime(countdown)} +

+
+ )} + + {/* 操作按钮 - 纵向排列 */} +
+ + + + + +
+
+
+ ); +};