import { useCallback, useEffect, useState } from 'react'; import { Drawer, Timeline, Button, Spin, Result, Space, Tag } from 'antd'; import { CheckCircleOutlined, ClockCircleOutlined, MinusCircleOutlined, CloseCircleOutlined, UserOutlined, } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import { actionInboxApi, type ActionItem, type ThreadResponse, type ActionPriority, } from '../api/health/actionInbox'; import client from '../api/client'; interface Props { open: boolean; item: ActionItem | null; onClose: () => void; onActionComplete?: () => void; } const PRIORITY_COLOR: Record = { urgent: 'red', high: 'orange', medium: 'blue', low: 'default', }; const PRIORITY_LABEL: Record = { urgent: '紧急', high: '高', medium: '中', low: '低', }; export default function ActionThreadDrawer({ open, item, onClose, onActionComplete, }: Props) { const navigate = useNavigate(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [threadData, setThreadData] = useState(null); const [actionLoading, setActionLoading] = useState(null); const fetchThread = useCallback(async () => { if (!item) return; setLoading(true); setError(null); try { const data = await actionInboxApi.getThread(item.source_ref); setThreadData(data); } catch (e: unknown) { const msg = e instanceof Error ? e.message : '获取线程失败'; setError(msg); } finally { setLoading(false); } }, [item]); useEffect(() => { if (open && item) fetchThread(); if (!open) setThreadData(null); }, [open, item, fetchThread]); const handleAction = async (endpoint: string, key: string) => { setActionLoading(key); try { await client.post(endpoint, { action: key }); onActionComplete?.(); fetchThread(); } catch { // 全局拦截器处理 } finally { setActionLoading(null); } }; const handleLinkClick = (linkTo?: string) => { if (linkTo) { onClose(); navigate(linkTo); } }; const timelineDot = (status: string) => { switch (status) { case 'completed': return ; case 'in_progress': return ; case 'dismissed': return ; default: return ; } }; return ( {loading && (
)} {error && (
)} {threadData && !loading && ( <>
{threadData.action_item.title}
{threadData.action_item.patient_name} {PRIORITY_LABEL[threadData.action_item.priority]}
处理进度
({ color: evt.status === 'completed' ? 'green' : evt.status === 'in_progress' ? 'blue' : 'gray', dot: timelineDot(evt.status), children: (
{evt.label}
{evt.detail && (
{evt.detail}
)} {evt.timestamp && (
{new Date(evt.timestamp).toLocaleString('zh-CN')}
)} {evt.link_to && ( handleLinkClick(evt.link_to)} style={{ fontSize: 12 }} > 查看详情 → )}
), }))} />
{threadData.available_actions.length > 0 && (
{threadData.available_actions.map((action) => ( ))}
)} )}
); }