import { useState, useEffect } from 'react'; import { View, Text, Input, ScrollView } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { useAuthStore } from '@/stores/auth'; import * as doctorApi from '@/services/doctor'; import Loading from '@/components/Loading'; import './index.scss'; interface CardConfig { key: keyof doctorApi.DoctorDashboard; label: string; initial: string; route: string; } const CARDS: CardConfig[] = [ { key: 'total_patients', label: '我的患者', initial: '患', route: '/pages/doctor/patients/index' }, { key: 'unread_messages', label: '未读消息', initial: '消', route: '/pages/doctor/consultation/index' }, { key: 'pending_follow_ups', label: '待处理随访', initial: '随', route: '/pages/doctor/followup/index' }, { key: 'today_consultations', label: '今日咨询', initial: '诊', route: '/pages/doctor/consultation/index' }, ]; const HEALTH_CARDS: CardConfig[] = [ { key: 'pending_dialysis_review', label: '待审透析', initial: '透', route: '/pages/doctor/patients/index' }, { key: 'pending_lab_review', label: '待审化验', initial: '化', route: '/pages/doctor/report/index' }, { key: 'today_appointments', label: '今日预约', initial: '约', route: '/pages/doctor/patients/index' }, ]; const QUICK_ACTIONS = [ { label: '化验审核', initial: '审', route: '/pages/doctor/report/index' }, { label: '患者查询', initial: '查', route: '/pages/doctor/patients/index' }, { label: '随访记录', initial: '随', route: '/pages/doctor/followup/index' }, { label: '排班查看', initial: '排', route: '/pages/doctor/patients/index' }, ]; export default function DoctorHome() { const { user, logout } = useAuthStore(); const [dashboard, setDashboard] = useState(null); const [alertCount, setAlertCount] = useState(0); const [loading, setLoading] = useState(true); useEffect(() => { loadDashboard(); }, []); const loadDashboard = async () => { try { const data = await doctorApi.getDashboard(); setDashboard(data); // 从仪表盘数据提取异常体征患者数 const count = (data as Record)?.abnormal_vital_count; setAlertCount(typeof count === 'number' ? count : 0); } catch { // 静默失败,显示占位 } finally { setLoading(false); } }; const handleCardClick = (card: CardConfig) => { Taro.navigateTo({ url: card.route }); }; const handleLogout = () => { logout(); }; const getValue = (key: keyof doctorApi.DoctorDashboard): number | string => { if (!dashboard) return '-'; return dashboard[key] ?? 0; }; if (loading) return ; return ( 医护工作台 {user?.display_name || user?.username || '医生'},您好 {new Date().toLocaleDateString('zh-CN', { month: 'long', day: 'numeric', weekday: 'long' })} {alertCount > 0 && ( ! {alertCount} 位患者体征异常 Taro.navigateTo({ url: '/pages/doctor/patients/index' })}>查看 → )} Taro.navigateTo({ url: '/pages/doctor/patients/index' })} /> 工作概览 {CARDS.map((card) => ( handleCardClick(card)} > {card.initial} {getValue(card.key)} {card.label} ))} 健康审核 {HEALTH_CARDS.map((card) => ( handleCardClick(card)} > {card.initial} {getValue(card.key)} {card.label} ))} 快捷操作 {QUICK_ACTIONS.map((action) => ( Taro.navigateTo({ url: action.route })} > {action.initial} {action.label} ))} 退出登录 ); }