import { useCallback, useEffect, useState } from 'react'; import { Tag, List, Badge, Tabs, Spin, Empty } from 'antd'; import { PageContainer } from '../../components/PageContainer'; import ActionThreadDrawer from '../../components/ActionThreadDrawer'; import { actionInboxApi, type ActionItem, type ActionType, type ActionPriority, } from '../../api/health/actionInbox'; import { formatRelative } from '../../utils/format'; const TYPE_CONFIG: Record = { ai_suggestion: { label: 'AI建议', color: '#722ed1' }, alert: { label: '告警', color: '#f5222d' }, followup: { label: '随访', color: '#1890ff' }, data_anomaly: { label: '异常', color: '#fa8c16' }, }; const PRIORITY_LABEL: Record = { urgent: '紧急', high: '高', medium: '中', low: '低', }; const PRIORITY_COLOR: Record = { urgent: 'red', high: 'orange', medium: 'blue', low: 'default', }; const STATUS_TABS = [ { key: 'all', label: '全部' }, { key: 'pending', label: '待处理' }, { key: 'in_progress', label: '进行中' }, { key: 'completed', label: '已完成' }, ]; const BADGE_STATUS: Record = { pending: 'error', in_progress: 'processing', completed: 'default', }; export default function ActionInbox() { const [items, setItems] = useState([]); const [total, setTotal] = useState(0); const [page, setPage] = useState(1); const [loading, setLoading] = useState(false); const [statusFilter, setStatusFilter] = useState('all'); const [drawerOpen, setDrawerOpen] = useState(false); const [selectedItem, setSelectedItem] = useState(null); const fetchData = useCallback( async (p: number, status?: string) => { setLoading(true); try { const resp = await actionInboxApi.list({ page: p, page_size: 20, status: status === 'all' ? undefined : status, }); setItems(resp.data); setTotal(resp.total); setPage(p); } finally { setLoading(false); } }, [], ); useEffect(() => { fetchData(1, 'all'); }, [fetchData]); const handleTabChange = (key: string) => { setStatusFilter(key); fetchData(1, key); }; const handleItemClick = (item: ActionItem) => { setSelectedItem(item); setDrawerOpen(true); }; const handleActionComplete = () => { fetchData(page, statusFilter); }; return ( ({ key: tab.key, label: tab.label, }))} /> {items.length === 0 && !loading ? ( ) : ( fetchData(p, statusFilter), showTotal: (t) => `共 ${t} 条`, }} renderItem={(item) => { const typeConf = TYPE_CONFIG[item.action_type] ?? ({ label: '未知', color: '#999' } as { label: string; color: string; }); return ( handleItemClick(item)} > } title={
{typeConf.label} {item.title} {PRIORITY_LABEL[item.priority]}
} description={`${item.patient_name} · ${formatRelative(item.created_at)}`} />
); }} /> )}
setDrawerOpen(false)} onActionComplete={handleActionComplete} />
); }