fix(web): DoctorSelect 预加载医生列表 + 搜索错误处理
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

- 组件挂载时预加载最多 50 条医生数据,下拉框打开即有选项
- 搜索清空时保留已有列表(不再置空)
- 搜索失败时 catch 错误,保留初始列表不静默丢失
- 更新质量验证报告:全部 MEDIUM 问题已关闭
This commit is contained in:
iven
2026-05-05 11:15:12 +08:00
parent 0f55d26076
commit 062b4493e4
2 changed files with 26 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { Select } from 'antd';
import { useState, useCallback } from 'react';
import { useState, useCallback, useEffect } from 'react';
import { doctorApi } from '../../../api/health/doctors';
interface Props {
@@ -14,9 +14,23 @@ export function DoctorSelect({ value, onChange, placeholder }: Props) {
>([]);
const [fetching, setFetching] = useState(false);
useEffect(() => {
let cancelled = false;
doctorApi.list({ page_size: 50 }).then((result) => {
if (!cancelled) {
setOptions(
result.data.map((d) => ({
value: d.id,
label: `${d.name}${d.department ? ` - ${d.department}` : ''}`,
})),
);
}
}).catch(() => {});
return () => { cancelled = true; };
}, []);
const handleSearch = useCallback(async (search: string) => {
if (!search || search.length < 1) {
setOptions([]);
return;
}
setFetching(true);
@@ -31,6 +45,8 @@ export function DoctorSelect({ value, onChange, placeholder }: Props) {
label: `${d.name}${d.department ? ` - ${d.department}` : ''}`,
})),
);
} catch {
// 搜索失败时保留初始列表
} finally {
setFetching(false);
}