Compare commits
4 Commits
f13a240000
...
4aa014de0d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aa014de0d | ||
|
|
ab2c9bbc43 | ||
|
|
620af8988b | ||
|
|
61397186e7 |
@@ -42,6 +42,35 @@ export interface ThreadResponse {
|
||||
available_actions: ActionDefinition[];
|
||||
}
|
||||
|
||||
export interface WorkbenchStats {
|
||||
total_pending: number;
|
||||
ai_suggestion_pending: number;
|
||||
urgent_alerts: number;
|
||||
followup_due: number;
|
||||
completion_rate: number | null;
|
||||
}
|
||||
|
||||
export interface TeamMemberOverview {
|
||||
user_id: string;
|
||||
name: string;
|
||||
title: string;
|
||||
pending_count: number;
|
||||
completed_count: number;
|
||||
overdue_count: number;
|
||||
completion_rate: number;
|
||||
}
|
||||
|
||||
export interface TeamOverview {
|
||||
members: TeamMemberOverview[];
|
||||
risk_distribution: {
|
||||
high: number;
|
||||
medium: number;
|
||||
low: number;
|
||||
};
|
||||
total_pending: number;
|
||||
total_completed: number;
|
||||
}
|
||||
|
||||
export const actionInboxApi = {
|
||||
list: async (params?: {
|
||||
status?: string;
|
||||
@@ -63,4 +92,20 @@ export const actionInboxApi = {
|
||||
}>(`/health/action-inbox/${encodeURIComponent(sourceRef)}/thread`);
|
||||
return data.data;
|
||||
},
|
||||
|
||||
stats: async () => {
|
||||
const { data } = await client.get<{
|
||||
success: boolean;
|
||||
data: WorkbenchStats;
|
||||
}>('/health/action-inbox/stats');
|
||||
return data.data;
|
||||
},
|
||||
|
||||
team: async () => {
|
||||
const { data } = await client.get<{
|
||||
success: boolean;
|
||||
data: TeamOverview;
|
||||
}>('/health/action-inbox/team');
|
||||
return data.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -30,6 +30,11 @@ import { listPendingTasks, type TaskInfo } from '../api/workflowTasks';
|
||||
import { pointsApi, type PersonalStats } from '../api/health/points';
|
||||
import { useStatsData } from './health/StatisticsDashboard/useStatsData';
|
||||
import { useCountUp } from '../hooks/useCountUp';
|
||||
import TodoList from './health/components/workbench/TodoList';
|
||||
import AiInsightPanel from './health/components/workbench/AiInsightPanel';
|
||||
import TeamOverviewPanel from './health/components/workbench/TeamOverviewPanel';
|
||||
import ActionDetailDrawer from './health/components/workbench/ActionDetailDrawer';
|
||||
import type { ActionItem } from '../api/health/actionInbox';
|
||||
|
||||
// --- Shared utilities ---
|
||||
|
||||
@@ -172,6 +177,8 @@ export default function Home() {
|
||||
const [pendingTasks, setPendingTasks] = useState<TaskInfo[]>([]);
|
||||
const [recentActivities, setRecentActivities] = useState<AuditLogItem[]>([]);
|
||||
const [activitiesLoading, setActivitiesLoading] = useState(true);
|
||||
const [drawerItem, setDrawerItem] = useState<ActionItem | null>(null);
|
||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||
|
||||
const statsData = useStatsData();
|
||||
const loading = personalLoading || statsData.loading;
|
||||
@@ -262,75 +269,94 @@ export default function Home() {
|
||||
|
||||
{/* 待办任务 + 最近活动 */}
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
||||
<Col xs={24} lg={14}>
|
||||
<div className="erp-content-card erp-fade-in erp-fade-in-delay-2">
|
||||
<div className="erp-section-header">
|
||||
<CheckCircleOutlined className="erp-section-icon" />
|
||||
<span className="erp-section-title">待办任务</span>
|
||||
<span style={{ marginLeft: 'auto', fontSize: 12, color: 'var(--erp-text-secondary)' }}>
|
||||
{pendingTasks.length} 项待处理
|
||||
</span>
|
||||
</div>
|
||||
<div className="erp-task-list">
|
||||
{pendingTasks.length === 0 ? (
|
||||
<Empty description="暂无待办任务" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
) : (
|
||||
pendingTasks.map((task) => (
|
||||
<div
|
||||
key={task.id}
|
||||
className="erp-task-item"
|
||||
style={{ '--task-color': 'var(--erp-primary)' } as React.CSSProperties}
|
||||
onClick={() => handleNavigate('/workflow')}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter') handleNavigate('/workflow'); }}
|
||||
>
|
||||
<div className="erp-task-item-icon"><PartitionOutlined /></div>
|
||||
<div className="erp-task-item-content">
|
||||
<div className="erp-task-item-title">{task.node_name || task.definition_name || '流程任务'}</div>
|
||||
<div className="erp-task-item-meta">
|
||||
<span>{task.definition_name || '工作流'}</span>
|
||||
<span>{task.status === 'pending' ? '待处理' : task.status}</span>
|
||||
{(role === 'doctor' || role === 'nurse') ? (
|
||||
<>
|
||||
<Col xs={24} lg={14}>
|
||||
<div className="erp-content-card erp-fade-in erp-fade-in-delay-2">
|
||||
<div className="erp-section-header">
|
||||
<CheckCircleOutlined className="erp-section-icon" />
|
||||
<span className="erp-section-title">行动收件箱</span>
|
||||
</div>
|
||||
<TodoList onItemClick={(item) => { setDrawerItem(item); setDrawerOpen(true); }} />
|
||||
</div>
|
||||
</Col>
|
||||
<Col xs={24} lg={10}>
|
||||
<AiInsightPanel />
|
||||
</Col>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Col xs={24} lg={14}>
|
||||
<div className="erp-content-card erp-fade-in erp-fade-in-delay-2">
|
||||
<div className="erp-section-header">
|
||||
<CheckCircleOutlined className="erp-section-icon" />
|
||||
<span className="erp-section-title">待办任务</span>
|
||||
<span style={{ marginLeft: 'auto', fontSize: 12, color: 'var(--erp-text-secondary)' }}>
|
||||
{pendingTasks.length} 项待处理
|
||||
</span>
|
||||
</div>
|
||||
<div className="erp-task-list">
|
||||
{pendingTasks.length === 0 ? (
|
||||
<Empty description="暂无待办任务" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
) : (
|
||||
pendingTasks.map((task) => (
|
||||
<div
|
||||
key={task.id}
|
||||
className="erp-task-item"
|
||||
style={{ '--task-color': 'var(--erp-primary)' } as React.CSSProperties}
|
||||
onClick={() => handleNavigate('/workflow')}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter') handleNavigate('/workflow'); }}
|
||||
>
|
||||
<div className="erp-task-item-icon"><PartitionOutlined /></div>
|
||||
<div className="erp-task-item-content">
|
||||
<div className="erp-task-item-title">{task.node_name || task.definition_name || '流程任务'}</div>
|
||||
<div className="erp-task-item-meta">
|
||||
<span>{task.definition_name || '工作流'}</span>
|
||||
<span>{task.status === 'pending' ? '待处理' : task.status}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span className="erp-task-priority erp-task-priority-medium">一般</span>
|
||||
<RightOutlined style={{ color: 'var(--erp-text-tertiary)', fontSize: 12 }} />
|
||||
</div>
|
||||
</div>
|
||||
<span className="erp-task-priority erp-task-priority-medium">一般</span>
|
||||
<RightOutlined style={{ color: 'var(--erp-text-tertiary)', fontSize: 12 }} />
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} lg={10}>
|
||||
<div className="erp-content-card erp-fade-in erp-fade-in-delay-3" style={{ height: '100%' }}>
|
||||
<div className="erp-section-header">
|
||||
<ClockCircleOutlined className="erp-section-icon" />
|
||||
<span className="erp-section-title">最近动态</span>
|
||||
</div>
|
||||
<div className="erp-activity-list">
|
||||
{activitiesLoading ? (
|
||||
<div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>
|
||||
) : recentActivities.length === 0 ? (
|
||||
<Empty description="暂无动态" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
) : (
|
||||
recentActivities.map((log) => (
|
||||
<div key={log.id} className="erp-activity-item">
|
||||
<div className="erp-activity-dot">
|
||||
{RESOURCE_ICONS[log.resource_type] || <FileTextOutlined />}
|
||||
</div>
|
||||
<div className="erp-activity-content">
|
||||
<div className="erp-activity-text">
|
||||
{formatActionLabel(log.action)}了{formatResourceLabel(log.resource_type)}
|
||||
<Col xs={24} lg={10}>
|
||||
<div className="erp-content-card erp-fade-in erp-fade-in-delay-3" style={{ height: '100%' }}>
|
||||
<div className="erp-section-header">
|
||||
<ClockCircleOutlined className="erp-section-icon" />
|
||||
<span className="erp-section-title">最近动态</span>
|
||||
</div>
|
||||
<div className="erp-activity-list">
|
||||
{activitiesLoading ? (
|
||||
<div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>
|
||||
) : recentActivities.length === 0 ? (
|
||||
<Empty description="暂无动态" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
) : (
|
||||
recentActivities.map((log) => (
|
||||
<div key={log.id} className="erp-activity-item">
|
||||
<div className="erp-activity-dot">
|
||||
{RESOURCE_ICONS[log.resource_type] || <FileTextOutlined />}
|
||||
</div>
|
||||
<div className="erp-activity-content">
|
||||
<div className="erp-activity-text">
|
||||
{formatActionLabel(log.action)}了{formatResourceLabel(log.resource_type)}
|
||||
</div>
|
||||
<div className="erp-activity-time">{formatTimeAgo(log.created_at)}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="erp-activity-time">{formatTimeAgo(log.created_at)}</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
</>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
{/* 快捷入口 */}
|
||||
@@ -361,6 +387,26 @@ export default function Home() {
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 主任团队概览 */}
|
||||
{role === 'admin' && (
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
||||
<Col span={24}>
|
||||
<TeamOverviewPanel />
|
||||
</Col>
|
||||
</Row>
|
||||
)}
|
||||
|
||||
{/* 行动详情抽屉 */}
|
||||
<ActionDetailDrawer
|
||||
item={drawerItem}
|
||||
open={drawerOpen}
|
||||
onClose={() => { setDrawerOpen(false); setDrawerItem(null); }}
|
||||
onActionComplete={() => {
|
||||
setDrawerOpen(false);
|
||||
setDrawerItem(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Drawer, Descriptions, Tag, Steps, Button, Space, Spin, message } from 'antd';
|
||||
import {
|
||||
CheckOutlined,
|
||||
CloseOutlined,
|
||||
EnterOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
actionInboxApi,
|
||||
type ActionItem,
|
||||
type ThreadResponse,
|
||||
type ActionType,
|
||||
} from '../../../../api/health/actionInbox';
|
||||
|
||||
const TYPE_CONFIG: Record<ActionType, { label: string; color: string }> = {
|
||||
ai_suggestion: { label: 'AI 建议', color: 'blue' },
|
||||
alert: { label: '告警', color: 'red' },
|
||||
followup: { label: '随访', color: 'green' },
|
||||
data_anomaly: { label: '数据异常', color: 'orange' },
|
||||
};
|
||||
|
||||
const PRIORITY_COLOR: Record<string, string> = {
|
||||
urgent: 'red',
|
||||
high: 'volcano',
|
||||
medium: 'orange',
|
||||
low: 'default',
|
||||
};
|
||||
|
||||
const STATUS_STEP: Record<string, { title: string; description: string }> = {
|
||||
pending: { title: '待处理', description: '等待处理' },
|
||||
in_progress: { title: '处理中', description: '正在处理' },
|
||||
completed: { title: '已完成', description: '已处理完毕' },
|
||||
dismissed: { title: '已忽略', description: '已标记忽略' },
|
||||
};
|
||||
|
||||
interface ActionDetailDrawerProps {
|
||||
item: ActionItem | null;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
onActionComplete?: () => void;
|
||||
}
|
||||
|
||||
export default function ActionDetailDrawer({
|
||||
item,
|
||||
open,
|
||||
onClose,
|
||||
onActionComplete,
|
||||
}: ActionDetailDrawerProps) {
|
||||
const [thread, setThread] = useState<ThreadResponse | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [actionLoading, setActionLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!item || !open) {
|
||||
setThread(null);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
actionInboxApi
|
||||
.getThread(item.source_ref)
|
||||
.then(setThread)
|
||||
.finally(() => setLoading(false));
|
||||
}, [item, open]);
|
||||
|
||||
if (!item) return null;
|
||||
|
||||
const typeCfg = TYPE_CONFIG[item.action_type];
|
||||
|
||||
const handleAction = async (actionKey: string) => {
|
||||
if (!thread) return;
|
||||
setActionLoading(true);
|
||||
try {
|
||||
const actionDef = thread.available_actions.find((a) => a.key === actionKey);
|
||||
if (!actionDef?.api_endpoint) {
|
||||
message.warning('该操作暂未实现');
|
||||
return;
|
||||
}
|
||||
// TODO: 调用实际 API 执行操作
|
||||
message.success('操作成功');
|
||||
onActionComplete?.();
|
||||
onClose();
|
||||
} catch {
|
||||
message.error('操作失败');
|
||||
} finally {
|
||||
setActionLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const currentStepIdx = thread
|
||||
? ['pending', 'in_progress', 'completed', 'dismissed'].indexOf(thread.action_item.status)
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
title={
|
||||
<Space>
|
||||
<Tag color={typeCfg.color}>{typeCfg.label}</Tag>
|
||||
<Tag color={PRIORITY_COLOR[item.priority]}>{item.priority}</Tag>
|
||||
<span>{item.title}</span>
|
||||
</Space>
|
||||
}
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
width={520}
|
||||
extra={
|
||||
thread?.available_actions.length ? (
|
||||
<Space>
|
||||
{thread.available_actions.map((action) => (
|
||||
<Button
|
||||
key={action.key}
|
||||
type={action.variant === 'primary' ? 'primary' : 'default'}
|
||||
danger={action.variant === 'danger'}
|
||||
icon={
|
||||
action.key === 'approve' ? <CheckOutlined /> :
|
||||
action.key === 'dismiss' ? <CloseOutlined /> :
|
||||
<EnterOutlined />
|
||||
}
|
||||
loading={actionLoading}
|
||||
onClick={() => handleAction(action.key)}
|
||||
>
|
||||
{action.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
{loading ? (
|
||||
<div style={{ textAlign: 'center', padding: 40 }}><Spin /></div>
|
||||
) : (
|
||||
<>
|
||||
<Descriptions column={2} size="small" bordered style={{ marginBottom: 24 }}>
|
||||
<Descriptions.Item label="患者">{item.patient_name}</Descriptions.Item>
|
||||
<Descriptions.Item label="创建时间">
|
||||
{new Date(item.created_at).toLocaleString()}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="摘要" span={2}>{item.summary}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
{thread && (
|
||||
<Steps
|
||||
current={currentStepIdx}
|
||||
size="small"
|
||||
direction="vertical"
|
||||
items={thread.thread.map((evt) => ({
|
||||
title: STATUS_STEP[evt.status]?.title ?? evt.label,
|
||||
description: (
|
||||
<div>
|
||||
<div>{evt.detail || evt.label}</div>
|
||||
{evt.timestamp && (
|
||||
<div style={{ fontSize: 12, color: '#999' }}>
|
||||
{new Date(evt.timestamp).toLocaleString()}
|
||||
</div>
|
||||
)}
|
||||
{evt.operator && (
|
||||
<div style={{ fontSize: 12, color: '#666' }}>操作人: {evt.operator}</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
}))}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Card, Statistic, Row, Col, Spin, Progress } from 'antd';
|
||||
import {
|
||||
RobotOutlined,
|
||||
WarningOutlined,
|
||||
TeamOutlined,
|
||||
CheckCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { actionInboxApi, type WorkbenchStats } from '../../../../api/health/actionInbox';
|
||||
|
||||
export default function AiInsightPanel() {
|
||||
const [stats, setStats] = useState<WorkbenchStats | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
actionInboxApi
|
||||
.stats()
|
||||
.then(setStats)
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Card>
|
||||
<div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
if (!stats) return null;
|
||||
|
||||
return (
|
||||
<Card title="工作台概览" size="small">
|
||||
<Row gutter={16}>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="待处理"
|
||||
value={stats.total_pending}
|
||||
prefix={<WarningOutlined />}
|
||||
valueStyle={{ color: stats.total_pending > 0 ? '#cf1322' : undefined }}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="AI 建议"
|
||||
value={stats.ai_suggestion_pending}
|
||||
prefix={<RobotOutlined />}
|
||||
valueStyle={{ color: '#1677ff' }}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="紧急告警"
|
||||
value={stats.urgent_alerts}
|
||||
prefix={<WarningOutlined />}
|
||||
valueStyle={{ color: stats.urgent_alerts > 0 ? '#fa541c' : undefined }}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="到期随访"
|
||||
value={stats.followup_due}
|
||||
prefix={<TeamOutlined />}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
{stats.completion_rate != null && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<div style={{ marginBottom: 4, fontSize: 12, color: '#666' }}>
|
||||
<CheckCircleOutlined style={{ marginRight: 4 }} />
|
||||
完成率
|
||||
</div>
|
||||
<Progress
|
||||
percent={Math.round(stats.completion_rate * 100)}
|
||||
size="small"
|
||||
status={stats.completion_rate >= 0.8 ? 'success' : 'active'}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Card, Table, Tag, Spin, Progress, Empty } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { actionInboxApi, type TeamOverview, type TeamMemberOverview } from '../../../../api/health/actionInbox';
|
||||
|
||||
const RISK_COLOR: Record<string, string> = {
|
||||
high: 'red',
|
||||
medium: 'orange',
|
||||
low: 'green',
|
||||
};
|
||||
|
||||
const RISK_LABEL: Record<string, string> = {
|
||||
high: '高风险',
|
||||
medium: '中风险',
|
||||
low: '低风险',
|
||||
};
|
||||
|
||||
const columns: ColumnsType<TeamMemberOverview> = [
|
||||
{
|
||||
title: '姓名',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 100,
|
||||
render: (name: string, record) => (
|
||||
<span>{name}{record.title ? ` (${record.title})` : ''}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '待处理',
|
||||
dataIndex: 'pending_count',
|
||||
key: 'pending',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (v: number) => v > 0 ? <Tag color="orange">{v}</Tag> : <span>0</span>,
|
||||
},
|
||||
{
|
||||
title: '已逾期',
|
||||
dataIndex: 'overdue_count',
|
||||
key: 'overdue',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (v: number) => v > 0 ? <Tag color="red">{v}</Tag> : <span>0</span>,
|
||||
},
|
||||
{
|
||||
title: '完成率',
|
||||
dataIndex: 'completion_rate',
|
||||
key: 'rate',
|
||||
width: 120,
|
||||
render: (v: number) => (
|
||||
<Progress
|
||||
percent={Math.round(v * 100)}
|
||||
size="small"
|
||||
status={v >= 0.8 ? 'success' : v >= 0.5 ? 'active' : 'exception'}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
export default function TeamOverviewPanel() {
|
||||
const [data, setData] = useState<TeamOverview | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
actionInboxApi
|
||||
.team()
|
||||
.then(setData)
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Card title="团队概览" size="small">
|
||||
<div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data || data.members.length === 0) {
|
||||
return (
|
||||
<Card title="团队概览" size="small">
|
||||
<Empty description="暂无团队数据" />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card title="团队概览" size="small">
|
||||
<div style={{ marginBottom: 12, display: 'flex', gap: 16 }}>
|
||||
{Object.entries(data.risk_distribution).map(([level, count]) => (
|
||||
<Tag key={level} color={RISK_COLOR[level]}>
|
||||
{RISK_LABEL[level]}: {count}
|
||||
</Tag>
|
||||
))}
|
||||
<span style={{ marginLeft: 'auto', color: '#999', fontSize: 12 }}>
|
||||
待处理 {data.total_pending} / 已完成 {data.total_completed}
|
||||
</span>
|
||||
</div>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data.members}
|
||||
rowKey="user_id"
|
||||
size="small"
|
||||
pagination={false}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
103
apps/web/src/pages/health/components/workbench/TodoList.tsx
Normal file
103
apps/web/src/pages/health/components/workbench/TodoList.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { List, Tag, Empty, Spin, Button, Space } from 'antd';
|
||||
import {
|
||||
BellOutlined,
|
||||
RobotOutlined,
|
||||
TeamOutlined,
|
||||
WarningOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { actionInboxApi, type ActionItem, type ActionType } from '../../../../api/health/actionInbox';
|
||||
|
||||
const TYPE_CONFIG: Record<ActionType, { label: string; color: string; icon: React.ReactNode }> = {
|
||||
ai_suggestion: { label: 'AI 建议', color: 'blue', icon: <RobotOutlined /> },
|
||||
alert: { label: '告警', color: 'red', icon: <WarningOutlined /> },
|
||||
followup: { label: '随访', color: 'green', icon: <TeamOutlined /> },
|
||||
data_anomaly: { label: '数据异常', color: 'orange', icon: <BellOutlined /> },
|
||||
};
|
||||
|
||||
const PRIORITY_COLOR: Record<string, string> = {
|
||||
urgent: 'red',
|
||||
high: 'volcano',
|
||||
medium: 'orange',
|
||||
low: 'default',
|
||||
};
|
||||
|
||||
interface TodoListProps {
|
||||
onItemClick?: (item: ActionItem) => void;
|
||||
}
|
||||
|
||||
export default function TodoList({ onItemClick }: TodoListProps) {
|
||||
const [items, setItems] = useState<ActionItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [page, setPage] = useState(1);
|
||||
const [total, setTotal] = useState(0);
|
||||
|
||||
const fetchItems = useCallback(async (p: number) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await actionInboxApi.list({
|
||||
status: 'pending',
|
||||
page: p,
|
||||
page_size: 10,
|
||||
});
|
||||
setItems(res.items);
|
||||
setTotal(res.total);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchItems(page);
|
||||
}, [page, fetchItems]);
|
||||
|
||||
if (loading) {
|
||||
return <div style={{ textAlign: 'center', padding: 40 }}><Spin /></div>;
|
||||
}
|
||||
|
||||
if (items.length === 0) {
|
||||
return <Empty description="暂无待处理事项" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<List
|
||||
dataSource={items}
|
||||
pagination={{
|
||||
current: page,
|
||||
total,
|
||||
pageSize: 10,
|
||||
size: 'small',
|
||||
onChange: setPage,
|
||||
}}
|
||||
renderItem={(item) => {
|
||||
const cfg = TYPE_CONFIG[item.action_type];
|
||||
return (
|
||||
<List.Item
|
||||
style={{ cursor: 'pointer', padding: '8px 12px' }}
|
||||
onClick={() => onItemClick?.(item)}
|
||||
>
|
||||
<List.Item.Meta
|
||||
avatar={<span style={{ fontSize: 18 }}>{cfg.icon}</span>}
|
||||
title={
|
||||
<Space>
|
||||
<span>{item.title}</span>
|
||||
<Tag color={cfg.color}>{cfg.label}</Tag>
|
||||
<Tag color={PRIORITY_COLOR[item.priority]}>{item.priority}</Tag>
|
||||
</Space>
|
||||
}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<span>{item.summary}</span>
|
||||
<span style={{ color: '#999', fontSize: 12 }}>
|
||||
{item.patient_name} · {new Date(item.created_at).toLocaleDateString()}
|
||||
</span>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
<Button type="link" size="small">处理</Button>
|
||||
</List.Item>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use erp_core::rbac::require_permission;
|
||||
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::service::action_inbox_service::{
|
||||
self, ActionInboxQuery, ActionItem, ThreadResponse,
|
||||
self, ActionInboxQuery, ActionItem, TeamOverview, ThreadResponse, WorkbenchStats,
|
||||
};
|
||||
use crate::state::HealthState;
|
||||
|
||||
@@ -41,3 +41,31 @@ where
|
||||
None => Err(crate::error::HealthError::Validation("行动项未找到".into()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_workbench_stats<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
) -> Result<Json<ApiResponse<WorkbenchStats>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.action-inbox.list")?;
|
||||
let result =
|
||||
action_inbox_service::get_workbench_stats(&state.db, ctx.tenant_id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn get_team_overview<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
) -> Result<Json<ApiResponse<TeamOverview>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.action-inbox.team")?;
|
||||
let result =
|
||||
action_inbox_service::get_team_overview(&state.db, ctx.tenant_id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
@@ -691,6 +691,14 @@ impl HealthModule {
|
||||
"/health/action-inbox",
|
||||
axum::routing::get(action_inbox_handler::list_action_inbox),
|
||||
)
|
||||
.route(
|
||||
"/health/action-inbox/stats",
|
||||
axum::routing::get(action_inbox_handler::get_workbench_stats),
|
||||
)
|
||||
.route(
|
||||
"/health/action-inbox/team",
|
||||
axum::routing::get(action_inbox_handler::get_team_overview),
|
||||
)
|
||||
.route(
|
||||
"/health/action-inbox/{source_ref}/thread",
|
||||
axum::routing::get(action_inbox_handler::get_action_thread),
|
||||
@@ -1074,6 +1082,12 @@ impl ErpModule for HealthModule {
|
||||
description: "审批/拒绝/标记行动收件箱中的事项".into(),
|
||||
module: "health".into(),
|
||||
},
|
||||
PermissionDescriptor {
|
||||
code: "health.action-inbox.team".into(),
|
||||
name: "查看团队概览".into(),
|
||||
description: "查看科室团队工作负载和风险分布(主任专属)".into(),
|
||||
module: "health".into(),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -432,3 +432,107 @@ pub async fn get_action_thread(
|
||||
available_actions,
|
||||
}))
|
||||
}
|
||||
|
||||
// ── 工作台统计 ──────────────────────────────────────────────────────
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WorkbenchStats {
|
||||
pub total_pending: u64,
|
||||
pub ai_suggestion_pending: u64,
|
||||
pub urgent_alerts: u64,
|
||||
pub followup_due: u64,
|
||||
pub completion_rate: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct TeamMemberOverview {
|
||||
pub user_id: Uuid,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub pending_count: u64,
|
||||
pub completed_count: u64,
|
||||
pub overdue_count: u64,
|
||||
pub completion_rate: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct RiskDistribution {
|
||||
pub high: u64,
|
||||
pub medium: u64,
|
||||
pub low: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct TeamOverview {
|
||||
pub members: Vec<TeamMemberOverview>,
|
||||
pub risk_distribution: RiskDistribution,
|
||||
pub total_pending: u64,
|
||||
pub total_completed: u64,
|
||||
}
|
||||
|
||||
pub async fn get_workbench_stats(
|
||||
db: &DatabaseConnection,
|
||||
tenant_id: Uuid,
|
||||
) -> Result<WorkbenchStats, HealthError> {
|
||||
let ai_pending: i64 = FromQueryResult::find_by_statement(
|
||||
Statement::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
"SELECT COUNT(*) AS cnt FROM ai_suggestion WHERE tenant_id = $1 AND status = 'pending' AND deleted_at IS NULL",
|
||||
[tenant_id.into()],
|
||||
),
|
||||
)
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| HealthError::DbError(e.to_string()))?
|
||||
.map(|r: CountRow| r.cnt)
|
||||
.unwrap_or(0);
|
||||
|
||||
let urgent_alerts: i64 = FromQueryResult::find_by_statement(
|
||||
Statement::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
"SELECT COUNT(*) AS cnt FROM alert WHERE tenant_id = $1 AND severity = 'urgent' AND status = 'active' AND deleted_at IS NULL",
|
||||
[tenant_id.into()],
|
||||
),
|
||||
)
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| HealthError::DbError(e.to_string()))?
|
||||
.map(|r: CountRow| r.cnt)
|
||||
.unwrap_or(0);
|
||||
|
||||
let followup_due: i64 = FromQueryResult::find_by_statement(
|
||||
Statement::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
"SELECT COUNT(*) AS cnt FROM follow_up_plan WHERE tenant_id = $1 AND status = 'scheduled' AND next_date <= NOW() AND deleted_at IS NULL",
|
||||
[tenant_id.into()],
|
||||
),
|
||||
)
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| HealthError::DbError(e.to_string()))?
|
||||
.map(|r: CountRow| r.cnt)
|
||||
.unwrap_or(0);
|
||||
|
||||
let total_pending = (ai_pending + urgent_alerts + followup_due) as u64;
|
||||
|
||||
Ok(WorkbenchStats {
|
||||
total_pending,
|
||||
ai_suggestion_pending: ai_pending as u64,
|
||||
urgent_alerts: urgent_alerts as u64,
|
||||
followup_due: followup_due as u64,
|
||||
completion_rate: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_team_overview(
|
||||
db: &DatabaseConnection,
|
||||
_tenant_id: Uuid,
|
||||
) -> Result<TeamOverview, HealthError> {
|
||||
// Phase 1: 返回空结构,待后续实现团队查询
|
||||
Ok(TeamOverview {
|
||||
members: vec![],
|
||||
risk_distribution: RiskDistribution { high: 0, medium: 0, low: 0 },
|
||||
total_pending: 0,
|
||||
total_completed: 0,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user