Files
hms/apps/web/src/pages/health/DeviceManage.tsx
iven 5140552ff6
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
fix(health): 走查止血 — 患者名显示修复 + 枚举补全 + 医护统计 + 设备选择器
后端:
- alert_service: list_alerts 批量查询 patient_name 填充 AlertResponse
- consultation_service: list_sessions 批量查询 patient_name/doctor_name
- erp-ai handler: list_analysis 通过 raw SQL 查询 patient_name

前端:
- AlertList/AlertDashboard: 使用后端返回的 patient_name 替代 ID 截断
- ConsultationDetail: 使用 patient_name/doctor_name 替代 ID 截断
- AiAnalysisList: 使用 patient_name 替代 ID 截断
- constants/health: SEVERITY 补 high/medium, STATUS 补 active
- AdminDashboard: 医护人数改为 API 查询(useStatsData 新增 doctorCount)
- DeviceManage: 患者 ID 输入改为 PatientSelect 搜索选择器
2026-05-04 00:03:40 +08:00

149 lines
4.0 KiB
TypeScript

import { useCallback, useEffect, useState } from 'react';
import { Button, Input, message, Popconfirm, Select, Space, Table, Tag } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import { deviceApi, type DeviceItem } from '../../api/health/devices';
import { DEVICE_TYPE_OPTIONS, DEVICE_TYPE_COLOR } from '../../constants/health';
import { PatientSelect } from './components/PatientSelect';
function formatTime(val?: string | null): string {
if (!val) return '-';
return dayjs(val).format('YYYY-MM-DD HH:mm');
}
export default function DeviceManage() {
const [data, setData] = useState<DeviceItem[]>([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
const [page, setPage] = useState(1);
const [filterPatientId, setFilterPatientId] = useState('');
const [filterDeviceType, setFilterDeviceType] = useState<string | undefined>(undefined);
const fetchDevices = useCallback(async () => {
setLoading(true);
try {
const res = await deviceApi.listDevices({
page,
page_size: 20,
...(filterPatientId ? { patient_id: filterPatientId } : {}),
...(filterDeviceType ? { device_type: filterDeviceType } : {}),
});
setData(res.data);
setTotal(res.total);
} catch {
message.error('加载设备列表失败');
} finally {
setLoading(false);
}
}, [page, filterPatientId, filterDeviceType]);
useEffect(() => {
fetchDevices();
}, [fetchDevices]);
const handleUnbind = async (record: DeviceItem) => {
try {
await deviceApi.unbindDevice(record.id, record.version);
message.success('设备已解绑');
fetchDevices();
} catch {
message.error('解绑失败');
}
};
const columns: ColumnsType<DeviceItem> = [
{
title: '设备 ID',
dataIndex: 'device_id',
width: 120,
render: (v: string) => v.slice(0, 8),
},
{
title: '设备型号',
dataIndex: 'device_model',
width: 160,
},
{
title: '设备类型',
dataIndex: 'device_type',
width: 100,
render: (v: string) => {
const label = DEVICE_TYPE_OPTIONS.find((d) => d.value === v)?.label || v;
return <Tag color={DEVICE_TYPE_COLOR[v] || 'default'}>{label}</Tag>;
},
},
{
title: '绑定时间',
dataIndex: 'bound_at',
width: 170,
render: (v: string) => formatTime(v),
},
{
title: '最后同步',
dataIndex: 'last_sync_at',
width: 170,
render: (v: string) => formatTime(v),
},
{
title: '操作',
width: 80,
render: (_, record) => (
<Popconfirm
title="确认解绑"
description="解绑后设备将不再关联该患者,确定继续?"
onConfirm={() => handleUnbind(record)}
okText="确定"
cancelText="取消"
>
<Button size="small" type="link" danger>
</Button>
</Popconfirm>
),
},
];
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}></h2>
<Space style={{ marginBottom: 16 }} wrap>
<div style={{ width: 240 }}>
<PatientSelect
value={filterPatientId || undefined}
onChange={(val) => setFilterPatientId(val || '')}
placeholder="搜索患者"
/>
</div>
<Select
placeholder="设备类型"
value={filterDeviceType}
onChange={setFilterDeviceType}
options={DEVICE_TYPE_OPTIONS}
style={{ width: 140 }}
allowClear
/>
<Button type="primary" onClick={() => setPage(1)}>
</Button>
</Space>
<Table<DeviceItem>
rowKey="id"
columns={columns}
dataSource={data}
loading={loading}
pagination={{
current: page,
total,
pageSize: 20,
showTotal: (t) => `${t}`,
onChange: (p) => setPage(p),
}}
/>
</div>
);
}