import { useState, useEffect } from 'react'; import { View, Text } from '@tarojs/components'; import { useRouter } from '@tarojs/taro'; import { useHealthStore } from '@/stores/health'; import TrendChart from '@/components/TrendChart'; import './index.scss'; const RANGE_OPTIONS = [ { value: '7d', label: '7天' }, { value: '30d', label: '30天' }, { value: '90d', label: '90天' }, ]; const INDICATOR_META: Record = { blood_pressure_systolic: { label: '收缩压', unit: 'mmHg', refMin: 90, refMax: 140 }, blood_pressure_diastolic: { label: '舒张压', unit: 'mmHg', refMin: 60, refMax: 90 }, heart_rate: { label: '心率', unit: 'bpm', refMin: 60, refMax: 100 }, blood_sugar_fasting: { label: '空腹血糖', unit: 'mmol/L', refMin: 3.9, refMax: 6.1 }, blood_sugar_postprandial: { label: '餐后血糖', unit: 'mmol/L', refMin: 3.9, refMax: 7.8 }, weight: { label: '体重', unit: 'kg' }, }; export default function Trend() { const router = useRouter(); const indicator = router.params.indicator || 'heart_rate'; const [range, setRange] = useState('7d'); const [points, setPoints] = useState<{ date: string; value: number }[]>([]); const { getTrend } = useHealthStore(); useEffect(() => { getTrend(indicator, range).then(setPoints); }, [indicator, range]); const meta = INDICATOR_META[indicator] || { label: indicator, unit: '' }; return ( {meta.label} 趋势 {RANGE_OPTIONS.map((opt) => ( setRange(opt.value)} > {opt.label} ))} {/* ECharts 折线图 */} {/* 数据列表 */} {points.length > 0 && ( {points.slice().reverse().map((p, i) => ( {p.date} {p.value}{meta.unit ? ` ${meta.unit}` : ''} ))} )} ); }