feat: 新增营养记录页面及相关组件
- 在应用中新增营养记录页面,展示用户的饮食记录 - 引入营养记录卡片组件,优化记录展示效果 - 更新路由常量,添加营养记录相关路径 - 修改布局文件,整合营养记录功能 - 优化数据加载逻辑,支持分页和日期过滤
This commit is contained in:
211
services/mockDietRecords.ts
Normal file
211
services/mockDietRecords.ts
Normal file
@@ -0,0 +1,211 @@
|
||||
import dayjs from 'dayjs';
|
||||
import { DietRecord } from './dietRecords';
|
||||
|
||||
// 模拟营养记录数据,用于测试UI效果
|
||||
export const mockDietRecords: DietRecord[] = [
|
||||
// 今天的记录
|
||||
{
|
||||
id: 1,
|
||||
mealType: 'breakfast',
|
||||
foodName: '燕麦粥配蓝莓',
|
||||
foodDescription: '有机燕麦片,新鲜蓝莓,低脂牛奶',
|
||||
weightGrams: 300,
|
||||
portionDescription: '1大碗',
|
||||
estimatedCalories: 280,
|
||||
proteinGrams: 12.5,
|
||||
carbohydrateGrams: 45.2,
|
||||
fatGrams: 6.8,
|
||||
fiberGrams: 8.5,
|
||||
sugarGrams: 15.3,
|
||||
sodiumMg: 120,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().hour(7).minute(30).toISOString(),
|
||||
imageUrl: 'https://images.unsplash.com/photo-1511690743698-d9d85f2fbf38?w=300&h=300&fit=crop',
|
||||
notes: '营养丰富的早餐,富含膳食纤维和抗氧化物质',
|
||||
createdAt: dayjs().hour(7).minute(35).toISOString(),
|
||||
updatedAt: dayjs().hour(7).minute(35).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
mealType: 'lunch',
|
||||
foodName: '鸡胸肉沙拉',
|
||||
foodDescription: '烤鸡胸肉,混合蔬菜,橄榄油调味',
|
||||
weightGrams: 250,
|
||||
portionDescription: '1份',
|
||||
estimatedCalories: 320,
|
||||
proteinGrams: 35.6,
|
||||
carbohydrateGrams: 8.4,
|
||||
fatGrams: 15.2,
|
||||
fiberGrams: 6.2,
|
||||
sugarGrams: 5.8,
|
||||
sodiumMg: 480,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().hour(12).minute(15).toISOString(),
|
||||
imageUrl: 'https://images.unsplash.com/photo-1546069901-ba9599a7e63c?w=300&h=300&fit=crop',
|
||||
notes: '高蛋白低碳水,适合健身人群',
|
||||
createdAt: dayjs().hour(12).minute(20).toISOString(),
|
||||
updatedAt: dayjs().hour(12).minute(20).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
mealType: 'snack',
|
||||
foodName: '混合坚果',
|
||||
foodDescription: '杏仁,核桃,腰果混合装',
|
||||
weightGrams: 30,
|
||||
portionDescription: '1小包',
|
||||
estimatedCalories: 180,
|
||||
proteinGrams: 6.5,
|
||||
carbohydrateGrams: 6.8,
|
||||
fatGrams: 15.5,
|
||||
fiberGrams: 3.2,
|
||||
sugarGrams: 2.1,
|
||||
sodiumMg: 5,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().hour(15).minute(30).toISOString(),
|
||||
notes: '健康的下午茶零食',
|
||||
createdAt: dayjs().hour(15).minute(35).toISOString(),
|
||||
updatedAt: dayjs().hour(15).minute(35).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
mealType: 'dinner',
|
||||
foodName: '三文鱼配蒸蔬菜',
|
||||
foodDescription: '挪威三文鱼,西兰花,胡萝卜',
|
||||
weightGrams: 350,
|
||||
portionDescription: '1份',
|
||||
estimatedCalories: 420,
|
||||
proteinGrams: 42.3,
|
||||
carbohydrateGrams: 12.5,
|
||||
fatGrams: 22.8,
|
||||
fiberGrams: 5.6,
|
||||
sugarGrams: 8.2,
|
||||
sodiumMg: 380,
|
||||
source: 'vision',
|
||||
mealTime: dayjs().hour(19).minute(0).toISOString(),
|
||||
imageUrl: 'https://images.unsplash.com/photo-1467003909585-2f8a72700288?w=300&h=300&fit=crop',
|
||||
notes: '富含Omega-3脂肪酸,有益心血管健康',
|
||||
createdAt: dayjs().hour(19).minute(10).toISOString(),
|
||||
updatedAt: dayjs().hour(19).minute(10).toISOString(),
|
||||
},
|
||||
|
||||
// 昨天的记录
|
||||
{
|
||||
id: 5,
|
||||
mealType: 'breakfast',
|
||||
foodName: '希腊酸奶杯',
|
||||
foodDescription: '无糖希腊酸奶,草莓,燕麦片',
|
||||
weightGrams: 200,
|
||||
portionDescription: '1杯',
|
||||
estimatedCalories: 220,
|
||||
proteinGrams: 20.4,
|
||||
carbohydrateGrams: 18.6,
|
||||
fatGrams: 8.2,
|
||||
fiberGrams: 4.1,
|
||||
sugarGrams: 12.5,
|
||||
sodiumMg: 85,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().subtract(1, 'day').hour(8).minute(0).toISOString(),
|
||||
imageUrl: 'https://images.unsplash.com/photo-1488477181946-6428a0291777?w=300&h=300&fit=crop',
|
||||
notes: '高蛋白早餐,饱腹感强',
|
||||
createdAt: dayjs().subtract(1, 'day').hour(8).minute(5).toISOString(),
|
||||
updatedAt: dayjs().subtract(1, 'day').hour(8).minute(5).toISOString(),
|
||||
},
|
||||
|
||||
// 更多历史记录,用于测试分页
|
||||
{
|
||||
id: 6,
|
||||
mealType: 'lunch',
|
||||
foodName: '牛肉面',
|
||||
foodDescription: '手拉面条,牛肉汤底,青菜',
|
||||
weightGrams: 400,
|
||||
portionDescription: '1碗',
|
||||
estimatedCalories: 580,
|
||||
proteinGrams: 28.0,
|
||||
carbohydrateGrams: 65.0,
|
||||
fatGrams: 18.5,
|
||||
fiberGrams: 4.8,
|
||||
sugarGrams: 6.2,
|
||||
sodiumMg: 1200,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().subtract(2, 'day').hour(13).minute(0).toISOString(),
|
||||
notes: '传统中式午餐',
|
||||
createdAt: dayjs().subtract(2, 'day').hour(13).minute(10).toISOString(),
|
||||
updatedAt: dayjs().subtract(2, 'day').hour(13).minute(10).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
mealType: 'breakfast',
|
||||
foodName: '全麦吐司配牛油果',
|
||||
foodDescription: '全麦面包,新鲜牛油果,煎蛋',
|
||||
weightGrams: 180,
|
||||
portionDescription: '2片吐司',
|
||||
estimatedCalories: 350,
|
||||
proteinGrams: 15.2,
|
||||
carbohydrateGrams: 28.5,
|
||||
fatGrams: 22.0,
|
||||
fiberGrams: 8.0,
|
||||
sugarGrams: 3.5,
|
||||
sodiumMg: 220,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().subtract(3, 'day').hour(8).minute(30).toISOString(),
|
||||
imageUrl: 'https://images.unsplash.com/photo-1541519227354-08fa5d50c44d?w=300&h=300&fit=crop',
|
||||
notes: '健康脂肪和蛋白质的完美组合',
|
||||
createdAt: dayjs().subtract(3, 'day').hour(8).minute(35).toISOString(),
|
||||
updatedAt: dayjs().subtract(3, 'day').hour(8).minute(35).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
mealType: 'dinner',
|
||||
foodName: '蒸蛋羹',
|
||||
foodDescription: '鸡蛋,温水,少许盐',
|
||||
weightGrams: 150,
|
||||
portionDescription: '1小碗',
|
||||
estimatedCalories: 140,
|
||||
proteinGrams: 12.0,
|
||||
carbohydrateGrams: 1.0,
|
||||
fatGrams: 10.0,
|
||||
fiberGrams: 0,
|
||||
sugarGrams: 1.0,
|
||||
sodiumMg: 180,
|
||||
source: 'manual',
|
||||
mealTime: dayjs().subtract(4, 'day').hour(18).minute(45).toISOString(),
|
||||
notes: '清淡易消化的晚餐',
|
||||
createdAt: dayjs().subtract(4, 'day').hour(19).minute(0).toISOString(),
|
||||
updatedAt: dayjs().subtract(4, 'day').hour(19).minute(0).toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
// 模拟API响应,支持分页和日期过滤
|
||||
export function getMockDietRecords({
|
||||
startDate,
|
||||
endDate,
|
||||
page = 1,
|
||||
limit = 10,
|
||||
}: {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
} = {}) {
|
||||
let filteredRecords = mockDietRecords;
|
||||
|
||||
// 如果有日期范围,则过滤
|
||||
if (startDate && endDate) {
|
||||
filteredRecords = mockDietRecords.filter(record => {
|
||||
const recordDate = dayjs(record.mealTime).format('YYYY-MM-DD');
|
||||
return recordDate >= startDate && recordDate <= endDate;
|
||||
});
|
||||
}
|
||||
|
||||
// 分页
|
||||
const startIndex = (page - 1) * limit;
|
||||
const endIndex = startIndex + limit;
|
||||
const paginatedRecords = filteredRecords.slice(startIndex, endIndex);
|
||||
|
||||
return {
|
||||
records: paginatedRecords,
|
||||
total: filteredRecords.length,
|
||||
page,
|
||||
limit,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user