From 92486cad8e2fe561e64ba9519a1ff87fb2173e50 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 28 Apr 2026 09:08:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E4=BB=AA?= =?UTF-8?q?=E8=A1=A8=E7=9B=98=20hooks=20=E9=A1=BA=E5=BA=8F=20+=20=E6=82=A3?= =?UTF-8?q?=E8=80=85=20DatePicker=20=E5=88=9D=E5=A7=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AdminDashboard/OperatorDashboard/DoctorDashboard/NurseDashboard: 将 useCountUp 调用从 JSX 中提取到组件顶层,避免条件提前返回 导致 hooks 数量不一致引发 React crash - PatientList: 编辑时 birth_date 字符串转 dayjs 对象,修复 Ant Design 6 DatePicker getUDayjs().isValid() 报错 --- apps/web/src/pages/health/PatientList.tsx | 3 ++- .../pages/health/StatisticsDashboard/AdminDashboard.tsx | 9 ++++++--- .../pages/health/StatisticsDashboard/DoctorDashboard.tsx | 6 ++++-- .../pages/health/StatisticsDashboard/NurseDashboard.tsx | 6 ++++-- .../health/StatisticsDashboard/OperatorDashboard.tsx | 9 ++++++--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/apps/web/src/pages/health/PatientList.tsx b/apps/web/src/pages/health/PatientList.tsx index ac3a6bc..a95eb02 100644 --- a/apps/web/src/pages/health/PatientList.tsx +++ b/apps/web/src/pages/health/PatientList.tsx @@ -30,6 +30,7 @@ import { PageContainer } from '../../components/PageContainer'; import { DrawerForm } from '../../components/DrawerForm'; import { usePaginatedData } from '../../hooks/usePaginatedData'; import { calcAge, formatDateTime } from '../../utils/format'; +import { dayjs } from '../../utils/dayjs'; /** 筛选器结构 */ interface PatientFilters { @@ -392,7 +393,7 @@ export default function PatientList() { ? { name: editingPatient.name, gender: editingPatient.gender, - birth_date: editingPatient.birth_date, + birth_date: editingPatient.birth_date ? dayjs(editingPatient.birth_date) : undefined, blood_type: editingPatient.blood_type, id_number: editingPatient.id_number, allergy_history: editingPatient.allergy_history, diff --git a/apps/web/src/pages/health/StatisticsDashboard/AdminDashboard.tsx b/apps/web/src/pages/health/StatisticsDashboard/AdminDashboard.tsx index ab5ecc8..df1ffa1 100644 --- a/apps/web/src/pages/health/StatisticsDashboard/AdminDashboard.tsx +++ b/apps/web/src/pages/health/StatisticsDashboard/AdminDashboard.tsx @@ -12,6 +12,9 @@ import HealthDataCenter from './HealthDataCenter'; export function AdminDashboard() { const { patientStats, followUpStats, healthDataStats, loading } = useStatsData(); + const patientCount = useCountUp(patientStats?.total_patients ?? 0); + const appointmentCount = useCountUp(healthDataStats?.appointments?.this_month ?? 0); + const doctorCount = useCountUp(0); if (loading && !patientStats) return ; @@ -27,12 +30,12 @@ export function AdminDashboard() { - } /> + } /> - } /> + } /> @@ -59,7 +62,7 @@ export function AdminDashboard() { - } /> + } /> diff --git a/apps/web/src/pages/health/StatisticsDashboard/DoctorDashboard.tsx b/apps/web/src/pages/health/StatisticsDashboard/DoctorDashboard.tsx index b013abc..654a82c 100644 --- a/apps/web/src/pages/health/StatisticsDashboard/DoctorDashboard.tsx +++ b/apps/web/src/pages/health/StatisticsDashboard/DoctorDashboard.tsx @@ -15,6 +15,8 @@ export function DoctorDashboard() { const [personal, setPersonal] = useState(null); const [loading, setLoading] = useState(true); const { consultationStats } = useStatsData(); + const myPatientsCount = useCountUp(personal?.my_patients ?? 0); + const consultationsCount = useCountUp(personal?.consultations_this_month ?? 0); const fetchPersonal = useCallback(async () => { try { @@ -66,7 +68,7 @@ export function DoctorDashboard() { } suffix={p && p.new_patients_this_month > 0 ? ( @@ -92,7 +94,7 @@ export function DoctorDashboard() { } suffix={p && p.pending_consultations > 0 ? ( diff --git a/apps/web/src/pages/health/StatisticsDashboard/NurseDashboard.tsx b/apps/web/src/pages/health/StatisticsDashboard/NurseDashboard.tsx index a4aa81c..13abf61 100644 --- a/apps/web/src/pages/health/StatisticsDashboard/NurseDashboard.tsx +++ b/apps/web/src/pages/health/StatisticsDashboard/NurseDashboard.tsx @@ -12,6 +12,8 @@ import { useCountUp } from '../../../hooks/useCountUp'; export function NurseDashboard() { const [personal, setPersonal] = useState(null); const [loading, setLoading] = useState(true); + const appointmentCount = useCountUp(personal?.today_appointments ?? 0); + const overdueCount = useCountUp(personal?.overdue_follow_ups ?? 0); const fetchPersonal = useCallback(async () => { try { @@ -97,7 +99,7 @@ export function NurseDashboard() { {/* 统计卡 */} - } /> + } /> @@ -113,7 +115,7 @@ export function NurseDashboard() { - } + } valueStyle={{ color: (p?.overdue_follow_ups ?? 0) > 0 ? '#cf1322' : undefined }} /> diff --git a/apps/web/src/pages/health/StatisticsDashboard/OperatorDashboard.tsx b/apps/web/src/pages/health/StatisticsDashboard/OperatorDashboard.tsx index 5687992..4ca271f 100644 --- a/apps/web/src/pages/health/StatisticsDashboard/OperatorDashboard.tsx +++ b/apps/web/src/pages/health/StatisticsDashboard/OperatorDashboard.tsx @@ -10,6 +10,9 @@ import { useCountUp } from '../../../hooks/useCountUp'; export function OperatorDashboard() { const { pointsStats, loading } = useStatsData(); + const issuedCount = useCountUp(pointsStats?.total_issued ?? 0); + const spentCount = useCountUp(pointsStats?.total_spent ?? 0); + const activeCount = useCountUp(pointsStats?.active_accounts ?? 0); if (loading && !pointsStats) return ; @@ -25,12 +28,12 @@ export function OperatorDashboard() { - } /> + } /> - } + } suffix={pointsStats ? ( 消费率{pointsStats.total_issued > 0 ? Math.round(pointsStats.total_spent / pointsStats.total_issued * 100) : 0}% @@ -41,7 +44,7 @@ export function OperatorDashboard() { - } /> + } />