feat: 更新统计页面,优化HRV数据展示和逻辑
- 移除模拟HRV数据,改为从健康数据中获取实际HRV值 - 新增HRV更新时间显示,提升用户信息获取体验 - 优化日期推导逻辑,确保数据加载一致性 - 更新BMI卡片和营养雷达图组件,支持紧凑模式展示 - 移除不再使用的图片资源,简化项目结构
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import { useAuthGuard } from '@/hooks/useAuthGuard';
|
||||
import {
|
||||
BMI_CATEGORIES,
|
||||
canCalculateBMI,
|
||||
getBMIResult,
|
||||
type BMIResult
|
||||
BMI_CATEGORIES,
|
||||
canCalculateBMI,
|
||||
getBMIResult,
|
||||
type BMIResult
|
||||
} from '@/utils/bmi';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Dimensions,
|
||||
Modal,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View
|
||||
Dimensions,
|
||||
Modal,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View
|
||||
} from 'react-native';
|
||||
import Toast from 'react-native-toast-message';
|
||||
|
||||
@@ -24,9 +24,10 @@ interface BMICardProps {
|
||||
weight?: number;
|
||||
height?: number;
|
||||
style?: any;
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
export function BMICard({ weight, height, style }: BMICardProps) {
|
||||
export function BMICard({ weight, height, style, compact = false }: BMICardProps) {
|
||||
const { pushIfAuthedElseLogin } = useAuthGuard();
|
||||
const [showInfoModal, setShowInfoModal] = useState(false);
|
||||
|
||||
@@ -61,14 +62,75 @@ export function BMICard({ weight, height, style }: BMICardProps) {
|
||||
if (!canCalculate) {
|
||||
// 缺少数据的情况
|
||||
return (
|
||||
<View style={styles.incompleteContent}>
|
||||
<TouchableOpacity
|
||||
style={[styles.incompleteContent, compact && styles.compactIncompleteContent]}
|
||||
onPress={handleShowInfoModal}
|
||||
activeOpacity={0.8}
|
||||
>
|
||||
<View style={styles.cardHeader}>
|
||||
<View style={styles.titleRow}>
|
||||
<View style={styles.iconSquare}>
|
||||
<Ionicons name="fitness-outline" size={18} color="#192126" />
|
||||
<Ionicons name="fitness-outline" size={16} color="#192126" />
|
||||
</View>
|
||||
<Text style={styles.cardTitle}>BMI 指数</Text>
|
||||
<Text style={[styles.cardTitle, compact && styles.compactTitle]}>BMI</Text>
|
||||
</View>
|
||||
{!compact && (
|
||||
<TouchableOpacity
|
||||
onPress={handleShowInfoModal}
|
||||
style={styles.infoButton}
|
||||
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||
>
|
||||
<Ionicons name="information-circle-outline" size={20} color="#9AA3AE" />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{compact ? (
|
||||
<View style={styles.compactMissingData}>
|
||||
<Text style={styles.compactMissingText}>
|
||||
{!weight && !height ? '完善身高体重' :
|
||||
!weight ? '完善体重' : '完善身高'}
|
||||
</Text>
|
||||
</View>
|
||||
) : (
|
||||
<>
|
||||
<View style={styles.missingDataContainer}>
|
||||
<Ionicons name="alert-circle-outline" size={24} color="#F59E0B" />
|
||||
<Text style={styles.missingDataText}>
|
||||
{!weight && !height ? '请完善身高和体重信息' :
|
||||
!weight ? '请完善体重信息' : '请完善身高信息'}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={handleGoToProfile}
|
||||
style={styles.completeButton}
|
||||
activeOpacity={0.8}
|
||||
>
|
||||
<Text style={styles.completeButtonText}>前往完善</Text>
|
||||
<Ionicons name="chevron-forward" size={16} color="#6B7280" />
|
||||
</TouchableOpacity>
|
||||
</>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
||||
// 有完整数据的情况
|
||||
return (
|
||||
<TouchableOpacity
|
||||
style={[styles.completeContent, { backgroundColor: bmiResult?.backgroundColor }, compact && styles.compactCompleteContent]}
|
||||
onPress={handleShowInfoModal}
|
||||
activeOpacity={0.8}
|
||||
>
|
||||
<View style={styles.cardHeader}>
|
||||
<View style={styles.titleRow}>
|
||||
<View style={styles.iconSquare}>
|
||||
<Ionicons name="fitness-outline" size={16} color="#192126" />
|
||||
</View>
|
||||
<Text style={[styles.cardTitle, compact && styles.compactTitle]}>BMI</Text>
|
||||
</View>
|
||||
{!compact && (
|
||||
<TouchableOpacity
|
||||
onPress={handleShowInfoModal}
|
||||
style={styles.infoButton}
|
||||
@@ -76,66 +138,41 @@ export function BMICard({ weight, height, style }: BMICardProps) {
|
||||
>
|
||||
<Ionicons name="information-circle-outline" size={20} color="#9AA3AE" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
<View style={styles.missingDataContainer}>
|
||||
<Ionicons name="alert-circle-outline" size={24} color="#F59E0B" />
|
||||
<Text style={styles.missingDataText}>
|
||||
{!weight && !height ? '请完善身高和体重信息' :
|
||||
!weight ? '请完善体重信息' : '请完善身高信息'}
|
||||
{compact ? (
|
||||
<View style={styles.compactBMIContent}>
|
||||
<Text style={[styles.compactBMIValue, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.value}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={handleGoToProfile}
|
||||
style={styles.completeButton}
|
||||
activeOpacity={0.8}
|
||||
>
|
||||
<Text style={styles.completeButtonText}>前往完善</Text>
|
||||
<Ionicons name="chevron-forward" size={16} color="#6B7280" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
// 有完整数据的情况
|
||||
return (
|
||||
<View style={[styles.completeContent, { backgroundColor: bmiResult?.backgroundColor }]}>
|
||||
<View style={styles.cardHeader}>
|
||||
<View style={styles.titleRow}>
|
||||
<View style={styles.iconSquare}>
|
||||
<Ionicons name="fitness-outline" size={18} color="#192126" />
|
||||
</View>
|
||||
<Text style={styles.cardTitle}>BMI 指数</Text>
|
||||
</View>
|
||||
<TouchableOpacity
|
||||
onPress={handleShowInfoModal}
|
||||
style={styles.infoButton}
|
||||
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||
>
|
||||
<Ionicons name="information-circle-outline" size={20} color="#9AA3AE" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<View style={styles.bmiValueContainer}>
|
||||
<Text style={[styles.bmiValue, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.value}
|
||||
</Text>
|
||||
<View style={[styles.categoryBadge, { backgroundColor: bmiResult?.color + '20' }]}>
|
||||
<Text style={[styles.categoryText, { color: bmiResult?.color }]}>
|
||||
<Text style={[styles.compactBMICategory, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.category.name}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
) : (
|
||||
<>
|
||||
<View style={styles.bmiValueContainer}>
|
||||
<Text style={[styles.bmiValue, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.value}
|
||||
</Text>
|
||||
<View style={[styles.categoryBadge, { backgroundColor: bmiResult?.color + '20' }]}>
|
||||
<Text style={[styles.categoryText, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.category.name}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<Text style={[styles.bmiDescription, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.description}
|
||||
</Text>
|
||||
<Text style={[styles.bmiDescription, { color: bmiResult?.color }]}>
|
||||
{bmiResult?.description}
|
||||
</Text>
|
||||
|
||||
<Text style={styles.encouragementText}>
|
||||
{bmiResult?.category.encouragement}
|
||||
</Text>
|
||||
</View>
|
||||
<Text style={styles.encouragementText}>
|
||||
{bmiResult?.category.encouragement}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -359,6 +396,46 @@ const styles = StyleSheet.create({
|
||||
fontStyle: 'italic',
|
||||
},
|
||||
|
||||
// 紧凑模式样式
|
||||
compactIncompleteContent: {
|
||||
minHeight: 110,
|
||||
padding: 14,
|
||||
margin: -14,
|
||||
},
|
||||
compactCompleteContent: {
|
||||
minHeight: 110,
|
||||
padding: 14,
|
||||
margin: -14,
|
||||
},
|
||||
compactTitle: {
|
||||
fontSize: 14,
|
||||
},
|
||||
compactMissingData: {
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flex: 1,
|
||||
},
|
||||
compactMissingText: {
|
||||
fontSize: 12,
|
||||
color: '#9AA3AE',
|
||||
fontWeight: '500',
|
||||
textAlign: 'center',
|
||||
},
|
||||
compactBMIContent: {
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flex: 1,
|
||||
},
|
||||
compactBMIValue: {
|
||||
fontSize: 28,
|
||||
fontWeight: '800',
|
||||
marginBottom: 4,
|
||||
},
|
||||
compactBMICategory: {
|
||||
fontSize: 12,
|
||||
fontWeight: '700',
|
||||
},
|
||||
|
||||
// 弹窗样式
|
||||
modalBackdrop: {
|
||||
flex: 1,
|
||||
|
||||
Reference in New Issue
Block a user