P1: - 全局 23 个页面 Taro.navigateTo → safeNavigateTo,防止页栈超10层 - 生产构建保留 console.warn/error,便于线上问题排查 - 添加 preloadRule 分包预加载(首页预加载健康/医生/文章分包) P2: - logout 时清理 ai_chat_history + BLE DataBuffer 缓存 - restore() 移除冗余的双重 Storage 读取(secureGet 已包含 getStorageSync) - 首页文章图片添加 lazyLoad
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import React, { useState, useCallback } from 'react';
|
|
import { View, Text } from '@tarojs/components';
|
|
import Taro from '@tarojs/taro';
|
|
import { safeNavigateTo } from '@/utils/navigate';
|
|
import { usePageData } from '@/hooks/usePageData';
|
|
import { listPatients, Patient } from '../../../services/patient';
|
|
import { useAuthStore } from '../../../stores/auth';
|
|
import EmptyState from '../../../components/EmptyState';
|
|
import { useElderClass } from '../../../hooks/useElderClass';
|
|
import PageShell from '@/components/ui/PageShell';
|
|
import './index.scss';
|
|
|
|
export default function FamilyList() {
|
|
const modeClass = useElderClass();
|
|
const [patients, setPatients] = useState<Patient[]>([]);
|
|
const [loading, setLoading] = useState(false);
|
|
const currentPatient = useAuthStore((s) => s.currentPatient);
|
|
const setCurrentPatient = useAuthStore((s) => s.setCurrentPatient);
|
|
|
|
const fetchPatients = useCallback(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const res = await listPatients();
|
|
setPatients(res.data || []);
|
|
} catch {
|
|
Taro.showToast({ title: '加载失败', icon: 'none' });
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
usePageData(fetchPatients, { throttleMs: 10000 });
|
|
|
|
const handleSelect = (patient: Patient) => {
|
|
setCurrentPatient({
|
|
id: patient.id,
|
|
name: patient.name,
|
|
gender: patient.gender,
|
|
birth_date: patient.birth_date,
|
|
relation: patient.relation || '本人',
|
|
});
|
|
Taro.showToast({ title: `已切换为 ${patient.name}`, icon: 'success' });
|
|
};
|
|
|
|
const goToAdd = () => {
|
|
safeNavigateTo('/pages/pkg-profile/family-add/index');
|
|
};
|
|
|
|
const goToEdit = (patient: Patient) => {
|
|
Taro.setStorageSync('edit_patient', patient);
|
|
safeNavigateTo(`/pages/pkg-profile/family-add/index?id=${patient.id}`);
|
|
};
|
|
|
|
const genderText = (g?: string) => {
|
|
if (g === 'male') return '男';
|
|
if (g === 'female') return '女';
|
|
return '未知';
|
|
};
|
|
|
|
const relationInitial = (relation: string) => {
|
|
return relation ? relation.charAt(0) : '本';
|
|
};
|
|
|
|
return (
|
|
<PageShell className={modeClass}>
|
|
<Text className='family-page-title'>就诊人管理</Text>
|
|
|
|
<View className='family-list'>
|
|
{patients.map((p) => {
|
|
const isActive = currentPatient?.id === p.id;
|
|
return (
|
|
<View
|
|
className={`family-item ${isActive ? 'active' : ''}`}
|
|
key={p.id}
|
|
onClick={() => handleSelect(p)}
|
|
>
|
|
<View className='family-avatar'>
|
|
<Text className='family-avatar-text'>{relationInitial(p.relation || '本人')}</Text>
|
|
</View>
|
|
<View className='family-info'>
|
|
<View className='family-name-row'>
|
|
<Text className='family-name'>{p.name}</Text>
|
|
{isActive && <Text className='family-current-tag'>当前</Text>}
|
|
</View>
|
|
<View className='family-meta'>
|
|
<Text className='family-relation-tag'>{p.relation || '本人'}</Text>
|
|
<Text className='family-gender'>{genderText(p.gender)}</Text>
|
|
</View>
|
|
</View>
|
|
<View
|
|
className='family-edit'
|
|
onClick={(e) => { e.stopPropagation(); goToEdit(p); }}
|
|
>
|
|
<Text className='family-edit-text'>编辑</Text>
|
|
</View>
|
|
</View>
|
|
);
|
|
})}
|
|
</View>
|
|
|
|
{patients.length === 0 && !loading && (
|
|
<EmptyState text='暂无就诊人' />
|
|
)}
|
|
|
|
<View className='family-add-btn' onClick={goToAdd}>
|
|
<Text className='family-add-text'>添加就诊人</Text>
|
|
</View>
|
|
</PageShell>
|
|
);
|
|
}
|