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

@@ -195,7 +195,7 @@ export const updateGoal = createAsyncThunk(
async ({ goalId, goalData }: { goalId: string; goalData: UpdateGoalRequest }, { rejectWithValue }) => {
try {
const response = await goalsApi.updateGoal(goalId, goalData);
return response.data;
return response;
} catch (error: any) {
return rejectWithValue(error.message || '更新目标失败');
}
@@ -457,10 +457,7 @@ const goalsSlice = createSlice({
state.updateLoading = false;
const updatedGoal = action.payload;
// 计算进度百分比
const progressPercentage = updatedGoal.targetCount && updatedGoal.targetCount > 0
? Math.round((updatedGoal.completedCount / updatedGoal.targetCount) * 100)
: 0;
console.log('updateGoal.fulfilled', updatedGoal);
// 更新目标列表中的目标
const goalIndex = state.goals.findIndex(goal => goal.id === updatedGoal.id);
@@ -468,7 +465,6 @@ const goalsSlice = createSlice({
state.goals[goalIndex] = {
...state.goals[goalIndex],
...updatedGoal,
progressPercentage,
};
}
@@ -477,7 +473,6 @@ const goalsSlice = createSlice({
state.currentGoal = {
...state.currentGoal,
...updatedGoal,
progressPercentage,
};
}
})