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:
@@ -114,6 +114,9 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
setCachedPatientId(currentPatient.id);
|
||||
}
|
||||
|
||||
// 状态有变化时清理请求缓存,避免返回过期数据
|
||||
clearRequestCache();
|
||||
|
||||
// 跳过未变更的 set()
|
||||
const cur = get();
|
||||
const userChanged = cur.user?.id !== user?.id;
|
||||
@@ -145,6 +148,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
secureSet('tenant_id', user.tenant_id || '');
|
||||
set({ user, roles, loading: false });
|
||||
clearLoggingOut();
|
||||
get().loadPatients();
|
||||
return true;
|
||||
}
|
||||
secureSet('wechat_openid', resp.openid);
|
||||
@@ -176,6 +180,8 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
secureSet('tenant_id', resp.user?.tenant_id || tenantId);
|
||||
set({ user: resp.user, roles, loading: false });
|
||||
clearLoggingOut();
|
||||
// 登录成功后自动加载患者档案(如果有的话)
|
||||
get().loadPatients();
|
||||
return true;
|
||||
} catch {
|
||||
set({ loading: false });
|
||||
@@ -209,6 +215,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
secureRemove('wechat_openid');
|
||||
set({ user: tokenData.user, roles, loading: false });
|
||||
clearLoggingOut();
|
||||
get().loadPatients();
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
secureRemove('wechat_openid');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand';
|
||||
import * as healthApi from '@/services/health';
|
||||
import { getCachedPatientId } from '@/services/request';
|
||||
import { useAuthStore } from './auth';
|
||||
|
||||
interface CachedTrend {
|
||||
data: { date: string; value: number }[];
|
||||
@@ -37,7 +38,9 @@ export const useHealthStore = create<HealthState>((set, get) => ({
|
||||
}
|
||||
set({ _refreshingToday: true, loading: true });
|
||||
try {
|
||||
const patientId = getCachedPatientId() || undefined;
|
||||
const patientId = getCachedPatientId()
|
||||
|| useAuthStore.getState().currentPatient?.id
|
||||
|| undefined;
|
||||
const data = await healthApi.getTodaySummary(patientId);
|
||||
set({ todaySummary: data, todaySummaryFetchedAt: Date.now(), loading: false, _refreshingToday: false });
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user