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

@@ -68,6 +68,10 @@ export async function getDietRecords({
}>(`/users/diet-records${params}`);
}
export async function deleteDietRecord(recordId: number): Promise<void> {
await api.delete(`/users/diet-records/${recordId}`);
}
export function calculateNutritionSummary(records: DietRecord[]): NutritionSummary {
if (records?.length === 0) {
return {

View File

@@ -53,8 +53,8 @@ export const getGoalById = async (goalId: string): Promise<ApiResponse<GoalDetai
/**
* 更新目标
*/
export const updateGoal = async (goalId: string, goalData: UpdateGoalRequest): Promise<ApiResponse<Goal>> => {
return api.put<ApiResponse<Goal>>(`/goals/${goalId}`, goalData);
export const updateGoal = async (goalId: string, goalData: UpdateGoalRequest): Promise<Goal> => {
return api.put<Goal>(`/goals/${goalId}`, goalData);
};
/**
@@ -106,33 +106,6 @@ export const batchOperateGoals = async (operationData: BatchGoalOperationRequest
return api.post<ApiResponse<BatchGoalOperationResult[]>>('/goals/batch', operationData);
};
/**
* 暂停目标
*/
export const pauseGoal = async (goalId: string): Promise<ApiResponse<Goal>> => {
return updateGoal(goalId, { status: 'paused' });
};
/**
* 恢复目标
*/
export const resumeGoal = async (goalId: string): Promise<ApiResponse<Goal>> => {
return updateGoal(goalId, { status: 'active' });
};
/**
* 完成目标
*/
export const markGoalCompleted = async (goalId: string): Promise<ApiResponse<Goal>> => {
return updateGoal(goalId, { status: 'completed' });
};
/**
* 取消目标
*/
export const cancelGoal = async (goalId: string): Promise<ApiResponse<Goal>> => {
return updateGoal(goalId, { status: 'cancelled' });
};
// 导出所有API方法
export const goalsApi = {
@@ -145,10 +118,6 @@ export const goalsApi = {
getGoalCompletions,
getGoalStats,
batchOperateGoals,
pauseGoal,
resumeGoal,
markGoalCompleted,
cancelGoal,
};
export default goalsApi;