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,4 +1,4 @@
|
||||
import { useRef, useCallback } from 'react';
|
||||
import { useRef, useState, useCallback } from 'react';
|
||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
||||
|
||||
interface UsePageDataOptions {
|
||||
@@ -22,6 +22,7 @@ export function usePageData(
|
||||
const enabled = options?.enabled ?? true;
|
||||
|
||||
const loadingRef = useRef(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const lastRunRef = useRef(0);
|
||||
const fetcherRef = useRef(fetcher);
|
||||
fetcherRef.current = fetcher;
|
||||
@@ -30,11 +31,13 @@ export function usePageData(
|
||||
if (!enabled || loadingRef.current) return;
|
||||
if (!force && Date.now() - lastRunRef.current < throttleMs) return;
|
||||
loadingRef.current = true;
|
||||
setLoading(true);
|
||||
lastRunRef.current = Date.now();
|
||||
try {
|
||||
await fetcherRef.current();
|
||||
} finally {
|
||||
loadingRef.current = false;
|
||||
setLoading(false);
|
||||
}
|
||||
}, [enabled, throttleMs]);
|
||||
|
||||
@@ -49,11 +52,13 @@ export function usePageData(
|
||||
const refresh = useCallback(async () => {
|
||||
if (loadingRef.current) return;
|
||||
loadingRef.current = true;
|
||||
setLoading(true);
|
||||
lastRunRef.current = Date.now();
|
||||
try {
|
||||
await fetcherRef.current();
|
||||
} finally {
|
||||
loadingRef.current = false;
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -66,5 +71,5 @@ export function usePageData(
|
||||
}
|
||||
});
|
||||
|
||||
return { loading: loadingRef.current, refresh, trigger };
|
||||
return { loading, refresh, trigger };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user