feat(medical): 添加医疗免责声明和参考文献功能

- 在用药模块首次添加时显示医疗免责声明弹窗
- 新增断食参考文献页面,展示权威医学机构来源
- 在个人中心添加WHO医学来源入口
- 使用本地存储记录用户已读免责声明状态
- 支持Liquid Glass毛玻璃效果和降级方案
- 新增中英文国际化翻译支持
This commit is contained in:
richarjiang
2025-11-14 09:14:12 +08:00
parent b0e93eedae
commit 6ad77bc0e2
7 changed files with 726 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ import {
import { Ionicons } from '@expo/vector-icons';
import { useFocusEffect } from '@react-navigation/native';
import dayjs from 'dayjs';
import { GlassView, isLiquidGlassAvailable } from 'expo-glass-effect';
import { useRouter } from 'expo-router';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
@@ -592,6 +593,38 @@ export default function FastingTabScreen() {
activePlanId={activePlan?.id ?? currentPlan?.id}
onSelectPlan={handleSelectPlan}
/>
{/* 参考文献入口 */}
<View style={styles.referencesSection}>
<TouchableOpacity
style={styles.referencesButton}
onPress={() => router.push(ROUTES.FASTING_REFERENCES)}
activeOpacity={0.8}
>
{isLiquidGlassAvailable() ? (
<GlassView
style={styles.referencesGlass}
glassEffectStyle="clear"
tintColor="rgba(46, 49, 66, 0.05)"
isInteractive={true}
>
<View style={styles.referencesContent}>
<Ionicons name="library-outline" size={20} color="#2E3142" />
<Text style={styles.referencesText}></Text>
<Ionicons name="chevron-forward" size={16} color="#6F7D87" />
</View>
</GlassView>
) : (
<View style={[styles.referencesGlass, styles.referencesFallback]}>
<View style={styles.referencesContent}>
<Ionicons name="library-outline" size={20} color="#2E3142" />
<Text style={styles.referencesText}></Text>
<Ionicons name="chevron-forward" size={16} color="#6F7D87" />
</View>
</View>
)}
</TouchableOpacity>
</View>
</ScrollView>
<FastingStartPickerModal
@@ -766,4 +799,34 @@ const styles = StyleSheet.create({
fontWeight: '600',
color: '#2E3142',
},
referencesSection: {
marginTop: 24,
marginBottom: 20,
},
referencesButton: {
borderRadius: 20,
overflow: 'hidden',
},
referencesGlass: {
borderRadius: 20,
paddingVertical: 16,
paddingHorizontal: 20,
},
referencesFallback: {
backgroundColor: 'rgba(246, 248, 250, 0.8)',
borderWidth: 1,
borderColor: 'rgba(46, 49, 66, 0.1)',
},
referencesContent: {
flexDirection: 'row',
alignItems: 'center',
},
referencesText: {
flex: 1,
fontSize: 16,
fontWeight: '600',
color: '#2E3142',
marginLeft: 12,
marginRight: 8,
},
});

View File

@@ -3,12 +3,14 @@ import { DateSelector } from '@/components/DateSelector';
import { MedicationCard } from '@/components/medication/MedicationCard';
import { ThemedText } from '@/components/ThemedText';
import { IconSymbol } from '@/components/ui/IconSymbol';
import { MedicalDisclaimerSheet } from '@/components/ui/MedicalDisclaimerSheet';
import { Colors } from '@/constants/Colors';
import { useAppDispatch, useAppSelector } from '@/hooks/redux';
import { useColorScheme } from '@/hooks/useColorScheme';
import { medicationNotificationService } from '@/services/medicationNotifications';
import { fetchMedicationRecords, fetchMedications, selectMedicationDisplayItemsByDate } from '@/store/medicationsSlice';
import { DEFAULT_MEMBER_NAME } from '@/store/userSlice';
import { getItemSync, setItemSync } from '@/utils/kvStore';
import { convertMedicationDataToWidget, refreshWidget, syncMedicationDataToWidget } from '@/utils/widgetDataSync';
import { useFocusEffect } from '@react-navigation/native';
import dayjs, { Dayjs } from 'dayjs';
@@ -29,6 +31,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
dayjs.locale('zh-cn');
// 本地存储键名:医疗免责声明已读状态
const MEDICAL_DISCLAIMER_READ_KEY = 'medical_disclaimer_read';
type MedicationFilter = 'all' | 'taken' | 'missed';
type ThemeColors = (typeof Colors)[keyof typeof Colors];
@@ -46,15 +51,37 @@ export default function MedicationsScreen() {
const celebrationRef = useRef<CelebrationAnimationRef>(null);
const celebrationTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const [isCelebrationVisible, setIsCelebrationVisible] = useState(false);
const [disclaimerVisible, setDisclaimerVisible] = useState(false);
// 从 Redux 获取数据
const selectedKey = selectedDate.format('YYYY-MM-DD');
const medicationsForDay = useAppSelector((state) => selectMedicationDisplayItemsByDate(selectedKey)(state));
const handleOpenAddMedication = useCallback(() => {
// 检查是否已经读过免责声明
const hasRead = getItemSync(MEDICAL_DISCLAIMER_READ_KEY);
if (hasRead === 'true') {
// 已读过,直接跳转
router.push('/medications/add-medication');
} else {
// 未读过,显示医疗免责声明弹窗
setDisclaimerVisible(true);
}
}, []);
const handleDisclaimerConfirm = useCallback(() => {
// 用户同意免责声明后,记录已读状态,关闭弹窗并跳转到添加页面
setItemSync(MEDICAL_DISCLAIMER_READ_KEY, 'true');
setDisclaimerVisible(false);
router.push('/medications/add-medication');
}, []);
const handleDisclaimerClose = useCallback(() => {
// 用户不接受免责声明,只关闭弹窗,不跳转,不记录已读状态
setDisclaimerVisible(false);
}, []);
const handleOpenMedicationManagement = useCallback(() => {
router.push('/medications/manage-medications');
}, []);
@@ -328,6 +355,13 @@ export default function MedicationsScreen() {
</View>
)}
</ScrollView>
{/* 医疗免责声明弹窗 */}
<MedicalDisclaimerSheet
visible={disclaimerVisible}
onClose={handleDisclaimerClose}
onConfirm={handleDisclaimerConfirm}
/>
</View>
);
}

View File

@@ -435,6 +435,16 @@ export default function PersonalScreen() {
},
],
},
{
title: t('personal.sections.medicalSources'),
items: [
{
icon: 'medkit-outline' as React.ComponentProps<typeof Ionicons>['name'],
title: t('personal.menu.whoSource'),
onPress: () => Linking.openURL('https://www.who.int'),
},
],
},
{
title: t('personal.language.title'),
items: [

300
app/fasting/references.tsx Normal file
View File

@@ -0,0 +1,300 @@
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
import { Ionicons } from '@expo/vector-icons';
import { GlassView, isLiquidGlassAvailable } from 'expo-glass-effect';
import { useRouter } from 'expo-router';
import React from 'react';
import { Linking, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
// 参考文献数据
const references = [
{
id: 5,
name: '中国国家卫生健康委员会(国家卫健委)',
englishName: 'National Health Commission of the People\'s Republic of China',
url: 'http://www.nhc.gov.cn',
note: '(用于中文用户环境非常合适)',
},
{
id: 1,
name: '美国国立卫生研究院NIH',
englishName: 'National Institutes of Health',
url: 'https://www.nih.gov',
},
{
id: 3,
name: '世界卫生组织WHO',
englishName: 'World Health Organization',
url: 'https://www.who.int',
},
{
id: 6,
name: '中国营养学会Chinese Nutrition Society',
englishName: 'Chinese Nutrition Society',
url: 'https://www.cnsoc.org',
},
];
export default function FastingReferencesScreen() {
const router = useRouter();
const insets = useSafeAreaInsets();
const theme = useColorScheme() ?? 'light';
const colors = Colors[theme];
const glassAvailable = isLiquidGlassAvailable();
const handleBack = () => {
router.back();
};
const handleLinkPress = async (url: string) => {
try {
const canOpen = await Linking.canOpenURL(url);
if (canOpen) {
await Linking.openURL(url);
} else {
console.log('无法打开链接:', url);
}
} catch (error) {
console.error('打开链接时发生错误:', error);
}
};
return (
<View style={[styles.safeArea, { backgroundColor: '#ffffff' }]}>
{/* 固定悬浮的返回按钮 */}
<View style={[styles.backButtonContainer, { paddingTop: insets.top + 12 }]}>
<TouchableOpacity style={styles.backButton} onPress={handleBack} activeOpacity={0.8}>
{glassAvailable ? (
<GlassView
style={styles.backButtonGlass}
glassEffectStyle="regular"
tintColor="rgba(255,255,255,0.4)"
isInteractive={true}
>
<Ionicons name="chevron-back" size={24} color="#2E3142" />
</GlassView>
) : (
<View style={styles.backButtonFallback}>
<Ionicons name="chevron-back" size={24} color="#2E3142" />
</View>
)}
</TouchableOpacity>
</View>
<ScrollView
contentContainerStyle={[
styles.scrollContainer,
{ paddingTop: insets.top + 80 }
]}
showsVerticalScrollIndicator={false}
>
<View style={styles.headerSection}>
<Text style={styles.title}></Text>
<Text style={styles.subtitle}>
</Text>
</View>
<View style={styles.referencesList}>
{references.map((reference) => (
<View key={reference.id} style={styles.referenceCard}>
<View style={styles.referenceHeader}>
<View style={styles.referenceIcon}>
<Ionicons name="medical-outline" size={24} color="#2E3142" />
</View>
<View style={styles.referenceInfo}>
<Text style={styles.referenceName}>{reference.name}</Text>
<Text style={styles.referenceEnglishName}>{reference.englishName}</Text>
</View>
</View>
<TouchableOpacity
style={styles.referenceLink}
onPress={() => handleLinkPress(reference.url)}
activeOpacity={0.8}
>
<Text style={styles.referenceUrl}>{reference.url}</Text>
<Ionicons name="open-outline" size={16} color="#6F7D87" />
</TouchableOpacity>
{reference.note && (
<Text style={styles.referenceNote}>{reference.note}</Text>
)}
</View>
))}
</View>
<View style={styles.disclaimerSection}>
<View style={styles.disclaimerHeader}>
<Ionicons name="information-circle-outline" size={20} color="#6F7D87" />
<Text style={styles.disclaimerTitle}></Text>
</View>
<Text style={styles.disclaimerText}>
怀
</Text>
</View>
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
backButtonContainer: {
position: 'absolute',
top: 0,
left: 24,
zIndex: 10,
},
backButton: {
width: 44,
height: 44,
borderRadius: 22,
alignItems: 'center',
justifyContent: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 4,
},
shadowOpacity: 0.15,
shadowRadius: 8,
elevation: 8,
},
backButtonGlass: {
width: 44,
height: 44,
borderRadius: 22,
alignItems: 'center',
justifyContent: 'center',
borderWidth: 1,
borderColor: 'rgba(255,255,255,0.3)',
overflow: 'hidden',
},
backButtonFallback: {
width: 44,
height: 44,
borderRadius: 22,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(255,255,255,0.85)',
borderWidth: 1,
borderColor: 'rgba(255,255,255,0.5)',
},
scrollContainer: {
paddingHorizontal: 24,
paddingBottom: 40,
},
headerSection: {
alignItems: 'center',
marginBottom: 32,
},
title: {
fontSize: 28,
fontWeight: '800',
color: '#2E3142',
marginBottom: 12,
textAlign: 'center',
},
subtitle: {
fontSize: 16,
color: '#6F7D87',
textAlign: 'center',
lineHeight: 24,
paddingHorizontal: 20,
},
referencesList: {
marginBottom: 32,
},
referenceCard: {
backgroundColor: '#FFFFFF',
borderRadius: 20,
padding: 20,
marginBottom: 16,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 8,
},
shadowOpacity: 0.06,
shadowRadius: 16,
elevation: 4,
},
referenceHeader: {
flexDirection: 'row',
alignItems: 'flex-start',
marginBottom: 12,
},
referenceIcon: {
width: 48,
height: 48,
borderRadius: 24,
backgroundColor: 'rgba(46, 49, 66, 0.08)',
alignItems: 'center',
justifyContent: 'center',
marginRight: 16,
},
referenceInfo: {
flex: 1,
},
referenceName: {
fontSize: 16,
fontWeight: '700',
color: '#2E3142',
marginBottom: 4,
},
referenceEnglishName: {
fontSize: 14,
color: '#6F7D87',
lineHeight: 20,
},
referenceLink: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: 'rgba(111, 125, 135, 0.08)',
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 12,
marginBottom: 8,
},
referenceUrl: {
fontSize: 14,
color: '#2E3142',
flex: 1,
},
referenceNote: {
fontSize: 13,
color: '#8A96A3',
fontStyle: 'italic',
lineHeight: 18,
},
disclaimerSection: {
backgroundColor: 'rgba(255, 248, 225, 0.6)',
borderRadius: 20,
padding: 20,
borderWidth: 1,
borderColor: 'rgba(255, 193, 7, 0.2)',
},
disclaimerHeader: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 12,
},
disclaimerTitle: {
fontSize: 16,
fontWeight: '700',
color: '#2E3142',
marginLeft: 8,
},
disclaimerText: {
fontSize: 14,
color: '#5B6572',
lineHeight: 22,
},
});