fix(mp): 五专家组审查 HIGH 级问题修复 — 9 项
- S-1: 隐私政策描述修正("混淆加密" → "HTTPS + 微信沙箱") - A-1: getCachedPatientId 统一导出 + 9 处 Storage 直读替换 - A-2: usePageData loading 改为 useState 响应式 - A-3: health.ts refreshingToday 移入 store state - M-2: prod config 移除 console.error/warn - M-4: clearCache 后同步刷新 request.ts 内存缓存 - Q-3: doctor/appointment.ts any[] → Appointment 类型 - Q-4: daily-monitoring 常量提取到 constants.ts - 清理: 删除空目录 FamilyPicker/HealthCard + 未使用组件 DeviceCard
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import Taro from '@tarojs/taro';
|
||||
import * as healthApi from '@/services/health';
|
||||
import { getCachedPatientId } from '@/services/request';
|
||||
|
||||
interface CachedTrend {
|
||||
data: { date: string; value: number }[];
|
||||
@@ -12,6 +12,7 @@ interface HealthState {
|
||||
todaySummaryFetchedAt: number;
|
||||
trendData: Record<string, CachedTrend>;
|
||||
loading: boolean;
|
||||
_refreshingToday: boolean;
|
||||
refreshToday: (force?: boolean) => Promise<void>;
|
||||
getTrend: (indicator: string, range: string) => Promise<{ date: string; value: number }[]>;
|
||||
clearCache: () => void;
|
||||
@@ -21,30 +22,26 @@ const CACHE_TTL = 5 * 60 * 1000;
|
||||
const TODAY_SUMMARY_TTL = 60_000;
|
||||
const MAX_TREND_KEYS = 20;
|
||||
|
||||
let refreshingToday = false;
|
||||
|
||||
export const useHealthStore = create<HealthState>((set, get) => ({
|
||||
todaySummary: null,
|
||||
todaySummaryFetchedAt: 0,
|
||||
trendData: {},
|
||||
loading: false,
|
||||
_refreshingToday: false,
|
||||
|
||||
refreshToday: async (force = false) => {
|
||||
if (refreshingToday) return;
|
||||
if (get()._refreshingToday) return;
|
||||
const state = get();
|
||||
if (!force && state.todaySummary && Date.now() - state.todaySummaryFetchedAt < TODAY_SUMMARY_TTL) {
|
||||
return;
|
||||
}
|
||||
refreshingToday = true;
|
||||
set({ loading: true });
|
||||
set({ _refreshingToday: true, loading: true });
|
||||
try {
|
||||
const patientId = Taro.getStorageSync('current_patient_id') || undefined;
|
||||
const patientId = getCachedPatientId() || undefined;
|
||||
const data = await healthApi.getTodaySummary(patientId);
|
||||
set({ todaySummary: data, todaySummaryFetchedAt: Date.now(), loading: false });
|
||||
set({ todaySummary: data, todaySummaryFetchedAt: Date.now(), loading: false, _refreshingToday: false });
|
||||
} catch {
|
||||
set({ loading: false });
|
||||
} finally {
|
||||
refreshingToday = false;
|
||||
set({ loading: false, _refreshingToday: false });
|
||||
}
|
||||
},
|
||||
|
||||
@@ -74,5 +71,5 @@ export const useHealthStore = create<HealthState>((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
clearCache: () => set({ trendData: {}, todaySummary: null, todaySummaryFetchedAt: 0 }),
|
||||
clearCache: () => set({ trendData: {}, todaySummary: null, todaySummaryFetchedAt: 0, _refreshingToday: false }),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user