feat: 支持食物库接口
This commit is contained in:
90
types/food.ts
Normal file
90
types/food.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
// 食物库相关类型定义
|
||||
|
||||
// 后端 API 响应类型
|
||||
export interface FoodItemDto {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
caloriesPer100g?: number;
|
||||
proteinPer100g?: number;
|
||||
carbohydratePer100g?: number;
|
||||
fatPer100g?: number;
|
||||
fiberPer100g?: number;
|
||||
sugarPer100g?: number;
|
||||
sodiumPer100g?: number;
|
||||
additionalNutrition?: Record<string, any>;
|
||||
isCommon: boolean;
|
||||
imageUrl?: string;
|
||||
sortOrder?: number;
|
||||
}
|
||||
|
||||
export interface FoodCategoryDto {
|
||||
key: string;
|
||||
name: string;
|
||||
icon?: string;
|
||||
sortOrder?: number;
|
||||
isSystem: boolean;
|
||||
foods: FoodItemDto[];
|
||||
}
|
||||
|
||||
export interface FoodLibraryResponseDto {
|
||||
categories: FoodCategoryDto[];
|
||||
}
|
||||
|
||||
// 前端使用的类型(兼容现有代码)
|
||||
export interface FoodItem {
|
||||
id: string;
|
||||
name: string;
|
||||
emoji?: string;
|
||||
calories: number;
|
||||
unit: string;
|
||||
description?: string;
|
||||
protein?: number;
|
||||
carbohydrate?: number;
|
||||
fat?: number;
|
||||
fiber?: number;
|
||||
sugar?: number;
|
||||
sodium?: number;
|
||||
additionalNutrition?: Record<string, any>;
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
export interface FoodCategory {
|
||||
id: string;
|
||||
name: string;
|
||||
foods: FoodItem[];
|
||||
icon?: string;
|
||||
sortOrder?: number;
|
||||
isSystem?: boolean;
|
||||
}
|
||||
|
||||
// 已选择的食物项目
|
||||
export interface SelectedFoodItem {
|
||||
id: string;
|
||||
food: FoodItem;
|
||||
amount: number;
|
||||
unit: string;
|
||||
calories: number;
|
||||
}
|
||||
|
||||
// 餐次类型
|
||||
export type MealType = 'breakfast' | 'lunch' | 'dinner' | 'snack';
|
||||
|
||||
// 食物库状态
|
||||
export interface FoodLibraryState {
|
||||
categories: FoodCategory[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
searchResults: FoodItem[];
|
||||
searchLoading: boolean;
|
||||
lastUpdated: number | null;
|
||||
}
|
||||
|
||||
// API 请求参数
|
||||
export interface SearchFoodsParams {
|
||||
keyword: string;
|
||||
}
|
||||
|
||||
export interface GetFoodByIdParams {
|
||||
id: number;
|
||||
}
|
||||
Reference in New Issue
Block a user