fix(miniprogram): 首页体征数据加载时序 + 并发控制 + 权限修复

- ConcurrencyLimiter 12→8 预留长轮询通道,避免超微信 10 并发限制
- usePageData 添加 AbortController,页面隐藏/卸载自动取消请求
- useHomeData 添加 useEffect 监听 currentPatient 变化自动触发数据加载
- 医护人员首页跳转前不渲染 HomeDashboard,避免触发无用 API 请求
- auth.ts getPatients 正确提取分页响应 .data 数组
- health.ts getTodaySummary 从 Storage 回退读取 patient_id
- health store refreshToday 从 auth store 回退获取 currentPatient.id
- auth store restore() 状态变化时清理请求缓存,避免返回过期数据
This commit is contained in:
iven
2026-05-21 01:08:29 +08:00
parent ec7f76127d
commit 9033ec8ca2
8 changed files with 78 additions and 13 deletions

View File

@@ -314,14 +314,25 @@ export default function Index() {
const modeClass = mode === 'elder' ? 'elder-mode' : '';
// 医护人员访问患者首页时,自动跳转到医生端
// 不渲染 HomeDashboard避免触发患者首页的 API 请求(并发叠加问题)
const shouldRedirect = user && isMedicalStaff();
useDidShow(() => {
if (user && isMedicalStaff()) {
Taro.redirectTo({ url: '/pages/pkg-doctor-core/index' });
if (shouldRedirect) {
Taro.reLaunch({
url: '/pages/pkg-doctor-core/index',
fail: () => {
console.warn('跳转医生端失败,停留患者首页');
},
});
}
});
if (!user) {
return <GuestHome modeClass={modeClass} />;
}
if (shouldRedirect) {
return <Loading />;
}
return <HomeDashboard modeClass={modeClass} />;
}

View File

@@ -1,4 +1,4 @@
import { useState, useMemo, useRef } from 'react';
import { useState, useMemo, useRef, useEffect } from 'react';
import { useHealthStore } from '@/stores/health';
import { useAuthStore } from '@/stores/auth';
import { usePageData } from '@/hooks/usePageData';
@@ -53,6 +53,17 @@ export function useHomeData() {
enabled: !!user,
});
// currentPatient 从 null 变为有值时重新触发加载
// 解决 loadPatients 异步完成前 useDidShow 已触发 fetchData 并因 patientId 为空提前返回的问题
const prevPatientRef = useRef<string | null>(null);
useEffect(() => {
const pid = currentPatient?.id ?? null;
if (pid && pid !== prevPatientRef.current) {
prevPatientRef.current = pid;
trigger();
}
}, [currentPatient?.id, trigger]);
const loadUnread = async () => {
try {
const res = await notificationService.getUnreadCount() as { data?: { count?: number } | number };