feat: 增强目标管理功能及相关组件

- 在 GoalsListScreen 中新增目标编辑功能,支持用户编辑现有目标
- 更新 CreateGoalModal 组件,支持编辑模式下的目标更新
- 在 NutritionRecordsScreen 中新增删除营养记录功能,允许用户删除不需要的记录
- 更新 NutritionRecordCard 组件,增加操作选项,支持删除记录
- 修改 dietRecords 服务,添加删除营养记录的 API 调用
- 优化 goalsSlice,确保目标更新逻辑与 Redux 状态管理一致
This commit is contained in:
2025-08-26 22:34:03 +08:00
parent 0610f287ee
commit 0a8b20f0ec
8 changed files with 244 additions and 131 deletions

View File

@@ -2,7 +2,7 @@ import { NutritionRecordCard } from '@/components/NutritionRecordCard';
import { HeaderBar } from '@/components/ui/HeaderBar';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
import { DietRecord, getDietRecords } from '@/services/dietRecords';
import { DietRecord, deleteDietRecord, getDietRecords } from '@/services/dietRecords';
import { getMonthDaysZh, getMonthTitleZh, getTodayIndexInMonth } from '@/utils/date';
import { Ionicons } from '@expo/vector-icons';
import dayjs from 'dayjs';
@@ -136,6 +136,18 @@ export default function NutritionRecordsScreen() {
}
};
// 删除记录
const handleDeleteRecord = async (recordId: number) => {
try {
await deleteDietRecord(recordId);
// 从本地状态中移除已删除的记录
setRecords(prev => prev.filter(record => record.id !== recordId));
} catch (error) {
console.error('删除营养记录失败:', error);
// 可以添加错误提示
}
};
// 渲染视图模式切换器
const renderViewModeToggle = () => (
<View style={[styles.viewModeContainer, { backgroundColor: colorTokens.pageBackgroundEmphasis }]}>
@@ -275,6 +287,7 @@ export default function NutritionRecordsScreen() {
showTimeline={true}
isFirst={index === 0}
isLast={index === records.length - 1}
onDelete={() => handleDeleteRecord(item.id)}
/>
);