瀏覽代碼

详情页跳转

CuddleNan 1 天之前
父節點
當前提交
a41b8aa913

+ 69 - 82
docs/schema.md

@@ -2,7 +2,7 @@
 
 #数据范式设计
 
-您是i一名专业的数据库工程师,熟悉PostgreSQL数据库和ParseServer,请注意表名用大驼峰,字段小驼峰,有预留字段:objectId,updatedAt,createdAt。
+您是一名专业的数据库工程师,熟悉PostgreSQL数据库和ParseServer,请注意表名用大驼峰,字段小驼峰,有预留字段:objectId,updatedAt,createdAt。
 关于ParseServer中断 数据类的描述,字段主要类型有
 String => String
 Number => Number
@@ -17,7 +17,7 @@ Null => null
 GeoPoint => {latitude: 40.0, longitude: -30.0}
 
 #项目需求
-我有6种菜品分类分别是:中式菜系,西式料理,减脂轻食,甜点烘培,汤羹粥品,素食主义。还有每日推荐食谱(每日推荐3个) 还有历史浏览记录 和收藏 ,用户信息 ,AI对话(需要咨询不同的营养家) 上述需要用到表。
+我需要一个食谱推荐系统,需要有食谱表,食谱分类表(中式菜系,西式料理,减脂轻食,甜点烘培,汤羹粥品,素食主义),每日推荐(每日推荐3个)
 
 #输出结果(UML类图)
 请您帮我用plantuml的类图描述设计好的几张表及其关系
@@ -25,97 +25,84 @@ GeoPoint => {latitude: 40.0, longitude: -30.0}
 请您帮我用markmap格式表示上卖弄的信息结构图
 #输出结果(SQL语句)
 请您帮我用sql格式给我建表语句和测试数据插入语句
+我需要一个食谱推荐系统,需要有用户,食谱表,食谱分类表(中式菜系,西式料理,减脂轻食,甜点烘培,汤羹粥品,素食主义),每日推荐(每日推荐3个),AI对话,收藏,浏览记录,用户信息等功能。请您帮我设计好这些表的字段,表之间的关系,以及表之间的关系描述。
 
-#UML类图
-```plantuml
-@startuml
-!theme plain
-
-entity User {
-  +String objectId
-  +String username
-  +String password
-  +String email
-  +String avatar: Parse.File
-  +Date createdAt
-  +Date updatedAt
-}
 
-entity DishCategory {
-  +String objectId
-  +String categoryName
-  +String description
-  +Parse.File coverImage
-  +Date createdAt
-  +Date updatedAt
-}
 
-entity Recipe {
-  +String objectId
-  +String recipeName
-  +Pointer<User> creator
-  +Pointer<DishCategory> category
-  +Array<String> ingredients
-  +Array<String> steps
-  +Number cookingTime
-  +Number calorie
-  +Parse.File coverImage
-  +Array<String> tags
-  +Date createdAt
-  +Date updatedAt
-}
 
-entity UserFavorite {
-  +String objectId
-  +Pointer<User> user
-  +Pointer<Recipe> recipe
-  +Date createdAt
+#UML类图
+```plantuml
+@startuml
+' 设置全局样式
+skinparam class {
+    BackgroundColor White
+    ArrowColor #444444
+    BorderColor #444444
 }
-
-entity UserHistory {
-  +String objectId
-  +Pointer<User> user
-  +Pointer<Recipe> recipe
-  +Date viewTime
+hide circle
+
+' 实体定义
+class Recipe {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  title: String
+  imageUrl: String
+  prepTime: String
+  cookTime: String
+  difficulty: String
+  servings: Number
+  ingredients: JSON Array
+  steps: JSON Array
+  rating: Number
+  category: Pointer<RecipeCategory>
+  author: Pointer<_User>
 }
 
-entity DailyRecommendation {
-  +String objectId
-  +Date recommendDate
-  +Array<Pointer<Recipe>> recipes
-  +String recommendType
-  +Date createdAt
+class RecipeCategory {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  name: String
+  icon: String
 }
 
-entity NutritionExpert {
-  +String objectId
-  +String expertName
-  +String specialty
-  +String description
-  +Parse.File avatar
+class DailyRecommendation {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  date: Date
+  recommendedRecipes: Array<Pointer<Recipe>>
 }
 
-entity AIConversation {
-  +String objectId
-  +Pointer<User> user
-  +Pointer<NutritionExpert> expert
-  +Array<Object> chatHistory
-  +Date lastActive
-  +Date createdAt
+' 关系定义
+RecipeCategory ||--o{ Recipe : "1个分类 → 多个食谱"
+DailyRecommendation }o--|| Recipe : "每日推荐 → 多个食谱"
+Recipe ||--o| _User : "作者关系"
+
+' 系统内置用户表
+class _User {
+  objectId: String
+  username: String
+  email: String
+  createdAt: Date
+  updatedAt: Date
 }
 
-' Relationships
-User ||--o{ UserFavorite : has
-User ||--o{ UserHistory : generates
-User ||--o{ AIConversation : initiates
-
-DishCategory ||--o{ Recipe : contains
-
-Recipe ||--o{ UserFavorite : in
-Recipe ||--o{ UserHistory : viewed_in
-Recipe ||--o{ DailyRecommendation : featured_in
-
-NutritionExpert ||--o{ AIConversation : participates_in
-
+' 样式调整
+note top of Recipe
+  **字段说明**
+  ingredients格式示例:
+  [{"name":"意大利面","amount":"400g"},...]
+  steps格式示例:
+  ["步骤1描述","步骤2描述",...]
+end note
+
+note right of DailyRecommendation
+  每日存储推荐记录
+  通过date字段实现历史推荐查询
+  推荐逻辑需通过云函数实现
+end note
 @enduml
-```
+
+```

+ 125 - 0
myapp/src/app/tab1/README.md

@@ -0,0 +1,125 @@
+#AI智能食谱推荐助手
+
+#数据范式设计
+
+您是一名专业的数据库工程师,熟悉PostgreSQL数据库和ParseServer,请注意表名用大驼峰,字段小驼峰,有预留字段:objectId,updatedAt,createdAt。
+关于ParseServer中断 数据类的描述,字段主要类型有
+String => String
+Number => Number
+Bool => bool
+Array => JSON Array
+Object => JSON Object
+Date => Date
+File => Parse.File
+Pointer => other Parse.Object
+Relation => Parse.Relation
+Null => null
+GeoPoint => {latitude: 40.0, longitude: -30.0}
+
+#项目需求
+我需要一个食谱推荐系统,需要有食谱表,食谱分类表(中式菜系,西式料理,减脂轻食,甜点烘培,汤羹粥品,素食主义),每日推荐(每日推荐3个)
+
+#UML类图
+```plantuml
+@startuml
+' 设置全局样式
+skinparam class {
+    BackgroundColor White
+    ArrowColor #444444
+    BorderColor #444444
+}
+hide circle
+
+' 实体定义
+class Recipe {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  title: String
+  imageUrl: String
+  prepTime: String
+  cookTime: String
+  difficulty: String
+  servings: Number
+  ingredients: JSON Array
+  steps: JSON Array
+  rating: Number
+  category: Pointer<RecipeCategory>
+  author: Pointer<_User>
+}
+
+class RecipeCategory {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  name: String
+  icon: String
+}
+
+class DailyRecommendation {
+  objectId: String
+  createdAt: Date
+  updatedAt: Date
+  date: Date
+  recommendedRecipes: Array<Pointer<Recipe>>
+}
+
+' 关系定义
+RecipeCategory ||--o{ Recipe : "1个分类 → 多个食谱"
+DailyRecommendation }o--|| Recipe : "每日推荐 → 多个食谱"
+Recipe ||--o| _User : "作者关系"
+
+' 系统内置用户表
+class _User {
+  objectId: String
+  username: String
+  email: String
+  createdAt: Date
+  updatedAt: Date
+}
+
+' 样式调整
+note top of Recipe
+  **字段说明**
+  ingredients格式示例:
+  [{"name":"意大利面","amount":"400g"},...]
+  steps格式示例:
+  ["步骤1描述","步骤2描述",...]
+end note
+
+note right of DailyRecommendation
+  每日存储推荐记录
+  通过date字段实现历史推荐查询
+  推荐逻辑需通过云函数实现
+end note
+@enduml
+```
+
+这个设计包含以下核心要素:
+
+1. **Recipe(食谱主表)**
+- 包含详细的食谱元数据(烹饪时间、难度等)
+- 使用JSON Array存储结构化数据(食材列表和步骤说明)
+- 通过Pointer关联分类和作者
+
+2. **RecipeCategory(分类表)**
+- 预置6大分类类型
+- 通过icon字段支持前端图标展示
+
+3. **DailyRecommendation(每日推荐表)**
+- 按日期存储推荐记录
+- 使用Pointer数组关联当日推荐的3个食谱
+
+4. **扩展性设计**
+- 内置用户系统(_User表)支持用户相关功能扩展
+- 评分字段为推荐算法留出扩展空间
+- 通过云函数可实现智能推荐逻辑
+
+建议配合Parse Server的afterSave云函数实现:
+- 每日定时生成推荐
+- 自动维护推荐关联
+- 评分自动更新等业务逻辑
+```
+
+创建测试数据 导入数据
+

+ 400 - 0
myapp/src/app/tab1/import-recipe-data.ts

@@ -0,0 +1,400 @@
+import { CloudObject } from "src/lib/ncloud";
+
+
+// 食谱分类数据生成
+async function seedRecipeCategories() {
+  const categories = [
+    { name: '中式菜系', icon: 'utensils' },
+    { name: '西式料理', icon: 'fork-knife' },
+    { name: '减脂轻食', icon: 'carrot' },
+    { name: '甜点烘焙', icon: 'cake' },
+    { name: '汤羹粥品', icon: 'bowl' },
+    { name: '素食主义', icon: 'leaf' }
+  ];
+
+  const createdCategories = [];
+  
+  for (const category of categories) {
+    const categoryObj = new CloudObject('RecipeCategory');
+    categoryObj.set(category);
+    await categoryObj.save();
+    createdCategories.push(categoryObj);
+    console.log(`Created category: ${category.name}`);
+  }
+
+  return createdCategories;
+}
+
+// 食谱数据生成
+async function seedRecipes(categories: CloudObject[]) {
+  const recipes = [
+    // 减脂轻食类
+  {
+    title: '香煎鸡胸肉配时蔬',
+    imageUrl: '/assets/food/jxr.jpg',
+    description: '低脂高蛋白的健身餐首选,鸡胸肉嫩滑多汁,搭配新鲜时蔬,营养均衡且美味',
+    prepTime: '10分钟',
+    cookTime: '20分钟',
+    difficulty: '简单',
+    servings: 2,
+    rating: 4.8,
+    ingredients: [
+      { name: '鸡胸肉', amount: '300g' },
+      { name: '西兰花', amount: '200g' },
+      { name: '胡萝卜', amount: '1根' },
+      { name: '橄榄油', amount: '2汤匙' },
+      { name: '盐和黑胡椒', amount: '适量' }
+    ],
+    steps: [
+      '鸡胸肉用盐和黑胡椒腌制10分钟',
+      '西兰花和胡萝卜切小块焯水',
+      '平底锅加热橄榄油,放入鸡胸肉煎至两面金黄',
+      '加入蔬菜翻炒均匀即可'
+    ],
+    category: categories.find(c => c.get('name') === '减脂轻食')
+  },
+  {
+    title: '藜麦蔬菜沙拉',
+    imageUrl: '/assets/food/lmssl.jpg',
+    description: '超级食物藜麦与新鲜蔬菜的完美组合,富含膳食纤维和植物蛋白',
+    prepTime: '15分钟',
+    cookTime: '15分钟',
+    difficulty: '简单',
+    servings: 2,
+    rating: 4.6,
+    ingredients: [
+      { name: '藜麦', amount: '100g' },
+      { name: '樱桃番茄', amount: '10颗' },
+      { name: '黄瓜', amount: '1根' },
+      { name: '柠檬汁', amount: '2汤匙' },
+      { name: '橄榄油', amount: '1汤匙' }
+    ],
+    steps: [
+      '藜麦煮熟后放凉',
+      '蔬菜洗净切丁',
+      '混合所有食材',
+      '加入柠檬汁和橄榄油拌匀'
+    ],
+    category: categories.find(c => c.get('name') === '减脂轻食')
+  },
+
+  // 西式料理类
+  {
+    title: '奶油蘑菇意面',
+    imageUrl: '/assets/food/nymg.jpg',
+    description: '经典意大利风味,奶油香浓,蘑菇鲜美,搭配弹牙意面口感绝佳',
+    prepTime: '15分钟',
+    cookTime: '30分钟',
+    difficulty: '中等',
+    servings: 2,
+    rating: 4.9,
+    ingredients: [
+      { name: '意大利面', amount: '250g' },
+      { name: '蘑菇', amount: '200g' },
+      { name: '淡奶油', amount: '200ml' },
+      { name: '大蒜', amount: '3瓣' },
+      { name: '帕玛森奶酪', amount: '适量' }
+    ],
+    steps: [
+      '意大利面按包装说明煮熟',
+      '大蒜切末,蘑菇切片',
+      '锅中加热橄榄油,炒香蒜末',
+      '加入蘑菇炒至软化',
+      '倒入淡奶油煮至浓稠',
+      '拌入煮好的意面,撒上奶酪'
+    ],
+    category: categories.find(c => c.get('name') === '西式料理')
+  },
+  {
+    title: '经典牛排配薯泥',
+    imageUrl: '/assets/food/np.jpg',
+    description: '三分熟完美牛排搭配绵密土豆泥,高端餐厅级别的家庭料理',
+    prepTime: '20分钟',
+    cookTime: '15分钟',
+    difficulty: '中等',
+    servings: 2,
+    rating: 4.7,
+    ingredients: [
+      { name: '牛排', amount: '2块(约300g)' },
+      { name: '土豆', amount: '500g' },
+      { name: '黄油', amount: '50g' },
+      { name: '迷迭香', amount: '2枝' },
+      { name: '海盐', amount: '适量' }
+    ],
+    steps: [
+      '牛排室温回温,两面撒盐',
+      '土豆煮熟压成泥,加入黄油',
+      '高温煎锅煎牛排,每面2分钟',
+      '加入迷迭香提香',
+      '静置5分钟后切片'
+    ],
+    category: categories.find(c => c.get('name') === '西式料理')
+  },
+
+  // 中式菜系类
+  {
+    title: '红烧肉',
+    imageUrl: '/assets/food/hsr.jpg',
+    description: '经典本帮菜,肥而不腻,入口即化,酱香浓郁的家常美味',
+    prepTime: '20分钟',
+    cookTime: '90分钟',
+    difficulty: '中等',
+    servings: 4,
+    rating: 4.7,
+    ingredients: [
+      { name: '五花肉', amount: '500g' },
+      { name: '生姜', amount: '1块' },
+      { name: '八角', amount: '2颗' },
+      { name: '老抽', amount: '2汤匙' },
+      { name: '冰糖', amount: '30g' }
+    ],
+    steps: [
+      '五花肉切块焯水',
+      '锅中放少量油,加入冰糖炒至融化',
+      '放入肉块翻炒上色',
+      '加入生姜、八角和适量水',
+      '小火炖煮1小时至肉质酥烂'
+    ],
+    category: categories.find(c => c.get('name') === '中式菜系')
+  },
+  {
+    title: '宫保鸡丁',
+    imageUrl: '/assets/food/gbjd.jpg',
+    description: '川菜经典,鸡肉嫩滑,花生香脆,麻辣酸甜的完美平衡',
+    prepTime: '15分钟',
+    cookTime: '10分钟',
+    difficulty: '中等',
+    servings: 3,
+    rating: 4.8,
+    ingredients: [
+      { name: '鸡胸肉', amount: '400g' },
+      { name: '花生米', amount: '100g' },
+      { name: '干辣椒', amount: '10个' },
+      { name: '花椒', amount: '1茶匙' },
+      { name: '生抽', amount: '2汤匙' }
+    ],
+    steps: [
+      '鸡肉切丁腌制',
+      '花生米炸至金黄',
+      '爆香辣椒和花椒',
+      '快速翻炒鸡丁',
+      '加入调味汁收干'
+    ],
+    category: categories.find(c => c.get('name') === '中式菜系')
+  },
+
+  // 甜点烘焙类
+  {
+    title: '提拉米苏',
+    imageUrl: '/assets/food/tlms.jpg',
+    description: '意大利经典甜点,咖啡酒香与马斯卡彭奶酪的完美融合,口感层次丰富',
+    prepTime: '30分钟',
+    cookTime: '0分钟',
+    difficulty: '中等',
+    servings: 6,
+    rating: 4.9,
+    ingredients: [
+      { name: '马斯卡彭奶酪', amount: '250g' },
+      { name: '手指饼干', amount: '200g' },
+      { name: '浓缩咖啡', amount: '100ml' },
+      { name: '鸡蛋', amount: '3个' },
+      { name: '可可粉', amount: '适量' }
+    ],
+    steps: [
+      '蛋黄加糖打发,拌入马斯卡彭奶酪',
+      '蛋白打发后拌入奶酪糊',
+      '手指饼干蘸咖啡液铺在容器底部',
+      '铺一层奶酪糊,重复一层饼干一层奶酪',
+      '冷藏4小时,撒可可粉'
+    ],
+    category: categories.find(c => c.get('name') === '甜点烘焙')
+  },
+  {
+    title: '巧克力熔岩蛋糕',
+    imageUrl: '/assets/food/qklry.jpg',
+    description: '外酥内软的巧克力甜点,切开后热巧克力浆缓缓流出,视觉与味觉的双重享受',
+    prepTime: '20分钟',
+    cookTime: '12分钟',
+    difficulty: '中等',
+    servings: 4,
+    rating: 4.9,
+    ingredients: [
+      { name: '黑巧克力', amount: '200g' },
+      { name: '黄油', amount: '100g' },
+      { name: '鸡蛋', amount: '3个' },
+      { name: '细砂糖', amount: '80g' },
+      { name: '低筋面粉', amount: '50g' }
+    ],
+    steps: [
+      '巧克力和黄油隔水融化',
+      '鸡蛋和糖打发至蓬松',
+      '混合巧克力液和蛋糊',
+      '筛入面粉轻轻拌匀',
+      '倒入模具210°C烤12分钟'
+    ],
+    category: categories.find(c => c.get('name') === '甜点烘焙')
+  },
+
+  // 汤羹粥品类
+  {
+    title: '番茄蛋花汤',
+    imageUrl: '/assets/food/fqdh.jpg',
+    description: '家常快手汤品,酸甜开胃,蛋花柔滑,五分钟即可完成的营养美味',
+    prepTime: '5分钟',
+    cookTime: '10分钟',
+    difficulty: '简单',
+    servings: 4,
+    rating: 4.5,
+    ingredients: [
+      { name: '番茄', amount: '2个' },
+      { name: '鸡蛋', amount: '2个' },
+      { name: '葱花', amount: '适量' },
+      { name: '盐', amount: '适量' }
+    ],
+    steps: [
+      '番茄切块,鸡蛋打散',
+      '水烧开放入番茄煮软',
+      '慢慢倒入蛋液形成蛋花',
+      '加盐调味,撒葱花'
+    ],
+    category: categories.find(c => c.get('name') === '汤羹粥品')
+  },
+  {
+    title: '皮蛋瘦肉粥',
+    imageUrl: '/assets/food/pdsrz.jpg',
+    description: '广式经典粥品,米粒开花绵密,皮蛋Q弹,肉丝鲜嫩,早餐夜宵皆宜',
+    prepTime: '10分钟',
+    cookTime: '40分钟',
+    difficulty: '简单',
+    servings: 4,
+    rating: 4.7,
+    ingredients: [
+      { name: '大米', amount: '150g' },
+      { name: '皮蛋', amount: '2个' },
+      { name: '猪里脊', amount: '100g' },
+      { name: '姜丝', amount: '适量' },
+      { name: '白胡椒粉', amount: '少许' }
+    ],
+    steps: [
+      '大米浸泡30分钟后煮粥',
+      '肉丝用调料腌制',
+      '皮蛋切块',
+      '粥煮至绵密时加入配料',
+      '再煮10分钟调味'
+    ],
+    category: categories.find(c => c.get('name') === '汤羹粥品')
+  },
+
+  // 素食主义类
+  {
+    title: '素食沙拉',
+    imageUrl: '/assets/food/ssl.jpg',
+    description: '清新爽口的全素沙拉,多种蔬菜搭配柠檬油醋汁,健康低卡无负担',
+    prepTime: '15分钟',
+    cookTime: '0分钟',
+    difficulty: '简单',
+    servings: 2,
+    rating: 4.6,
+    ingredients: [
+      { name: '生菜', amount: '100g' },
+      { name: '黄瓜', amount: '1根' },
+      { name: '樱桃番茄', amount: '10个' },
+      { name: '橄榄油', amount: '2汤匙' },
+      { name: '柠檬汁', amount: '1汤匙' }
+    ],
+    steps: [
+      '所有蔬菜洗净切块',
+      '混合橄榄油和柠檬汁制成酱汁',
+      '将酱汁淋在蔬菜上拌匀'
+    ],
+    category: categories.find(c => c.get('name') === '素食主义')
+  },
+  {
+    title: '素三鲜豆腐',
+    imageUrl: '/assets/food/ssxd.jpg',
+    description: '植物蛋白丰富的素食料理,豆腐外焦里嫩,搭配三种时令鲜蔬',
+    prepTime: '15分钟',
+    cookTime: '15分钟',
+    difficulty: '简单',
+    servings: 3,
+    rating: 4.5,
+    ingredients: [
+      { name: '老豆腐', amount: '1块' },
+      { name: '香菇', amount: '5朵' },
+      { name: '胡萝卜', amount: '1根' },
+      { name: '青椒', amount: '1个' },
+      { name: '素蚝油', amount: '2汤匙' }
+    ],
+    steps: [
+      '豆腐切块煎至两面金黄',
+      '蔬菜切片炒至断生',
+      '加入豆腐和调味料',
+      '小火焖煮5分钟'
+    ],
+    category: categories.find(c => c.get('name') === '素食主义')
+  }
+  ];
+
+  const createdRecipes = [];
+  
+  for (const recipe of recipes) {
+    const recipeObj = new CloudObject('Recipe');
+    const recipeData = {
+      ...recipe,
+      category: recipe.category?.toPointer()
+    };
+    recipeObj.set(recipeData);
+    await recipeObj.save();
+    createdRecipes.push(recipeObj);
+    console.log(`Created recipe: ${recipe.title}`);
+  }
+
+  return createdRecipes;
+}
+
+// 每日推荐数据生成
+async function seedDailyRecommendations(recipes: CloudObject[]) {
+  // 获取最近7天的日期
+  const dates = [];
+  for (let i = 0; i < 7; i++) {
+    const date = new Date();
+    date.setDate(date.getDate() - i);
+    dates.push(date);
+  }
+
+  for (const date of dates) {
+    // 随机选择3个食谱
+    const shuffled = [...recipes].sort(() => 0.5 - Math.random());
+    const recommended = shuffled.slice(0, 3).map(r => r.toPointer());
+    
+    const recommendation = new CloudObject('DailyRecommendation');
+    recommendation.set({
+      date: date.toISOString(),
+      recommendedRecipes: recommended
+    });
+    
+    await recommendation.save();
+    console.log(`Created recommendation for ${date.toLocaleDateString()}`);
+  }
+}
+
+// 主导入函数
+export async function importAllData() {
+  try {
+    console.log('Starting data import...');
+    
+    // 1. 先导入分类
+    const categories = await seedRecipeCategories();
+    
+    // 2. 导入食谱数据
+    const recipes = await seedRecipes(categories);
+    
+    // 3. 生成每日推荐
+    await seedDailyRecommendations(recipes);
+    
+    console.log('Data import completed successfully!');
+  } catch (error) {
+    console.error('Error during data import:', error);
+  }
+}
+

+ 13 - 10
myapp/src/app/tab1/page-detail/page-detail.page.html

@@ -10,20 +10,20 @@
 <ion-content [fullscreen]="true">
   <!-- 菜品图片 -->
   <div class="recipe-image-container">
-    <img [src]="recipe?.imageUrl" [alt]="recipe?.title" class="recipe-image">
+    <img [src]="recipe?.get('imageUrl')" [alt]="recipe?.get('title')" class="recipe-image">
     <div class="image-overlay">
-      <ion-chip color="primary">{{ recipe?.category }}</ion-chip>
-      <ion-chip color="dark">{{ recipe?.cookTime }}</ion-chip>
+      <ion-chip color="primary">{{ recipe?.get('category')}}</ion-chip>
+      <ion-chip color="dark">{{ recipe?.get('cookTime') }}</ion-chip>
     </div>
   </div>
 
   <!-- 菜品名称 -->
   <div class="recipe-header">
-    <h1 class="recipe-title">{{ recipe?.title }}</h1>
+    <h1 class="recipe-title">{{ recipe?.get('title') }}</h1>
     <div class="recipe-meta">
-      <span class="meta-item"><ion-icon name="time-outline"></ion-icon> {{ recipe?.prepTime }} 准备</span>
-      <span class="meta-item"><ion-icon name="flame-outline"></ion-icon> {{ recipe?.difficulty }}</span>
-      <span class="meta-item"><ion-icon name="people-outline"></ion-icon> {{ recipe?.servings }} 人份</span>
+      <span class="meta-item"><ion-icon name="time-outline"></ion-icon> {{ recipe?.get('prepTime') }} 准备</span>
+      <span class="meta-item"><ion-icon name="flame-outline"></ion-icon> {{ recipe?.get('difficulty') }}</span>
+      <span class="meta-item"><ion-icon name="people-outline"></ion-icon> {{ recipe?.get('servings') }} 人份</span>
     </div>
   </div>
 
@@ -37,7 +37,7 @@
     </ion-card-header>
     <ion-card-content>
       <ion-list lines="none">
-        <ion-item *ngFor="let ingredient of recipe?.ingredients">
+        <ion-item *ngFor="let ingredient of recipe?.get('ingredients')">
           <ion-label>{{ ingredient.name }}</ion-label>
           <ion-note slot="end" color="primary">{{ ingredient.amount }}</ion-note>
         </ion-item>
@@ -46,7 +46,7 @@
   </ion-card>
 
   <!-- 操作步骤 -->
-  <ion-card class="section-card">
+  <ion-card class="section-card" *ngIf="recipe">
     <ion-card-header>
       <ion-card-title>
         <ion-icon name="restaurant-outline" slot="start"></ion-icon>
@@ -55,7 +55,10 @@
     </ion-card-header>
     <ion-card-content>
       <ion-list lines="none">
-        <ion-item *ngFor="let step of recipe?.steps; let i = index" class="step-item">
+        <ion-item 
+          *ngFor="let step of recipe?.get('steps'); let i = index" 
+          class="step-item"
+        >
           <ion-avatar slot="start" class="step-number">
             {{ i + 1 }}
           </ion-avatar>

+ 59 - 43
myapp/src/app/tab1/page-detail/page-detail.page.ts

@@ -1,8 +1,10 @@
+import { CommonModule } from '@angular/common';
 import { Component, OnInit } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 import { IonBackButton, IonButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonChip, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonNote, IonThumbnail, IonTitle, IonToolbar } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
 import { basketOutline, restaurantOutline, timeOutline, flameOutline, peopleOutline } from 'ionicons/icons';
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
 interface Ingredient {
   name: string;
@@ -26,58 +28,72 @@ interface Recipe {
   selector: 'app-page-detail',
   templateUrl: './page-detail.page.html',
   styleUrls: ['./page-detail.page.scss'],
-  standalone: false,
+  //imports:[CommonModule],
+  standalone: false
   // imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, IonButtons, IonButton, IonIcon, 
   //           IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonList, IonItem, IonLabel, IonNote, IonChip]
 })
 export class PageDetailPage implements OnInit {
-  recipe: Recipe | null = null;
+  //recipe: Recipe | null = null;
 
-  constructor(private route: ActivatedRoute) {
+  constructor(
+    private route: ActivatedRoute
+  ) {
     addIcons({ basketOutline, restaurantOutline, timeOutline, flameOutline, peopleOutline });
+    this.route.params.subscribe(params => {
+     console.log(params) ;
+     this.loadRecipe(params['recipeId']);
+    })
   }
+  recipe : CloudObject | undefined |null;
 
-  ngOnInit() {
-    // 模拟从路由参数获取菜谱ID并加载数据
-    const recipeId = this.route.snapshot.paramMap.get('id');
-    this.loadRecipe(recipeId);
+  async loadRecipe(recipeId: string) {
+    let query = new CloudQuery("Recipe");
+    this.recipe = await query.get(recipeId);
+    console.log(this.recipe);
   }
 
-  loadRecipe(id: string | null) {
-    // 这里应该是从API获取数据,暂时使用模拟数据
-    this.recipe = {
-      id: 1,
-      title: '经典意大利肉酱面',
-      imageUrl: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
-      category: '意大利菜',
-      prepTime: '20分钟',
-      cookTime: '1小时',
-      difficulty: '中等',
-      servings: 4,
-      ingredients: [
-        { name: '意大利面', amount: '400g' },
-        { name: '牛肉末', amount: '300g' },
-        { name: '洋葱', amount: '1个' },
-        { name: '胡萝卜', amount: '1根' },
-        { name: '芹菜', amount: '1根' },
-        { name: '大蒜', amount: '3瓣' },
-        { name: '番茄酱', amount: '2汤匙' },
-        { name: '红酒', amount: '100ml' },
-        { name: '橄榄油', amount: '2汤匙' },
-        { name: '盐和黑胡椒', amount: '适量' },
-        { name: '帕玛森奶酪', amount: '装饰用' }
-      ],
-      steps: [
-        '将洋葱、胡萝卜和芹菜切碎成小丁,大蒜切末备用。',
-        '在大锅中加热橄榄油,加入切碎的蔬菜炒至软化,约5分钟。',
-        '加入牛肉末,用中火翻炒至变色,约8-10分钟。',
-        '倒入红酒,煮至酒精挥发,约2分钟。',
-        '加入番茄酱和适量的水,调至小火慢炖45分钟,期间偶尔搅拌。',
-        '在另一个锅中煮意大利面,根据包装指示时间减1分钟。',
-        '将煮好的面条沥干,保留一杯面水。',
-        '将面条加入肉酱中,加入少量面水搅拌至酱汁浓稠裹满意面。',
-        '用盐和黑胡椒调味,撒上帕玛森奶酪即可享用。'
-      ]
-    };
+  ngOnInit() {
+    // 模拟从路由参数获取菜谱ID并加载数据
+    // const recipeId = this.route.snapshot.paramMap.get('id');
+    //this.loadRecipe(recipeId);
   }
+  //预设数据
+  // loadRecipe(id: string | null) {
+  //   // 这里应该是从API获取数据,暂时使用模拟数据
+  //   this.recipe = {
+  //     id: 1,
+  //     title: '经典意大利肉酱面',
+  //     imageUrl: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
+  //     category: '意大利菜',
+  //     prepTime: '20分钟',
+  //     cookTime: '1小时',
+  //     difficulty: '中等',
+  //     servings: 4,
+  //     ingredients: [
+  //       { name: '意大利面', amount: '400g' },
+  //       { name: '牛肉末', amount: '300g' },
+  //       { name: '洋葱', amount: '1个' },
+  //       { name: '胡萝卜', amount: '1根' },
+  //       { name: '芹菜', amount: '1根' },
+  //       { name: '大蒜', amount: '3瓣' },
+  //       { name: '番茄酱', amount: '2汤匙' },
+  //       { name: '红酒', amount: '100ml' },
+  //       { name: '橄榄油', amount: '2汤匙' },
+  //       { name: '盐和黑胡椒', amount: '适量' },
+  //       { name: '帕玛森奶酪', amount: '装饰用' }
+  //     ],
+  //     steps: [
+  //       '将洋葱、胡萝卜和芹菜切碎成小丁,大蒜切末备用。',
+  //       '在大锅中加热橄榄油,加入切碎的蔬菜炒至软化,约5分钟。',
+  //       '加入牛肉末,用中火翻炒至变色,约8-10分钟。',
+  //       '倒入红酒,煮至酒精挥发,约2分钟。',
+  //       '加入番茄酱和适量的水,调至小火慢炖45分钟,期间偶尔搅拌。',
+  //       '在另一个锅中煮意大利面,根据包装指示时间减1分钟。',
+  //       '将煮好的面条沥干,保留一杯面水。',
+  //       '将面条加入肉酱中,加入少量面水搅拌至酱汁浓稠裹满意面。',
+  //       '用盐和黑胡椒调味,撒上帕玛森奶酪即可享用。'
+  //     ]
+  //   };
+  // }
 }

+ 8 - 6
myapp/src/app/tab1/page-type/page-type.page.html

@@ -7,19 +7,21 @@
   </ion-toolbar>
 </ion-header>
 
+
 <ion-content [fullscreen]="true">
   <ion-list>
     <ion-item 
-      *ngFor="let recipe of recipes" 
-      [routerLink]="['/recipe-detail', recipe.id]"
-      detail="true" (click) = "goToDetail()">
+      *ngFor="let recipe of recipeList" 
+      [routerLink]="['/recipe-detail', recipe.get('objectId')]"
+      detail="true" (click)="goToDetail(recipe)">
       <ion-thumbnail slot="start">
-        <img [src]="recipe.imageUrl" [alt]="recipe.title">
+        <img [src]="recipe.get('imageUrl')" [alt]="recipe.get('title')">
       </ion-thumbnail>
       <ion-label>
-        <h2>{{ recipe.title }}</h2>
-        <p *ngIf="recipe.description">{{ recipe.description }}</p>
+        <h2>{{ recipe.get('title') }}</h2>
+        <p *ngIf="recipe.get('description')">{{ recipe.get('description') }}</p>
       </ion-label>
     </ion-item>
   </ion-list>
+  <button (click)="importRecipeList()">导入食谱列表数据</button>
 </ion-content>

+ 19 - 2
myapp/src/app/tab1/page-type/page-type.page.ts

@@ -2,6 +2,8 @@ import { Component, OnInit } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 import { NavController } from '@ionic/angular';
 import { IonBackButton, IonButtons, IonContent, IonHeader, IonItem, IonLabel, IonList, IonThumbnail, IonTitle, IonToolbar } from '@ionic/angular/standalone';
+import { importAllData } from '../import-recipe-data';
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
 interface Recipe {
   id: number;
@@ -31,8 +33,23 @@ export class PageTypePage implements OnInit {
     
     // 加载该分类下的菜品数据
     this.loadRecipes();
+    this.loadRecipeList();
   }
 
+  importRecipeList() {
+    importAllData();
+  }
+  recipeList : Array<CloudObject> = [];
+  recipeCategoryList : Array<CloudObject> = [];
+  DailyRecommendationList : Array<CloudObject> = [];
+  async loadRecipeList(){
+    let query1 = new CloudQuery("Recipe");
+    this.recipeList = await query1.find(); 
+    let query2 = new CloudQuery("RecipeCategory");
+    this.recipeCategoryList = await query1.find(); 
+    let query3 = new CloudQuery("DailyRecommendation");
+    this.DailyRecommendationList = await query1.find(); 
+  }
   loadRecipes() {
     // 模拟数据 - 实际应用中应该从API获取
     this.recipes = [
@@ -79,8 +96,8 @@ export class PageTypePage implements OnInit {
     ];
   }
 
-  goToDetail() {
-    this.navCtrl.navigateForward(["tabs","tab1","page-detail"]);
+  goToDetail(recipe : CloudObject) {
+    this.navCtrl.navigateForward(["tabs","tab1","page-detail",recipe.id]);
     console.log('Navigating to page-detail');
   }
 }

+ 1 - 1
myapp/src/app/tab1/tab1-routing.module.ts

@@ -16,7 +16,7 @@ const routes: Routes = [
     loadChildren: () => import('./page-type/page-type.module').then( m => m.PageTypePageModule)
   },
   {
-    path: 'page-detail',
+    path: 'page-detail/:recipeId',
     loadChildren: () => import('./page-detail/page-detail.module').then( m => m.PageDetailPageModule)
   },