feat(notifications): 新增晚餐和心情提醒功能,支持HRV压力检测和后台处理

- 新增晚餐提醒(18:00)和心情提醒(21:00)的定时通知
- 实现基于HRV数据的压力检测和智能鼓励通知
- 添加后台任务处理支持,修改iOS后台模式为processing
- 优化营养记录页面使用Redux状态管理,支持实时数据更新
- 重构卡路里计算公式,移除目标卡路里概念,改为基代+运动-饮食
- 新增营养目标动态计算功能,基于用户身体数据智能推荐
- 完善通知点击跳转逻辑,支持多种提醒类型的路由处理
This commit is contained in:
richarjiang
2025-09-01 10:29:13 +08:00
parent fe634ba258
commit a34ca556e8
12 changed files with 867 additions and 189 deletions

View File

@@ -12,7 +12,7 @@ import { backgroundTaskManager } from '@/services/backgroundTaskManager';
import { notificationService } from '@/services/notifications';
import { store } from '@/store';
import { rehydrateUser, setPrivacyAgreed } from '@/store/userSlice';
import { NutritionNotificationHelpers } from '@/utils/notificationHelpers';
import { MoodNotificationHelpers, NutritionNotificationHelpers } from '@/utils/notificationHelpers';
import React from 'react';
import RNExitApp from 'react-native-exit-app';
@@ -45,12 +45,7 @@ function Bootstrapper({ children }: { children: React.ReactNode }) {
try {
// 初始化通知服务
await notificationService.initialize();
// 只有在用户数据加载完成后且用户名存在时才注册午餐提醒
if (userDataLoaded && profile?.name) {
await NutritionNotificationHelpers.scheduleDailyLunchReminder(profile.name);
console.log('通知服务初始化成功,午餐提醒已注册');
}
console.log('通知服务初始化成功');
} catch (error) {
console.error('通知服务初始化失败:', error);
}
@@ -70,21 +65,31 @@ function Bootstrapper({ children }: { children: React.ReactNode }) {
}
}, [userDataLoaded, privacyAgreed]);
// 当用户数据加载完成且用户名存在时,注册午餐提醒
// 当用户数据加载完成且用户名存在时,注册所有提醒
React.useEffect(() => {
const registerLunchReminder = async () => {
const registerAllReminders = async () => {
if (userDataLoaded && profile?.name) {
try {
await notificationService.initialize();
// 注册午餐提醒12:00
await NutritionNotificationHelpers.scheduleDailyLunchReminder(profile.name);
console.log('午餐提醒已注册');
// 注册晚餐提醒18:00
await NutritionNotificationHelpers.scheduleDailyDinnerReminder(profile.name);
console.log('晚餐提醒已注册');
// 注册心情提醒21:00
await MoodNotificationHelpers.scheduleDailyMoodReminder(profile.name);
console.log('心情提醒已注册');
} catch (error) {
console.error('注册午餐提醒失败:', error);
console.error('注册提醒失败:', error);
}
}
};
registerLunchReminder();
registerAllReminders();
}, [userDataLoaded, profile?.name]);
const handlePrivacyAgree = () => {