refactor(web): 新增 useDictionary hook + 4 个页面下拉选项改用字典 API

- 新增 useDictionary hook 支持字典 API 获取 + fallback 降级
- DoctorList 科室/职称改用 useDictionary (health_department/health_title)
- FollowUpTaskList 随访类型改用 useDictionary (health_follow_up_type)
- ConsultationList 咨询类型改用 useDictionary (health_consultation_type)
- FamilyMembersTab 家庭关系改用 useDictionary (health_relationship)
This commit is contained in:
iven
2026-05-02 11:27:11 +08:00
parent b6e780e649
commit 63ead0c442
5 changed files with 45 additions and 5 deletions

View File

@@ -0,0 +1,31 @@
import { useEffect, useState, useMemo } from 'react';
import { listItemsByCode, type DictionaryItemInfo } from '../api/dictionaries';
export interface DictOption {
value: string;
label: string;
}
export function useDictionary(code: string, fallback?: DictOption[]) {
const [items, setItems] = useState<DictionaryItemInfo[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
setLoading(true);
listItemsByCode(code)
.then((data) => setItems(data))
.catch(() => setItems([]))
.finally(() => setLoading(false));
}, [code]);
const options = useMemo<DictOption[]>(() => {
if (items.length > 0) {
return items
.sort((a, b) => a.sort_order - b.sort_order)
.map((item) => ({ value: item.value, label: item.label }));
}
return fallback ?? [];
}, [items, fallback]);
return { items, options, loading };
}