feat(mp): Phase 2 功能补全 — SOS+推送+趋势图tooltip+家属安全存储

- index: 添加 SOS 紧急求助悬浮按钮(仅患者可见)
- alerts: 告警页面添加微信推送订阅 + critical 推送标识
- TrendChart: 添加触摸 tooltip 显示日期和数值
- family: edit_patient 改用 secureSet/secureGet 安全存储
This commit is contained in:
iven
2026-05-21 16:24:40 +08:00
parent 6338cd7428
commit 4e9eb7b397
8 changed files with 159 additions and 6 deletions

View File

@@ -45,3 +45,21 @@
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
// ── Tooltip ──
.trend-tooltip {
position: absolute;
transform: translateX(-50%);
background: rgba(15, 23, 42, 0.9);
padding: 6px 12px;
border-radius: 6px;
white-space: nowrap;
pointer-events: none;
z-index: 10;
}
.trend-tooltip-text {
font-size: 12px;
color: #fff;
}

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useCallback } from 'react';
import React, { useEffect, useRef, useCallback, useState } from 'react';
import { Canvas, View, Text } from '@tarojs/components';
import Taro from '@tarojs/taro';
import './index.scss';
@@ -41,6 +41,7 @@ export default React.memo(function TrendChart({
height = 500,
}: TrendChartProps) {
const canvasRef = useRef<any>(null);
const [tooltip, setTooltip] = useState<{ date: string; value: number; x: number } | null>(null);
const draw = useCallback(() => {
const node = canvasRef.current;
@@ -150,6 +151,26 @@ export default React.memo(function TrendChart({
ctx.restore();
}, [data, referenceMin, referenceMax]);
const handleTouchStart = useCallback((e: any) => {
if (!data || data.length === 0 || !canvasRef.current) return;
const touch = e.touches[0];
const node = canvasRef.current;
const dpr = getDPR();
const x = touch.x;
const w = node.width / dpr;
const pad = { left: 45, right: 15 };
const cw = w - pad.left - pad.right;
const relX = x - pad.left;
const idx = Math.round((relX / cw) * (data.length - 1));
if (idx >= 0 && idx < data.length) {
setTooltip({
date: data[idx].date,
value: data[idx].value,
x: pad.left + (idx / Math.max(data.length - 1, 1)) * cw,
});
}
}, [data]);
useEffect(() => {
const query = Taro.createSelectorQuery();
query
@@ -181,7 +202,18 @@ export default React.memo(function TrendChart({
type='2d'
id='trend-chart-canvas'
style={{ width: '100%', height: '100%' }}
onTouchStart={handleTouchStart}
/>
{tooltip && (
<View
className='trend-tooltip'
style={{ left: `${tooltip.x}px`, top: '8px' }}
>
<Text className='trend-tooltip-text'>
{tooltip.date}: {tooltip.value}{unit ? ` ${unit}` : ''}
</Text>
</View>
)}
</View>
);
});