fix(miniprogram): 健康阈值缓存加密 — secureGet/secureSet 替换明文 Storage (S2-2)

- getHealthThresholds 使用 AES-GCM 加密存储替代明文 Taro.getStorageSync
- 移除未使用的 Taro import
This commit is contained in:
iven
2026-05-22 08:19:31 +08:00
parent 2aa393dd65
commit b44ed6dfd2

View File

@@ -1,5 +1,5 @@
import Taro from '@tarojs/taro';
import { api, getCachedPatientId } from './request'; import { api, getCachedPatientId } from './request';
import { secureGet, secureSet } from '@/utils/secure-storage';
export interface VitalSignInput { export interface VitalSignInput {
indicator_type: string; indicator_type: string;
@@ -147,17 +147,18 @@ const THRESHOLD_TTL = 24 * 60 * 60 * 1000; // 24h
/** 从缓存或 API 获取健康阈值列表 */ /** 从缓存或 API 获取健康阈值列表 */
export async function getHealthThresholds(): Promise<HealthThreshold[]> { export async function getHealthThresholds(): Promise<HealthThreshold[]> {
try { try {
const cached = Taro.getStorageSync(THRESHOLD_CACHE_KEY) as const cachedRaw = secureGet(THRESHOLD_CACHE_KEY);
| { data: HealthThreshold[]; ts: number } if (cachedRaw) {
| undefined; const cached = JSON.parse(cachedRaw) as { data: HealthThreshold[]; ts: number };
if (cached && Date.now() - cached.ts < THRESHOLD_TTL) { if (cached && Date.now() - cached.ts < THRESHOLD_TTL) {
return cached.data; return cached.data;
}
} }
} catch { /* cache miss */ } } catch { /* cache miss */ }
try { try {
const data = await api.get<HealthThreshold[]>('/health/critical-value-thresholds/public'); const data = await api.get<HealthThreshold[]>('/health/critical-value-thresholds/public');
Taro.setStorageSync(THRESHOLD_CACHE_KEY, { data, ts: Date.now() }); secureSet(THRESHOLD_CACHE_KEY, JSON.stringify({ data, ts: Date.now() }));
return data; return data;
} catch (err) { } catch (err) {
console.warn('[health] 数据加载失败:', err); console.warn('[health] 数据加载失败:', err);