fix(miniprogram): 健康阈值缓存加密 — secureGet/secureSet 替换明文 Storage (S2-2)
- getHealthThresholds 使用 AES-GCM 加密存储替代明文 Taro.getStorageSync - 移除未使用的 Taro import
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
import { api, getCachedPatientId } from './request';
|
||||
import { secureGet, secureSet } from '@/utils/secure-storage';
|
||||
|
||||
export interface VitalSignInput {
|
||||
indicator_type: string;
|
||||
@@ -147,17 +147,18 @@ const THRESHOLD_TTL = 24 * 60 * 60 * 1000; // 24h
|
||||
/** 从缓存或 API 获取健康阈值列表 */
|
||||
export async function getHealthThresholds(): Promise<HealthThreshold[]> {
|
||||
try {
|
||||
const cached = Taro.getStorageSync(THRESHOLD_CACHE_KEY) as
|
||||
| { data: HealthThreshold[]; ts: number }
|
||||
| undefined;
|
||||
if (cached && Date.now() - cached.ts < THRESHOLD_TTL) {
|
||||
return cached.data;
|
||||
const cachedRaw = secureGet(THRESHOLD_CACHE_KEY);
|
||||
if (cachedRaw) {
|
||||
const cached = JSON.parse(cachedRaw) as { data: HealthThreshold[]; ts: number };
|
||||
if (cached && Date.now() - cached.ts < THRESHOLD_TTL) {
|
||||
return cached.data;
|
||||
}
|
||||
}
|
||||
} catch { /* cache miss */ }
|
||||
|
||||
try {
|
||||
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;
|
||||
} catch (err) {
|
||||
console.warn('[health] 数据加载失败:', err);
|
||||
|
||||
Reference in New Issue
Block a user