From b44ed6dfd2e36311259cdd3a8272d167fccd96de Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 22 May 2026 08:19:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(miniprogram):=20=E5=81=A5=E5=BA=B7=E9=98=88?= =?UTF-8?q?=E5=80=BC=E7=BC=93=E5=AD=98=E5=8A=A0=E5=AF=86=20=E2=80=94=20sec?= =?UTF-8?q?ureGet/secureSet=20=E6=9B=BF=E6=8D=A2=E6=98=8E=E6=96=87=20Stora?= =?UTF-8?q?ge=20(S2-2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getHealthThresholds 使用 AES-GCM 加密存储替代明文 Taro.getStorageSync - 移除未使用的 Taro import --- apps/miniprogram/src/services/health.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/miniprogram/src/services/health.ts b/apps/miniprogram/src/services/health.ts index 8d7b108..4e996f8 100644 --- a/apps/miniprogram/src/services/health.ts +++ b/apps/miniprogram/src/services/health.ts @@ -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 { 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('/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);