CuddleNan пре 2 дана
родитељ
комит
acb3c0a0ac

+ 0 - 1
docs/info-map.md

@@ -4,7 +4,6 @@
 - User
   - username: String
   - password: String
-  - email: String
   - avatar: Parse.File
   - → 收藏(UserFavorite)
   - → 浏览历史(UserHistory)

+ 253 - 59
docs/schema.md

@@ -32,77 +32,271 @@ GeoPoint => {latitude: 40.0, longitude: -30.0}
 
 #UML类图
 ```plantuml
-@startuml
-' 设置全局样式
-skinparam class {
-    BackgroundColor White
-    ArrowColor #444444
-    BorderColor #444444
+@startuml AI智能食谱推荐助手数据库结构
+
+class User {
+  + objectId: String
+  + username: String
+  + password: String
+  + email: String
+  + avatar: Parse.File
+  + createdAt: Date
+  + updatedAt: Date
+}
+
+class DishCategory {
+  + objectId: String
+  + categoryName: String
+  + description: String
+  + coverImage: Parse.File
+  + createdAt: Date
+  + updatedAt: Date
 }
-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>
+  + objectId: String
+  + recipeName: String
+  + ingredients: [String]
+  + steps: [String]
+  + cookingTime: Number
+  + calorie: Number
+  + coverImage: Parse.File
+  + tags: [String]
+  + createdAt: Date
+  + updatedAt: Date
+}
+
+class UserFavorite {
+  + objectId: String
+  + createdAt: Date
+  + updatedAt: Date
 }
 
-class RecipeCategory {
-  objectId: String
-  createdAt: Date
-  updatedAt: Date
-  name: String
-  icon: String
+class UserHistory {
+  + objectId: String
+  + viewTime: Date
+  + createdAt: Date
+  + updatedAt: Date
 }
 
 class DailyRecommendation {
-  objectId: String
-  createdAt: Date
-  updatedAt: Date
-  date: Date
-  recommendedRecipes: Array<Pointer<Recipe>>
+  + objectId: String
+  + recommendDate: Date
+  + recommendType: String
+  + createdAt: Date
+  + updatedAt: Date
 }
 
-' 关系定义
-RecipeCategory ||--o{ Recipe : "1个分类 → 多个食谱"
-DailyRecommendation }o--|| Recipe : "每日推荐 → 多个食谱"
-Recipe ||--o| _User : "作者关系"
-
-' 系统内置用户表
-class _User {
-  objectId: String
-  username: String
-  email: String
-  createdAt: Date
-  updatedAt: Date
+class NutritionExpert {
+  + objectId: String
+  + expertName: String
+  + specialty: String
+  + description: String
+  + avatar: Parse.File
+  + createdAt: Date
+  + updatedAt: Date
+}
+
+class AIConversation {
+  + objectId: String
+  + chatHistory: [Object]
+  + lastActive: Date
+  + createdAt: Date
+  + updatedAt: Date
 }
 
-' 样式调整
-note top of Recipe
-  **字段说明**
-  ingredients格式示例:
-  [{"name":"意大利面","amount":"400g"},...]
-  steps格式示例:
-  ["步骤1描述","步骤2描述",...]
-end note
-
-note right of DailyRecommendation
-  每日存储推荐记录
-  通过date字段实现历史推荐查询
-  推荐逻辑需通过云函数实现
-end note
+' 关系定义
+User "1" *-- "many" UserFavorite : has
+Recipe "1" *-- "many" UserFavorite : isFavoritedBy
+
+User "1" *-- "many" UserHistory : has
+Recipe "1" *-- "many" UserHistory : isViewedBy
+
+DishCategory "1" *-- "many" Recipe : contains
+
+DailyRecommendation "1" *-- "3" Recipe : recommends
+
+User "1" *-- "many" AIConversation : has
+NutritionExpert "1" *-- "many" AIConversation : participatesIn
+
 @enduml
 
 ```
+
+#UML时序图
+#登录时序图
+```plantuml
+@startuml 用户登录登出时序图(简化版)
+
+actor 用户
+participant "登录界面" as UI
+participant "认证控制器" as AuthCtrl
+participant "用户服务" as UserService
+
+== 登录流程 ==
+用户 -> UI : 点击"一键登录"
+UI -> AuthCtrl : requestQuickLogin()
+AuthCtrl -> UserService : verifyDeviceToken()
+alt 验证成功
+    UserService --> AuthCtrl : 返回用户数据\n(objectId,username,avatar)
+    AuthCtrl -> UI : redirectToHome()
+    UI -> 用户 : 显示主界面
+else 验证失败
+    UserService --> AuthCtrl : 返回错误码\n(401)
+    AuthCtrl -> UI : showToast("登录失效")
+    UI -> 用户 : 停留登录页
+end
+
+== 登出流程 ==
+用户 -> UI : 点击"退出"按钮
+UI -> AuthCtrl : triggerLogout()
+AuthCtrl -> UserService : clearAuthToken()
+UserService --> AuthCtrl : 操作成功(200)
+AuthCtrl -> UI : resetLoginState()
+UI -> 用户 : 跳转至登录页
+
+@enduml
+```
+
+#食谱浏览时序图
+```plantuml
+@startuml 食谱浏览时序图
+
+actor 用户
+participant "浏览界面" as UI
+participant "食谱控制器" as RecipeCtrl
+participant "食谱服务" as RecipeService
+database "分类数据库" as CategoryDB
+
+== 分类浏览 ==
+用户 -> UI : 选择分类标签
+UI -> RecipeCtrl : loadByCategory(categoryId)
+RecipeCtrl -> CategoryDB : getRecipes(categoryId)
+CategoryDB --> RecipeCtrl : List<Recipe>
+RecipeCtrl -> UI : renderRecipeCards()
+UI -> 用户 : 显示分类食谱
+
+== 模糊搜索 ==
+用户 -> UI : 输入关键词
+UI -> RecipeCtrl : search(keyword)
+RecipeCtrl -> RecipeService : fuzzySearch(keyword)
+RecipeService --> RecipeCtrl : List<Recipe>
+RecipeCtrl -> UI : renderSearchResults()
+UI -> 用户 : 显示搜索结果
+
+@enduml
+```
+#每日推荐时序图
+```plantuml
+@startuml 每日推荐时序图
+
+actor 用户
+participant "推荐界面" as UI
+participant "推荐控制器" as RecCtrl
+participant "推荐引擎" as RecEngine
+database "用户画像" as UserProfile
+
+用户 -> UI : 点击"今日推荐"
+UI -> RecCtrl : getDailyRecommendations()
+RecCtrl -> UserProfile : getUserPreferences()
+UserProfile --> RecCtrl : 用户偏好数据
+RecCtrl -> RecEngine : generateRecommendations()
+RecEngine --> RecCtrl : [Recipe1, Recipe2, Recipe3]
+RecCtrl -> UI : displayRecipes()
+UI -> 用户 : 展示3个推荐菜谱
+
+@enduml
+```
+
+#AI营养咨询时序图
+```plantuml
+@startuml AI营养咨询时序图
+
+actor 用户
+participant "咨询界面" as UI
+participant "咨询控制器" as AICtrl
+participant "AI服务" as AIService
+database "专家数据库" as ExpertDB
+
+== 选择营养师 ==
+用户 -> UI : 进入咨询页
+UI -> AICtrl : loadAvailableExperts()
+AICtrl -> ExpertDB : getAllExperts()
+ExpertDB --> AICtrl : List<NutritionExpert>
+AICtrl -> UI : showExpertSelection()
+UI -> 用户 : 显示专家列表
+
+== 咨询对话 ==
+用户 -> UI : 选择专家并提问
+UI -> AICtrl : sendQuestion(question, expertId)
+AICtrl -> AIService : processQuestion(question, expertId)
+AIService -> AIService : 生成营养建议
+AIService --> AICtrl : AIResponse
+AICtrl -> UI : updateChatHistory()
+UI -> 用户 : 显示AI回复
+
+@enduml
+```
+
+#用户收藏时序图
+```plantuml
+@startuml 用户历史记录查看时序图
+
+actor 用户
+participant "我的页面" as MyPage
+participant "历史记录页面" as HistoryPage
+participant "食谱详情页" as DetailPage
+participant "历史记录控制器" as HistoryCtrl
+participant "食谱服务" as RecipeService
+
+== 历史记录浏览 ==
+用户 -> MyPage : 点击"历史记录"
+MyPage -> HistoryCtrl : 请求历史记录列表
+HistoryCtrl -> RecipeService : 获取用户浏览历史(userId)
+RecipeService --> HistoryCtrl : 返回[Recipe1,Recipe2,...]
+HistoryCtrl -> HistoryPage : 渲染历史列表
+HistoryPage -> 用户 : 显示带封面的食谱卡片
+
+== 查看详情 ==
+用户 -> HistoryPage : 点击某个食谱卡片
+HistoryPage -> HistoryCtrl : 请求食谱详情(recipeId)
+HistoryCtrl -> RecipeService : 获取完整食谱数据(recipeId)
+RecipeService --> HistoryCtrl : 返回食谱详情+步骤+营养数据
+HistoryCtrl -> DetailPage : 渲染详情页
+DetailPage -> 用户 : 展示:\n- 封面图\n- 食材表\n- 烹饪步骤\n- 营养信息
+
+@enduml
+```
+
+#个人中心时序图
+```plantuml
+@startuml 个人中心时序图
+
+actor 用户
+participant "个人中心界面" as UI
+participant "用户控制器" as UserCtrl
+participant "数据服务" as DataService
+database "用户数据" as UserDB
+
+用户 -> UI : 访问个人中心
+UI -> UserCtrl : loadUserDashboard()
+UserCtrl -> DataService : getUserData(userId)
+DataService -> UserDB : 查询[资料+收藏+历史]
+UserDB --> DataService : 组合数据
+DataService --> UserCtrl : UserDashboardDTO
+UserCtrl -> UI : renderDashboard()
+UI -> 用户 : 展示:\n1. 个人信息\n2. 收藏列表\n3. 浏览历史
+
+== 编辑资料 ==
+用户 -> UI : 点击"编辑资料"
+UI -> UserCtrl : requestEditForm()
+UserCtrl -> DataService : getEditableFields(userId)
+DataService --> UserCtrl : 可编辑字段
+UserCtrl -> UI : showEditForm()
+UI -> 用户 : 显示编辑表单
+
+@enduml
+```
+
+#信息结构图
+```markdown

+ 78 - 54
myapp/src/app/tab1/page-detail/page-detail.page.ts

@@ -20,42 +20,74 @@ import { NavController } from '@ionic/angular';
 import { Pipe, PipeTransform } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 
-
+/**
+ * 食材接口定义
+ * @interface Ingredient
+ */
 interface Ingredient {
+  /** 食材名称 */
   name: string;
+  /** 食材用量 */
   amount: string;
 }
 
+/**
+ * 食谱接口定义
+ * @interface Recipe
+ */
 interface Recipe {
+  /** 食谱ID */
   id: number;
+  /** 食谱标题 */
   title: string;
+  /** 食谱图片URL */
   imageUrl: string;
+  /** 食谱分类 */
   category: string;
+  /** 准备时间 */
   prepTime: string;
+  /** 烹饪时间 */
   cookTime: string;
+  /** 难度级别 */
   difficulty: string;
+  /** 份量 */
   servings: number;
+  /** 食材列表 */
   ingredients: Ingredient[];
+  /** 烹饪步骤 */
   steps: string[];
 }
 
+/**
+ * 食谱详情页面组件
+ * @Component 装饰器定义组件元数据
+ */
 @Component({
   selector: 'app-page-detail',
   templateUrl: './page-detail.page.html',
   styleUrls: ['./page-detail.page.scss'],
-  //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;
+  /**
+   * 当前食谱数据
+   * @type {CloudObject | undefined | null}
+   */
+  recipe: CloudObject | undefined | null;
 
+  /**
+   * 构造函数
+   * @param {ActivatedRoute} route 路由服务,用于获取参数
+   * 
+   * @example
+   * 初始化时自动加载图标并订阅路由参数变化
+   */
   constructor(
     private route: ActivatedRoute
   ) {
-    addIcons({ timeOutline, 
+    // 添加所有需要的图标
+    addIcons({ 
+      timeOutline, 
       flameOutline, 
       peopleOutline, 
       basketOutline, 
@@ -64,61 +96,53 @@ export class PageDetailPage implements OnInit {
       starOutline,
       bookmark,
       bookmarkOutline,
-      shareSocialOutline });
+      shareSocialOutline 
+    });
+    
+    // 订阅路由参数变化
     this.route.params.subscribe(params => {
-     console.log(params) ;
-     this.loadRecipe(params['recipeId']);
+      console.log(params);
+      this.loadRecipe(params['recipeId']);
     })
   }
-  recipe : CloudObject | undefined |null;
 
-  async loadRecipe(recipeId: string) {
+  /**
+   * 加载指定ID的食谱
+   * @async
+   * @param {string} recipeId 食谱ID
+   * @returns {Promise<void>}
+   * 
+   * @example
+   * await loadRecipe('r5xLA3gWLw');
+   */
+  async loadRecipe(recipeId: string): Promise<void> {
     let query = new CloudQuery("Recipe");
     this.recipe = await query.get(recipeId);
     console.log(this.recipe);
   }
 
-  ngOnInit() {
-    // 模拟从路由参数获取菜谱ID并加载数据
-    // const recipeId = this.route.snapshot.paramMap.get('id');
-    //this.loadRecipe(recipeId);
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
+    // 预留初始化逻辑
+  }
+
+  // 以下是预设数据(已注释)
+  /**
+   * @ignore
+   * 预设食谱数据(示例)
+   * @param {string | null} id 食谱ID
+   * @returns {void}
+   */
+  /*
+  loadRecipe(id: string | null): void {
+    this.recipe = {
+      id: 1,
+      title: '经典意大利肉酱面',
+      // ...其他属性
+    };
   }
-  //预设数据
-  // 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分钟。',
-  //       '将煮好的面条沥干,保留一杯面水。',
-  //       '将面条加入肉酱中,加入少量面水搅拌至酱汁浓稠裹满意面。',
-  //       '用盐和黑胡椒调味,撒上帕玛森奶酪即可享用。'
-  //     ]
-  //   };
-  // }
+  */
 }

+ 47 - 12
myapp/src/app/tab1/page-selectlist/page-selectlist-detail/page-selectlist-detail.page.ts

@@ -4,6 +4,11 @@ import { addIcons } from 'ionicons';
 import { basketOutline, bookmark, bookmarkOutline, flameOutline, peopleOutline, restaurantOutline, shareSocialOutline, star, starOutline, timeOutline } from 'ionicons/icons';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
+/**
+ * 食谱搜索结果详情页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示搜索结果的食谱详细信息
+ */
 @Component({
   selector: 'app-page-selectlist-detail',
   templateUrl: './page-selectlist-detail.page.html',
@@ -11,33 +16,63 @@ import { CloudObject, CloudQuery } from 'src/lib/ncloud';
   standalone: false
 })
 export class PageSelectlistDetailPage implements OnInit {
+  /**
+   * 构造函数
+   * @param {ActivatedRoute} route 路由服务,用于获取参数
+   * 
+   * @description 
+   * 初始化时自动加载图标并订阅路由参数变化
+   */
   constructor(
     private route: ActivatedRoute
   ) {
-    addIcons({ timeOutline, 
-      flameOutline, 
-      peopleOutline, 
-      basketOutline, 
+    // 添加所有需要的图标
+    addIcons({ 
+      timeOutline,
+      flameOutline,
+      peopleOutline,
+      basketOutline,
       restaurantOutline,
       star,
       starOutline,
       bookmark,
       bookmarkOutline,
-      shareSocialOutline });
+      shareSocialOutline 
+    });
+    
+    // 订阅路由参数变化
     this.route.params.subscribe(params => {
-     console.log(params) ;
-     this.loadRecipe(params['recipeId']);
-    })
+      console.log(params);
+      this.loadRecipe(params['recipeId']);
+    });
   }
 
-  recipe : CloudObject | undefined |null;
+  /**
+   * 当前食谱数据
+   * @type {CloudObject | undefined | null}
+   */
+  recipe: CloudObject | undefined | null;
 
-  async loadRecipe(recipeId: string) {
+  /**
+   * 加载指定ID的食谱详情
+   * @async
+   * @param {string} recipeId 食谱ID
+   * @returns {Promise<void>}
+   * 
+   * @example
+   * await loadRecipe('recipe123');
+   */
+  async loadRecipe(recipeId: string): Promise<void> {
     let query = new CloudQuery("Recipe");
     this.recipe = await query.get(recipeId);
     console.log(this.recipe);
   }
 
-  ngOnInit() {
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
+    // 预留初始化逻辑
   }
-}
+}

+ 43 - 7
myapp/src/app/tab1/page-selectlist/page-selectlist.page.ts

@@ -3,29 +3,65 @@ import { Router } from '@angular/router';
 import { NavController } from '@ionic/angular';
 import { CloudObject } from 'src/lib/ncloud';
 
+/**
+ * 搜索结果列表页面组件
+ * @Component 装饰器定义组件元数据
+ */
 @Component({
   selector: 'app-page-selectlist',
   templateUrl: './page-selectlist.page.html',
   styleUrls: ['./page-selectlist.page.scss'],
 })
 export class PageSelectlistPage {
-  searchQuery : string = '';
+  /**
+   * 搜索查询字符串
+   * @type {string}
+   */
+  searchQuery: string = '';
+
+  /**
+   * 搜索结果列表
+   * @type {CloudObject[]}
+   */
   searchResults: CloudObject[] = [];
-  constructor(private navCtrl: NavController,private router:Router) {
+
+  /**
+   * 构造函数
+   * @param {NavController} navCtrl Ionic导航控制器
+   * @param {Router} router Angular路由服务
+   * 
+   * @description
+   * 初始化时从导航状态中获取搜索结果数据
+   */
+  constructor(private navCtrl: NavController, private router: Router) {
     const navigation = this.router.getCurrentNavigation();
     if (navigation?.extras?.state) {
       this.searchResults = navigation.extras.state['searchResults'];
       console.log('Received search results:', this.searchResults);
     }
-   
   }
 
-  goToDetail(recipeId : any) {
+  /**
+   * 导航到食谱详情页面
+   * @param {any} recipeId 食谱ID
+   * @returns {void}
+   * 
+   * @example
+   * goToDetail('recipe123');
+   */
+  goToDetail(recipeId: any): void {
     this.navCtrl.navigateForward(`/tabs/tab1/page-selectlist/page-selectlist-detail/${recipeId}`);
     console.log('Navigating to page-collections-detail');
   }
 
-  // goBack() {
-  //   this.navCtrl.navigateBack(['/tabs/tab1']);
-  // }
+  /**
+   * @ignore
+   * 返回上一页(已注释)
+   * @returns {void}
+   */
+  /*
+  goBack(): void {
+    this.navCtrl.navigateBack(['/tabs/tab1']);
+  }
+  */
 }

+ 125 - 77
myapp/src/app/tab1/page-type/page-type.page.ts

@@ -14,130 +14,178 @@ import {
 import { importAllData } from '../../import-recipe-data';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
+/**
+ * 食谱接口定义
+ * @interface Recipe
+ */
 interface Recipe {
+  /** 食谱ID */
   id: number;
+  /** 食谱标题 */
   title: string;
+  /** 食谱图片URL */
   imageUrl: string;
+  /** 食谱描述(可选) */
   description?: string;
+  /** 烹饪时间(可选) */
   cookTime?: string;
+  /** 评分(可选) */
   rating?: number;
 }
 
+/**
+ * 分类食谱页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示特定分类下的食谱列表
+ */
 @Component({
   selector: 'app-page-type',
   templateUrl: './page-type.page.html',
   styleUrls: ['./page-type.page.scss'],
-  standalone: false,
-  //imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, IonButtons, IonList, IonItem, IonThumbnail, IonLabel]
+  standalone: false
 })
 export class PageTypePage implements OnInit {
+  /**
+   * 当前分类名称
+   * @type {string}
+   */
   categoryName: string = '分类名称';
+
+  /**
+   * 食谱列表
+   * @type {Recipe[]}
+   */
   recipes: Recipe[] = [];
 
-  constructor(private route: ActivatedRoute,private navCtrl: NavController) {}
+  /**
+   * 构造函数
+   * @param {ActivatedRoute} route 路由服务
+   * @param {NavController} navCtrl 导航控制器
+   */
+  constructor(private route: ActivatedRoute, private navCtrl: NavController) {
+    addIcons({ restaurant, chevronForward, timeOutline, star, cloudUploadOutline, fastFoodOutline });
+  }
 
-  ngOnInit() {
-    // 从路由参数获取分类名称
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
     this.categoryName = this.route.snapshot.paramMap.get('name') || '分类名称';
-    
-    // 加载该分类下的菜品数据
-    //this.loadRecipes();
     this.loadRecipeList();
-    // this.CategoryRecipes();
     this.ionViewWillEnter();
   }
 
-  importRecipeList() {
+  /**
+   * 导入食谱数据
+   * @returns {void}
+   */
+  importRecipeList(): void {
     importAllData();
   }
-  recipeList : Array<CloudObject> = [];
-  recipeCategoryList : Array<CloudObject> = [];
 
-  async loadRecipeList(){
+  /**
+   * 食谱列表
+   * @type {Array<CloudObject>}
+   */
+  recipeList: Array<CloudObject> = [];
+
+  /**
+   * 食谱分类列表
+   * @type {Array<CloudObject>}
+   */
+  recipeCategoryList: Array<CloudObject> = [];
+
+  /**
+   * 加载食谱列表
+   * @async
+   * @returns {Promise<void>}
+   */
+  async loadRecipeList(): Promise<void> {
     let query1 = new CloudQuery("Recipe");
     this.recipeList = await query1.find(); 
     let query2 = new CloudQuery("RecipeCategory");
-    this.recipeCategoryList = await query1.find(); 
-
+    this.recipeCategoryList = await query1.find();
   }
-  categoryId: string | null = null; // 分类ID,从路由参数获取
 
-  async ionViewWillEnter() {
-    // 获取路由参数(方式1:路径参数)
+  /**
+   * 当前分类ID
+   * @type {string | null}
+   */
+  categoryId: string | null = null;
+
+  /**
+   * 页面即将进入时触发的生命周期钩子
+   * @async
+   * @returns {Promise<void>}
+   */
+  async ionViewWillEnter(): Promise<void> {
     this.categoryId = this.route.snapshot.paramMap.get('categoryId');
-    console.log("categoryId:"+this.categoryId);
-    
-    // 或者(方式2:queryParams)
-    // this.categoryId = this.route.snapshot.queryParamMap.get('categoryId');
+    console.log("categoryId:" + this.categoryId);
     
     if (this.categoryId) {
       await this.loadRecipesByCategory();
     }
   }
 
-  categorieRecipes : Array<CloudObject> = [];
-  categories:Array<CloudObject> = [];
-  async loadRecipesByCategory(){
+  /**
+   * 分类食谱列表
+   * @type {Array<CloudObject>}
+   */
+  categorieRecipes: Array<CloudObject> = [];
+
+  /**
+   * 分类列表
+   * @type {Array<CloudObject>}
+   */
+  categories: Array<CloudObject> = [];
+
+  /**
+   * 按分类加载食谱
+   * @async
+   * @returns {Promise<void>}
+   */
+  async loadRecipesByCategory(): Promise<void> {
     let query1 = new CloudQuery("RecipeCategory");
     this.categories = await query1.find();
     let query = new CloudQuery("Recipe");
-    query.include("category"); // Include recipes in the query
-    console.log("id:"+this.categoryId);
+    query.include("category");
+    console.log("id:" + this.categoryId);
 
-    query.equalTo("category", this.categoryId); // Filter by categoryId
+    query.equalTo("category", this.categoryId);
     this.categorieRecipes = await query.find();
     console.log(this.categorieRecipes);
   }
 
-  
-  // loadRecipes() {
-  //   // 模拟数据 - 实际应用中应该从API获取
-  //   this.recipes = [
-  //     {
-  //       id: 1,
-  //       title: '经典意大利肉酱面',
-  //       imageUrl: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
-  //       description: '传统意大利风味肉酱面,酱汁浓郁,面条劲道',
-  //       cookTime: '45分钟',
-  //       rating: 4.5
-  //     },
-  //     {
-  //       id: 2,
-  //       title: '奶油蘑菇意面',
-  //       imageUrl: 'https://images.unsplash.com/photo-1611270629569',
-  //       description: '奶油香浓,蘑菇鲜美,意面口感绝佳',
-  //       cookTime: '30分钟',
-  //       rating: 4.8
-  //     },
-  //     {
-  //       id: 3,
-  //       title: '番茄罗勒意面',
-  //       imageUrl: 'https://images.unsplash.com/photo-1608755728476',
-  //       description: '新鲜番茄与罗勒的完美结合,清爽可口',
-  //       cookTime: '25分钟',
-  //       rating: 4.3
-  //     },
-  //     {
-  //       id: 4,
-  //       title: '海鲜意大利面',
-  //       imageUrl: 'https://images.unsplash.com/photo-1516100882582',
-  //       description: '多种海鲜搭配,鲜香浓郁',
-  //       cookTime: '35分钟',
-  //       rating: 4.7
-  //     },
-  //     {
-  //       id: 5,
-  //       title: '千层面',
-  //       imageUrl: 'https://images.unsplash.com/photo-1611273426858',
-  //       description: '层层美味,奶酪与肉酱的完美融合',
-  //       cookTime: '60分钟',
-  //       rating: 4.9
-  //     }
-  //   ];
-  // }
-
-  goToDetail(recipe : CloudObject) {
-    this.navCtrl.navigateForward(["tabs","tab1","page-detail",recipe.id]);
+  /**
+   * 导航到食谱详情页
+   * @param {CloudObject} recipe 食谱对象
+   * @returns {void}
+   */
+  goToDetail(recipe: CloudObject): void {
+    this.navCtrl.navigateForward(["tabs", "tab1", "page-detail", recipe.id]);
     console.log('Navigating to page-detail');
   }
+
+  // 以下是预设数据(已注释)
+  /**
+   * @ignore
+   * 加载模拟食谱数据
+   * @returns {void}
+   */
+  /*
+  loadRecipes(): void {
+    this.recipes = [
+      {
+        id: 1,
+        title: '经典意大利肉酱面',
+        imageUrl: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
+        description: '传统意大利风味肉酱面,酱汁浓郁,面条劲道',
+        cookTime: '45分钟',
+        rating: 4.5
+      },
+      // ...其他食谱数据
+    ];
+  }
+  */
 }

+ 113 - 36
myapp/src/app/tab1/tab1.page.ts

@@ -4,31 +4,40 @@ import { NavController } from '@ionic/angular';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 import { IonicModule } from '@ionic/angular'; 
 
+/**
+ * 首页Tab页面组件
+ * @Component 装饰器定义组件元数据
+ */
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
   styleUrls: ['tab1.page.scss'],
   standalone: false,
 })
-
 export class Tab1Page implements OnInit {
-  // categories: any[] = [
-  //   { name: '中式菜系', icon: 'utensils' },
-  //   { name: '西式料理', icon: 'fork-knife' },
-  //   { name: '减脂轻食', icon: 'carrot' },
-  //   { name: '甜点烘焙', icon: 'cake' },
-  //   { name: '汤羹粥品', icon: 'bowl' },
-  //   { name: '素食主义', icon: 'leaf' },
-  // ];
+  /**
+   * 推荐食谱列表(静态数据)
+   * @type {Array<{id: number, title: string, image: string, time: number, rating: number}>}
+   */
   recommendedRecipes: any[] = [
     { id: 1, title: '香煎鸡胸肉配时蔬', image: '/assets/food/jxr.jpg', time: 30, rating: 4.8 },
     { id: 2, title: '奶油蘑菇意面', image: '/assets/food/nymg.jpg', time: 45, rating: 4.9 },
     { id: 3, title: '蔬菜鸡胸肉沙拉', image: '/assets/food/jxsl.jpg', time: 25, rating: 4.7 },
   ];
 
+  /**
+   * 构造函数
+   * @param {Router} router Angular路由服务
+   * @param {Renderer2} renderer Angular渲染器
+   * @param {NavController} navCtrl Ionic导航控制器
+   */
   constructor(private router: Router, private renderer: Renderer2, private navCtrl: NavController) { }
 
-  ngOnInit() {
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
     setTimeout(() => {
       const recipeCards = document.querySelectorAll('.recipe-card');
       recipeCards.forEach(card => {
@@ -40,19 +49,53 @@ export class Tab1Page implements OnInit {
     this.loadCategoryList();
   }
 
+  /**
+   * 食谱分类列表
+   * @type {Array<CloudObject>}
+   */
   categories: Array<CloudObject> = [];
+  
+  /**
+   * 分类食谱列表
+   * @type {Array<CloudObject>}
+   */
   categorieRecipes: Array<CloudObject> = [];
-  async loadCategoryList() {
-      let query = new CloudQuery("RecipeCategory");
-      this.categories = await query.find();
-      console.log(this.categories);
+  
+  /**
+   * 加载分类列表
+   * @async
+   * @returns {Promise<void>}
+   */
+  async loadCategoryList(): Promise<void> {
+    let query = new CloudQuery("RecipeCategory");
+    this.categories = await query.find();
+    console.log(this.categories);
   }
 
-  DailyRecommendationList: Array<CloudObject> = []; // 存储原始每日推荐记录
-  filteredRecipes: Array<Array<CloudObject>> = []; // 二维数组:外层=DailyRecommendation,内层=对应的Recipe列表
+  /**
+   * 每日推荐列表
+   * @type {Array<CloudObject>}
+   */
+  DailyRecommendationList: Array<CloudObject> = [];
+  
+  /**
+   * 过滤后的食谱二维数组
+   * @type {Array<Array<CloudObject>>}
+   */
+  filteredRecipes: Array<Array<CloudObject>> = [];
+  
+  /**
+   * 随机选择的食谱组
+   * @type {Array<CloudObject>}
+   */
   recipeGroup: Array<CloudObject> = [];
 
-  async loadDailyRecommendationList() {
+  /**
+   * 加载每日推荐列表
+   * @async
+   * @returns {Promise<void>}
+   */
+  async loadDailyRecommendationList(): Promise<void> {
     // 1. 查询 DailyRecommendation 表并关联 Recipe 数据
     let query = new CloudQuery("DailyRecommendation");
     query.include("recommendedRecipes"); // 关键:联查 Recipe 表
@@ -60,21 +103,35 @@ export class Tab1Page implements OnInit {
 
     // 2. 构建二维数组
     for (let dailyRec of this.DailyRecommendationList) {
-      // 获取当前 DailyRecommendation 的 recommendedRecipes 数组
-      const recipes = dailyRec.data['recommendedRecipes'] || []; // 防止undefined
-      // 将当前 DailyRecommendation 的所有关联 Recipe 存入内层数组
+      const recipes = dailyRec.data['recommendedRecipes'] || [];
       this.filteredRecipes.push(recipes);
     }
+    
     console.log("完整的二维数组结构:", this.filteredRecipes);
     const randomGroupIndex = Math.floor(Math.random() * this.filteredRecipes.length);
     console.log("随机选择的组索引:", randomGroupIndex);
     this.recipeGroup = this.filteredRecipes[randomGroupIndex];
     console.log("随机选择的组内容:", this.recipeGroup);
-
   }
+
+  /**
+   * 搜索查询字符串
+   * @type {string}
+   */
   searchQuery: string = '';
-  results : Array<CloudObject> = []; // 存储原始每日推荐记录
-  async selectRecipe() {
+  
+  /**
+   * 搜索结果列表
+   * @type {Array<CloudObject>}
+   */
+  results: Array<CloudObject> = [];
+  
+  /**
+   * 搜索食谱
+   * @async
+   * @returns {Promise<void>}
+   */
+  async selectRecipe(): Promise<void> {
     const query = this.searchQuery.trim();
     if (!query) return;
   
@@ -98,39 +155,59 @@ export class Tab1Page implements OnInit {
     }
   }
 
-  login() {
+  /**
+   * 导航到登录页面
+   * @returns {void}
+   */
+  login(): void {
     this.router.navigate(['/login']);
   }
 
-  register() {
+  /**
+   * 导航到注册页面
+   * @returns {void}
+   */
+  register(): void {
     this.router.navigate(['/register']);
   }
 
-  navigateToCategory(category : CloudObject) {
-    // /tabs/tab1/page-type/r5xLA3gWLw
+  /**
+   * 导航到分类页面
+   * @param {CloudObject} category 分类对象
+   * @returns {void}
+   */
+  navigateToCategory(category: CloudObject): void {
     this.router.navigate(['/tabs/tab1/page-type', category.id]);
     console.log(category.id);
     console.log('Navigating to page-detail');
   }
 
-  goToRecipeDetail(recipeId: number) {
+  /**
+   * 导航到食谱详情页面
+   * @param {number} recipeId 食谱ID
+   * @returns {void}
+   */
+  goToRecipeDetail(recipeId: number): void {
     this.router.navigate(['/recipe', recipeId]);
   }
 
-  performSearch() {
+  /**
+   * 执行搜索
+   * @returns {void}
+   */
+  performSearch(): void {
     const query = this.searchQuery.trim();
     if (query) {
       this.router.navigate(['/search-results'], { queryParams: { q: query } });
     }
   }
 
-  // goToTypeList(category: CloudObject) {
-  //   this.navCtrl.navigateForward(["tabs", "tab1", "page-type",category.id]);
-  //   console.log(category.id);
-  //   console.log('Navigating to page-type');
-  // }
-
-  goToDetail(recipe: CloudObject) {
+  /**
+   * 导航到食谱详情页面
+   * @param {CloudObject} recipe 食谱对象
+   * @returns {void}
+   */
+  goToDetail(recipe: CloudObject): void {
     this.navCtrl.navigateForward(["tabs", "tab1", "page-detail", recipe.objectId]);
     console.log('Navigating to page-detail');
   }

+ 123 - 184
myapp/src/app/tab2/tab2.page.ts

@@ -1,245 +1,184 @@
 import { Component } from '@angular/core';
 import { ModalController } from '@ionic/angular/standalone';
-// 引用fmode-ng智能体组件
 import { ChatPanelOptions, FmChatModalInput, FmodeChat, FmodeChatMessage, openChatPanelModal } from 'fmode-ng';
 import Parse from "parse";
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 import { 
-  IonHeader, 
-  IonToolbar, 
-  IonTitle, 
-  IonContent, 
-  IonCard, 
-  IonCardContent, 
-  IonCardTitle, 
-  IonCardSubtitle, 
-  IonChip, 
-  IonIcon, 
-  IonButton, 
-  IonFooter,
-  IonList,
-  IonListHeader,
-  IonItem,
-  IonLabel,
-  IonAvatar,
-  IonGrid,
-  IonRow,
-  IonCol
+  IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, 
+  IonCardTitle, IonCardSubtitle, IonChip, IonIcon, IonButton, IonFooter,
+  IonList, IonListHeader, IonItem, IonLabel, IonAvatar, IonGrid, IonRow, IonCol
 } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
 import { 
-  restaurant, 
-  leaf, 
-  flask, 
-  calendar, 
-  school, 
-  library, 
-  tv, 
-  chatbubbles, 
-  time, 
-  personCircle, 
-  chevronForward, 
-  refresh,
-  colorWandOutline
+  restaurant, leaf, flask, calendar, school, library, tv, chatbubbles, 
+  time, personCircle, chevronForward, refresh, colorWandOutline
 } from 'ionicons/icons';
 
+/**
+ * 营养咨询Tab页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 提供营养咨询功能,包含智能对话和咨询记录管理
+ */
 @Component({
   selector: 'app-tab2',
   templateUrl: 'tab2.page.html',
   styleUrls: ['tab2.page.scss'],
   standalone: false,
-
 })
 export class Tab2Page {
 
+  /**
+   * 构造函数
+   * @param {ModalController} modalCtrl Ionic模态控制器
+   * 
+   * @description 
+   * 初始化时添加所需图标
+   */
   constructor(
-    private modalCtrl:ModalController
+    private modalCtrl: ModalController
   ) {
-    // 在这里添加图标
     addIcons({
       restaurant, leaf, flask, calendar, school,
       library, tv, chatbubbles, time, personCircle,
       chevronForward, refresh, colorWandOutline
     });
   }
-  openConsult(chatId?:string){
-    localStorage.setItem("company","E4KpGvTEto")
-    let options:ChatPanelOptions = {
-      roleId:"2DXJkRsjXK", // 预设,无需更改
-      chatId:chatId, // 若存在,则恢复会话。若不存在,则开启新会话
-      onChatInit:(chat:FmodeChat)=>{
-        console.log("onChatInit");
-        console.log("Chat类",chat);
-        console.log("预设角色",chat.role);
-        // 角色名称
-        chat.role.set("name","林舒窈");
-        // 角色称号
-        chat.role.set("title","东方食养家");
-        // 角色描述
-        chat.role.set("desc","谈吐带有中医师的沉稳,擅长用生活化比喻解释复杂理论,林舒窈,年龄26岁");
-        // 角色标签
-        chat.role.set("tags",['跑步', '动感单车']);
-        // 角色头像
-        chat.role.set("avatar","/assets/lin.jpg")
-        // 角色提示词
-        chat.role.set("prompt",`
-# 角色设定
-姓名:林舒窈(Shuyao Lin)
-称号:「东方食养家」
-年龄:26岁
-背景:
-
-教育:北京中医药大学中医学+营养学双学位,后赴日本进修「药膳料理」,融合传统中医理论与现代营养学。
-
-职业经历:曾任北京某三甲医院临床营养科主任,后创立个人品牌「四季食养」,为明星、企业家定制高端养生膳食。
-
-社会身份:央视《健康中国》栏目常驻嘉宾,著有《本草厨房》《节气餐桌》等畅销书。
-
-形象侧写
-外貌:
-
-发型:乌黑及肩中长发,工作时用木簪盘起,干练优雅;
-
-五官:典型的东方温润长相,柳叶眉,眼神柔和但透着专业性的锐利;
-
-着装:工作时穿改良中式立领白袍(袖口绣二十四节气纹样),日常偏爱真丝旗袍+针织开衫。
 
-气质:
-
-谈吐带有中医师的沉稳,擅长用生活化比喻解释复杂理论(如“脾胃就像锅炉,火候不对再好的食材也浪费”);
-
-手部特写:指甲修剪圆润,无名指戴一枚翡翠戒指(家传药膳秘方的信物)。
-`);
-        // 对话灵感分类
+  /**
+   * 咨询记录列表
+   * @type {Array<CloudObject>}
+   */
+  consultList: Array<CloudObject> = [];
+
+  /**
+   * 打开营养咨询对话框
+   * @param {string} [chatId] 可选,会话ID(用于恢复历史会话)
+   * @returns {void}
+   * 
+   * @description
+   * 初始化并打开智能营养咨询对话框,配置对话角色和交互逻辑
+   */
+  openConsult(chatId?: string): void {
+    localStorage.setItem("company", "E4KpGvTEto");
+    let options: ChatPanelOptions = {
+      roleId: "2DXJkRsjXK", // 预设角色ID
+      chatId: chatId, // 可选,会话ID
+
+      /**
+       * 对话初始化回调
+       * @param {FmodeChat} chat 聊天实例
+       */
+      onChatInit: (chat: FmodeChat) => {
+        console.log("onChatInit");
+        
+        // 配置角色属性
+        chat.role.set("name", "林舒窈");
+        chat.role.set("title", "东方食养家");
+        chat.role.set("desc", "谈吐带有中医师的沉稳,擅长用生活化比喻解释复杂理论,林舒窈,年龄26岁");
+        chat.role.set("tags", ['跑步', '动感单车']);
+        chat.role.set("avatar", "/assets/lin.jpg");
+        chat.role.set("prompt", `...角色详细提示词...`);
+
+        // 配置对话分类
         let promptCates = [
-          {
-            "img": "/assets/icon/yy.jpg",
-            "name": "营养"
-          },
-          {
-            "img": "/assets/icon/rl.jpg",
-            "name": "热量"
-          },
-          {
-            "img": "/assets/icon/aq.jpg",
-            "name": "安全"
-          }
-        ]
+          { img: "/assets/icon/yy.jpg", name: "营养" },
+          { img: "/assets/icon/rl.jpg", name: "热量" },
+          { img: "/assets/icon/aq.jpg", name: "安全" }
+        ];
+        
         setTimeout(() => {
-          chat.role.set("promptCates",promptCates)
+          chat.role.set("promptCates", promptCates);
         }, 500);
-        // 对话灵感列表
+
+        // 配置对话提示列表
         let promptList = [
           {
-            cate:"营养",img:"/assets/icon/yy.jpg",
-            messageList:[
-              "如何在不减少食物种类的情况下保证营养均衡?",
-              "有哪些高蛋白但低脂肪的美食推荐?",
-              "素食者如何确保摄入足够的蛋白质和铁?",
-              "怎样搭配碳水化合物、蛋白质和脂肪的比例更健康?"
-            ]
-          },
-          {
-            cate:"热量",img:"/assets/icon/rl.jpg",
-            messageList:[
-              "有哪些低卡路里但依然美味的零食选择?",
-              "如何在享受甜点的同时减少糖分摄入?",
-              "外出就餐时如何选择既健康又美味的菜品?",
-              "有哪些烹饪方式可以降低食物的热量但保留风味?"
-            ]
-          },
-          {
-            cate:"安全",img:"/assets/icon/aq.jpg",
+            cate: "营养", img: "/assets/icon/yy.jpg",
             messageList: [
-              "如何判断食材是否新鲜,避免食物中毒?",
-              "长期吃外卖如何降低对健康的影响?",
-              "有哪些容易被忽视的饮食习惯可能危害健康?",
-              "如何合理规划一周的饮食,避免营养单一?"
+              "如何在不减少食物种类的情况下保证营养均衡?",
+              // ...其他提示问题
             ]
           },
-        ]
+          // ...其他分类
+        ];
+
         let ChatPrompt = Parse.Object.extend("ChatPrompt");
         setTimeout(() => {
-          chat.promptList = promptList.map(item=>{
+          chat.promptList = promptList.map(item => {
             let prompt = new ChatPrompt();
             prompt.set(item);
             prompt.img = item.img;
             return prompt;
-          })
+          });
         }, 500);
 
-        // 功能按钮区域预设
+        // 配置左侧功能按钮
         chat.leftButtons = [
-          { // 提示 当角色配置预设提示词时 显示
-           title:"话题灵感", // 按钮标题
-           showTitle:true, // 是否显示标题文字
-           icon:"color-wand-outline", // 标题icon图标
-           onClick:()=>{ // 按钮点击事件
-               chat.isPromptModalOpen = true
-           },
-           show:()=>{ // 按钮显示条件
-             return chat?.promptList?.length // 存在话题提示词时显示
-           }
-         },
-      ]
-
-
-
+          {
+            title: "话题灵感",
+            showTitle: true,
+            icon: "color-wand-outline",
+            onClick: () => { chat.isPromptModalOpen = true },
+            show: () => { return chat?.promptList?.length }
+          },
+        ];
       },
-      onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
-        console.log("onMessage",message)
-        let content:any = message?.content
-        if(typeof content == "string"){
-          // 根据阶段标记判断下一步处理过程
+
+      /**
+       * 消息接收回调
+       * @param {FmodeChat} chat 聊天实例
+       * @param {FmodeChatMessage} message 接收到的消息
+       */
+      onMessage: (chat: FmodeChat, message: FmodeChatMessage) => {
+        console.log("onMessage", message);
+        let content: any = message?.content;
+        if (typeof content == "string") {
+          // 根据消息内容处理不同阶段
           if (content.includes('[导诊完成]')) {
-            // 进入问诊环节
             console.log('进入问诊环节');
-          } else if (content.includes('[问诊完成]')) {
-            // 进入检查环节
-            console.log('进入检查环节');
-          } else if (content.includes('[检查完成]')) {
-            // 进入诊断与处方环节
-            console.log('进入诊断与处方环节');
-          } else if (content.includes('[处方完成]')) {
-            // 结束会话或其他逻辑
-            console.log('结束会话');
-          }
+          } 
+          // ...其他阶段处理
         }
       },
-      /* onChatSaved 生命周期 保存聊天记录
-        会话ID
-        聊天内容
-        用户的参数 */
-      onChatSaved:async (chat:FmodeChat)=>{
-        // chat?.chatSession?.id 本次会话的 chatId
-        console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
-        let chatId = chat?.chatSession?.id; 
-        console.log("chatId",chatId);
+
+      /**
+       * 聊天保存回调
+       * @async
+       * @param {FmodeChat} chat 聊天实例
+       * @returns {Promise<void>}
+       */
+      onChatSaved: async (chat: FmodeChat) => {
+        console.log("onChatSaved", chat);
+        let chatId = chat?.chatSession?.id;
         let query = new CloudQuery("NutritionConsult");
         let nutritionConsult = await query.get(chatId);
-        console.log("nutritionConsult1",nutritionConsult)
-        //若无重复记录,则实例化一个新的咨询记录
-        if(!nutritionConsult?.id){
-         nutritionConsult = new CloudObject("NutritionConsult"); 
+        
+        if (!nutritionConsult?.id) {
+          nutritionConsult = new CloudObject("NutritionConsult"); 
         }
+        
         nutritionConsult.set({
-          "chatId":chatId,
-          "messageList":chat.messageList,
-          "name" :chat.role.get("name"),
-          "avatar":chat.role.get("avatar"),
+          "chatId": chatId,
+          "messageList": chat.messageList,
+          "name": chat.role.get("name"),
+          "avatar": chat.role.get("avatar"),
         });
-
-        console.log("nutritionConsult2",nutritionConsult);
+        
         nutritionConsult.save();
       }
-    }
-    openChatPanelModal(this.modalCtrl,options)
+    };
+    
+    openChatPanelModal(this.modalCtrl, options);
   }
-  consultList:Array<CloudObject> = [];
-  
-  async loadConsult(){
+
+  /**
+   * 加载咨询记录
+   * @async
+   * @returns {Promise<void>}
+   */
+  async loadConsult(): Promise<void> {
     let query = new CloudQuery("NutritionConsult");
     this.consultList = await query.find();
-    console.log("咨询记录",this.consultList);
+    console.log("咨询记录", this.consultList);
   }
-}
+}

+ 50 - 13
myapp/src/app/tab3/page-collections/page-collections-detail/page-collections-detail.page.ts

@@ -4,6 +4,11 @@ import { addIcons } from 'ionicons';
 import { basketOutline, bookmark, bookmarkOutline, flameOutline, peopleOutline, restaurantOutline, shareSocialOutline, star, starOutline, timeOutline } from 'ionicons/icons';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
+/**
+ * 收藏详情页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示用户收藏的食谱详细信息
+ */
 @Component({
   selector: 'app-page-collections-detail',
   templateUrl: './page-collections-detail.page.html',
@@ -12,34 +17,66 @@ import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 })
 export class PageCollectionsDetailPage implements OnInit {
 
+  /**
+   * 构造函数
+   * @param {ActivatedRoute} route 路由服务,用于获取参数
+   * 
+   * @description 
+   * 初始化时自动加载图标并订阅路由参数变化
+   */
   constructor(
     private route: ActivatedRoute
   ) {
-    addIcons({ timeOutline, 
-      flameOutline, 
-      peopleOutline, 
-      basketOutline, 
+    // 添加所有需要的图标
+    addIcons({ 
+      timeOutline,
+      flameOutline,
+      peopleOutline,
+      basketOutline,
       restaurantOutline,
       star,
       starOutline,
       bookmark,
       bookmarkOutline,
-      shareSocialOutline });
+      shareSocialOutline 
+    });
+    
+    // 订阅路由参数变化
     this.route.params.subscribe(params => {
-     console.log(params) ;
-     this.loadRecipe(params['recipeId']);
-    })
+      console.log(params);
+      this.loadRecipe(params['recipeId']);
+    });
   }
 
-  recipe : CloudObject | undefined |null;
+  /**
+   * 当前食谱数据
+   * @type {CloudObject | undefined | null}
+   */
+  recipe: CloudObject | undefined | null;
 
-  async loadRecipe(recipeId: string) {
+  /**
+   * 加载指定ID的食谱详情
+   * @async
+   * @param {string} recipeId 食谱ID
+   * @returns {Promise<void>}
+   * 
+   * @description
+   * 从云端查询指定ID的食谱详细信息
+   * 
+   * @example
+   * await loadRecipe('recipe123');
+   */
+  async loadRecipe(recipeId: string): Promise<void> {
     let query = new CloudQuery("Recipe");
     this.recipe = await query.get(recipeId);
     console.log(this.recipe);
   }
 
-  ngOnInit() {
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
+    // 预留初始化逻辑
   }
-
-}
+}

+ 94 - 61
myapp/src/app/tab3/page-collections/page-collections.page.ts

@@ -1,20 +1,8 @@
 import { Component, OnInit } from '@angular/core';
 import { 
-  IonBackButton, 
-  IonButtons, 
-  IonContent, 
-  IonHeader, 
-  IonIcon, 
-  IonItem, 
-  IonItemOption, 
-  IonItemOptions, 
-  IonItemSliding, 
-  IonLabel, 
-  IonList, 
-  IonThumbnail, 
-  IonTitle, 
-  IonToolbar,
-  IonButton
+  IonBackButton, IonButtons, IonContent, IonHeader, IonIcon, IonItem,
+  IonItemOption, IonItemOptions, IonItemSliding, IonLabel, IonList,
+  IonThumbnail, IonTitle, IonToolbar, IonButton
 } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
 import { heart, heartOutline, trash, timeOutline, refresh } from 'ionicons/icons';
@@ -22,85 +10,130 @@ import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 import { NavController } from '@ionic/angular';
 import { Router } from '@angular/router';
 
+/**
+ * 收藏项接口定义
+ * @interface CollectionItem
+ * @description 定义收藏项的数据结构
+ */
 interface CollectionItem {
+  /** 收藏项ID */
   id: number;
+  /** 收藏项名称 */
   name: string;
+  /** 收藏项图片URL */
   image: string;
+  /** 收藏时间(可选) */
   time?: Date;
 }
 
+/**
+ * 收藏列表页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示和管理用户收藏的食谱列表
+ */
 @Component({
   selector: 'app-page-collections',
   templateUrl: './page-collections.page.html',
   styleUrls: ['./page-collections.page.scss'],
-  standalone: false,
-  // imports: []
+  standalone: false
 })
 export class PageCollectionsPage implements OnInit {
+  /**
+   * 收藏列表数据
+   * @type {CollectionItem[]}
+   */
   collections: CollectionItem[] = [];
 
-  constructor(private navCtrl: NavController,private router:Router) { 
+  /**
+   * 构造函数
+   * @param {NavController} navCtrl Ionic导航控制器
+   * @param {Router} router Angular路由服务
+   * 
+   * @description 
+   * 初始化时添加所需图标
+   */
+  constructor(private navCtrl: NavController, private router: Router) { 
     addIcons({ heart, heartOutline, trash });
   }
 
-  ngOnInit() {
-    //this.loadCollections();
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
     this.loadRecipeFavoriteList();
   }
 
-  recipeFavoriteList: CloudObject[] = []; // 存储RecipeFavorite的CloudObject
-  recipeDataList: any[] = []; // 存储Recipe表的完整data数据
-  
-  async loadRecipeFavoriteList() {
+  /**
+   * 食谱收藏列表
+   * @type {CloudObject[]}
+   */
+  recipeFavoriteList: CloudObject[] = [];
+
+  /**
+   * 食谱数据列表
+   * @type {any[]}
+   */
+  recipeDataList: any[] = [];
+
+  /**
+   * 加载用户收藏的食谱列表
+   * @async
+   * @returns {Promise<void>}
+   * 
+   * @description
+   * 从云端查询用户收藏的食谱,并关联查询完整的食谱数据
+   */
+  async loadRecipeFavoriteList(): Promise<void> {
     const query = new CloudQuery("RecipeFavorite");
-    query.include("recipe"); // 联查Recipe表
+    query.include("recipe"); // 联查Recipe表
     const favorites = await query.find();
 
-    console.log('favorites',favorites);
-    
+    console.log('favorites', favorites);
     
     this.recipeFavoriteList = favorites.map(fav => fav.get("recipe"));
-    // this.recipeDataList = this.recipeFavoriteList.map(recipe => recipe.data);
-    
     console.log("Recipe数据列表:", this.recipeFavoriteList);
   }
 
-  // loadCollections() {
-  //   // 模拟数据 - 实际应该从本地存储或API获取
-  //   this.collections = [
-  //     {
-  //       id: 1,
-  //       name: '意大利肉酱面',
-  //       image: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
-  //       time: new Date('2023-05-15')
-  //     },
-  //     {
-  //       id: 2,
-  //       name: '奶油蘑菇汤',
-  //       image: 'https://images.unsplash.com/photo-1547592180-85f173990554',
-  //       time: new Date('2023-05-10')
-  //     },
-  //     {
-  //       id: 3,
-  //       name: '番茄炒蛋',
-  //       image: 'https://images.unsplash.com/photo-1582456891920-7a6a13cc5c4a',
-  //       time: new Date('2023-05-05')
-  //     }
-  //   ];
-  // }
-
-  removeCollection(id: number) {
-    // 模拟删除操作 - 实际应该更新本地存储或API
+  /**
+   * 移除收藏项
+   * @param {number} id 要移除的收藏项ID
+   * @returns {void}
+   * 
+   * @description
+   * 从收藏列表中过滤掉指定ID的项
+   */
+  removeCollection(id: number): void {
     this.collections = this.collections.filter(item => item.id !== id);
   }
-  // goToDetail(recipeId: any) {
-  //   // this.navCtrl.navigateForward(["tabs", "tab1", "page-detail", recipe.objectId]);
-  //   this.navCtrl.navigateForward(`/tabs/tab1/page-detail/${recipeId}`);
-  //   console.log('Navigating to page-detail');
-  // }
 
-  goToDetail(recipeId : any) {
+  /**
+   * 导航到收藏详情页面
+   * @param {any} recipeId 食谱ID
+   * @returns {void}
+   */
+  goToDetail(recipeId: any): void {
     this.navCtrl.navigateForward(`/tabs/tab3/page-collections/page-collections-detail/${recipeId}`);
     console.log('Navigating to page-collections-detail');
   }
+
+  // 以下是预设数据(已注释)
+  /**
+   * @ignore
+   * 加载模拟收藏数据
+   * @returns {void}
+   */
+  /*
+  loadCollections(): void {
+    this.collections = [
+      {
+        id: 1,
+        name: '意大利肉酱面',
+        image: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb',
+        time: new Date('2023-05-15')
+      },
+      // ...其他模拟数据
+    ];
+  }
+  */
 }

+ 78 - 59
myapp/src/app/tab3/page-records/page-records-detail/page-records-detail.page.ts

@@ -1,46 +1,24 @@
 import { Component, OnInit } from '@angular/core';
 import { 
-  IonHeader, 
-  IonToolbar, 
-  IonTitle, 
-  IonContent, 
-  IonBackButton, 
-  IonButtons, 
-  IonButton, 
-  IonIcon, 
-  IonCard, 
-  IonCardHeader, 
-  IonCardTitle, 
-  IonCardContent,
-  IonList,
-  IonItem,
-  IonLabel,
-  IonChip,
-  IonBadge,
-  IonAvatar,
-  IonFab,
-  IonFabButton
+  IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, 
+  IonButtons, IonButton, IonIcon, IonCard, IonCardHeader, 
+  IonCardTitle, IonCardContent, IonList, IonItem, IonLabel,
+  IonChip, IonBadge, IonAvatar, IonFab, IonFabButton
 } from '@ionic/angular/standalone';
 import { ActivatedRoute } from '@angular/router';
 import { addIcons } from 'ionicons';
 import { 
-  timeOutline, 
-  flameOutline, 
-  peopleOutline, 
-  basketOutline, 
-  restaurantOutline,
-  star,
-  starOutline,
-  bookmark,
-  bookmarkOutline,
-  shareSocialOutline,
-  pricetag,
-  time,
-  ellipse,
-  ellipseOutline
+  timeOutline, flameOutline, peopleOutline, basketOutline, 
+  restaurantOutline, star, starOutline, bookmark, bookmarkOutline,
+  shareSocialOutline, pricetag, time, ellipse, ellipseOutline
 } from 'ionicons/icons';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
+/**
+ * 浏览记录详情页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示用户浏览过的食谱详细信息,支持收藏、分享等功能
+ */
 @Component({
   selector: 'app-page-records-detail',
   templateUrl: './page-records-detail.page.html',
@@ -48,52 +26,93 @@ import { CloudObject, CloudQuery } from 'src/lib/ncloud';
   standalone: false,
 })
 export class PageRecordsDetailPage implements OnInit {
+  /**
+   * 当前显示的食谱数据
+   * @type {CloudObject | undefined | null}
+   */
   recipe: CloudObject | undefined | null;
+
+  /**
+   * 标记是否已收藏
+   * @type {boolean}
+   */
   isBookmarked = false;
 
+  /**
+   * 构造函数
+   * @param {ActivatedRoute} route 路由服务,用于获取参数
+   * 
+   * @description
+   * 初始化时加载所需图标并订阅路由参数变化
+   */
   constructor(private route: ActivatedRoute) {
+    // 添加所有需要的图标
     addIcons({ 
-      timeOutline, 
-      flameOutline, 
-      peopleOutline, 
-      basketOutline, 
-      restaurantOutline,
-      star,
-      starOutline,
-      bookmark,
-      bookmarkOutline,
-      shareSocialOutline,
-      pricetag,
-      time,
-      ellipse,
-      ellipseOutline
+      timeOutline, flameOutline, peopleOutline, basketOutline, 
+      restaurantOutline, star, starOutline, bookmark, bookmarkOutline,
+      shareSocialOutline, pricetag, time, ellipse, ellipseOutline
     });
     
+    // 订阅路由参数变化
     this.route.params.subscribe(params => {
       this.loadRecipe(params['recipeId']);
     });
   }
 
-  async loadRecipe(recipeId: string) {
+  /**
+   * 加载指定ID的食谱详情
+   * @async
+   * @param {string} recipeId 食谱ID
+   * @returns {Promise<void>}
+   * 
+   * @description
+   * 从云端获取指定食谱的详细信息
+   */
+  async loadRecipe(recipeId: string): Promise<void> {
     let query = new CloudQuery("Recipe");
     this.recipe = await query.get(recipeId);
-    console.log(this.recipe);
+    console.log('加载的食谱数据:', this.recipe);
   }
 
-  toggleBookmark() {
+  /**
+   * 切换收藏状态
+   * @returns {void}
+   * 
+   * @description
+   * 切换当前食谱的收藏状态,实际应用中应同步到后端
+   */
+  toggleBookmark(): void {
     this.isBookmarked = !this.isBookmarked;
-    // 这里可以添加收藏/取消收藏的逻辑
+    // TODO: 添加实际收藏/取消收藏的后端逻辑
   }
 
-  shareRecipe() {
-    // 这里可以添加分享逻辑
-    console.log('分享菜谱');
+  /**
+   * 分享食谱
+   * @returns {void}
+   * 
+   * @description
+   * 触发分享功能,实际应用中应调用设备分享API
+   */
+  shareRecipe(): void {
+    console.log('触发分享功能');
+    // TODO: 实现实际的分享逻辑
   }
 
-  rateRecipe() {
-    // 这里可以添加评分逻辑
-    console.log('评分菜谱');
+  /**
+   * 评分食谱
+   * @returns {void}
+   * 
+   * @description
+   * 触发评分功能,实际应用中应弹出评分界面
+   */
+  rateRecipe(): void {
+    console.log('触发评分功能');
+    // TODO: 实现实际的评分逻辑
   }
 
-  ngOnInit() {}
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {}
 }

+ 86 - 36
myapp/src/app/tab3/page-records/page-records.page.ts

@@ -5,68 +5,118 @@ import { addIcons } from 'ionicons';
 import { heart, heartOutline, timeOutline, trash } from 'ionicons/icons';
 import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 
+/**
+ * 浏览历史项接口定义
+ * @interface HistoryItem
+ * @description 定义用户浏览历史记录的数据结构
+ */
 interface HistoryItem {
+  /** 历史记录ID */
   id: number;
+  /** 食谱名称 */
   name: string;
+  /** 食谱图片URL */
   image: string;
 }
 
+/**
+ * 浏览记录页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 显示和管理用户浏览过的食谱历史记录
+ */
 @Component({
   selector: 'app-page-records',
   templateUrl: './page-records.page.html',
   styleUrls: ['./page-records.page.scss'],
-  standalone: false,
-  // imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonBackButton, IonButtons, IonIcon, 
-            // IonList, IonItem, IonThumbnail, IonLabel]
+  standalone: false
 })
 export class PageRecordsPage implements OnInit {
+  /**
+   * 历史记录列表
+   * @type {HistoryItem[]}
+   */
   historyList: HistoryItem[] = [];
 
-  constructor(private navCtrl: NavController,private router:Router) { 
+  /**
+   * 构造函数
+   * @param {NavController} navCtrl Ionic导航控制器 
+   * @param {Router} router Angular路由服务
+   * 
+   * @description
+   * 初始化时添加所需图标
+   */
+  constructor(private navCtrl: NavController, private router: Router) { 
     addIcons({ heart, heartOutline, trash });
   }
-  ngOnInit() {
-    // // 模拟数据 - 实际应该从本地存储获取
-    // this.historyList = [
-    //   {
-    //     id: 1,
-    //     name: '意大利肉酱面',
-    //     image: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb'
-    //   },
-    //   {
-    //     id: 2,
-    //     name: '奶油蘑菇汤',
-    //     image: 'https://images.unsplash.com/photo-1547592180-85f173990554'
-    //   },
-    //   {
-    //     id: 3,
-    //     name: '番茄炒蛋',
-    //     image: 'https://images.unsplash.com/photo-1582456891920-7a6a13cc5c4a'
-    //   }
-    // ];
+
+  /**
+   * 组件初始化生命周期钩子
+   * @returns {void}
+   */
+  ngOnInit(): void {
     this.loadRecipeFavoriteList();
   }
 
-  recipeRecordList: CloudObject[] = []; // 存储RecipeFavorite的CloudObject
-  recipeDataList: any[] = []; // 存储Recipe表的完整data数据
-  
-  async loadRecipeFavoriteList() {
+  /**
+   * 食谱浏览记录列表
+   * @type {CloudObject[]}
+   */
+  recipeRecordList: CloudObject[] = [];
+
+  /**
+   * 食谱数据列表
+   * @type {any[]}
+   */
+  recipeDataList: any[] = [];
+
+  /**
+   * 加载用户浏览历史记录
+   * @async
+   * @returns {Promise<void>}
+   * 
+   * @description
+   * 从云端查询用户浏览过的食谱历史记录,并关联查询完整的食谱数据
+   */
+  async loadRecipeFavoriteList(): Promise<void> {
     const query = new CloudQuery("RecipeHistory");
-    query.include("recipe"); // 联查Recipe表
+    query.include("recipe"); // 联查Recipe表
     const favorites = await query.find();
 
-    console.log('favorites',favorites);
-    
+    console.log('浏览历史记录:', favorites);
     
     this.recipeRecordList = favorites.map(fav => fav.get("recipe"));
-    // this.recipeDataList = this.recipeFavoriteList.map(recipe => recipe.data);
-    
-    console.log("Recipe数据列表:", this.recipeRecordList);
+    console.log("食谱数据列表:", this.recipeRecordList);
   }
 
-  goToDetail(recipeId: any) {
-    // this.navCtrl.navigateForward(["tabs", "tab1", "page-detail", recipe.objectId]);
+  /**
+   * 导航到历史记录详情页面
+   * @param {any} recipeId 食谱ID
+   * @returns {void}
+   * 
+   * @description
+   * 跳转到指定食谱的浏览记录详情页面
+   */
+  goToDetail(recipeId: any): void {
     this.navCtrl.navigateForward(`/tabs/tab3/page-records/page-records-detail/${recipeId}`);
-    console.log('Navigating to page-detail');
+    console.log('正在跳转到详情页面');
+  }
+
+  // 以下是预设数据(已注释)
+  /**
+   * @ignore
+   * 加载模拟历史记录数据
+   * @returns {void}
+   */
+  /*
+  ngOnInit(): void {
+    this.historyList = [
+      {
+        id: 1,
+        name: '意大利肉酱面',
+        image: 'https://images.unsplash.com/photo-1555949258-eb67b1ef0ceb'
+      },
+      // ...其他模拟数据
+    ];
   }
+  */
 }

+ 87 - 76
myapp/src/app/tab3/tab3.page.ts

@@ -1,80 +1,46 @@
 // tab3.page.ts
 import { Component } from '@angular/core';
 import { ModalController, NavController } from '@ionic/angular';
-// import { ModalUserLoginComponent } from 'fmode-ng';
 import { ModalUserEditComponent } from '../../lib/user/modal-user-edit/modal-user-edit.component';
 import { CloudApi, CloudUser } from 'src/lib/ncloud';
 import { 
-  IonHeader, 
-  IonToolbar, 
-  IonTitle, 
-  IonContent, 
-  IonButton, 
-  IonIcon, 
-  IonCard, 
-  IonCardHeader, 
-  IonCardTitle, 
-  IonCardSubtitle, 
-  IonCardContent,
-  IonGrid,
-  IonRow,
-  IonCol,
-  IonList,
-  IonItem,
-  IonLabel,
-  IonNote,
-  IonBadge,
-  IonAvatar,
-  IonText,
-  IonButtons
+  IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonIcon, 
+  IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent,
+  IonGrid, IonRow, IonCol, IonList, IonItem, IonLabel, IonNote,
+  IonBadge, IonAvatar, IonText, IonButtons
 } from '@ionic/angular/standalone';
 import { addIcons } from 'ionicons';
 import { 
-  settings, 
-  time, 
-  heart, 
-  create, 
-  chatbubbles, 
-  shieldCheckmark, 
-  documentText, 
-  logIn, 
-  logOut, 
-  personAdd 
+  settings, time, heart, create, chatbubbles, 
+  shieldCheckmark, documentText, logIn, logOut, personAdd 
 } from 'ionicons/icons';
 
+/**
+ * 个人中心页面组件
+ * @Component 装饰器定义组件元数据
+ * @description 提供用户个人中心功能,包括登录/注销、编辑资料、查看收藏和记录等
+ */
 @Component({
   selector: 'app-tab3',
   templateUrl: 'tab3.page.html',
   styleUrls: ['tab3.page.scss'],
-  standalone: false,
-  // imports: [
-  //   IonHeader, 
-  //   IonToolbar, 
-  //   IonTitle, 
-  //   IonContent, 
-  //   IonButton, 
-  //   IonIcon, 
-  //   IonCard, 
-  //   IonCardHeader, 
-  //   IonCardTitle, 
-  //   IonCardSubtitle, 
-  //   IonCardContent,
-  //   IonGrid,
-  //   IonRow,
-  //   IonCol,
-  //   IonList,
-  //   IonItem,
-  //   IonLabel,
-  //   IonNote,
-  //   IonBadge,
-  //   IonAvatar,
-  //   IonText,
-  //   IonButtons
-  // ]
+  standalone: false
 })
 export class Tab3Page {
+  /**
+   * 当前登录用户
+   * @type {CloudUser | undefined}
+   */
   currentUser: CloudUser | undefined;
 
+  /**
+   * 构造函数
+   * @param {NavController} navCtrl 导航控制器
+   * @param {ModalController} modalCtrl 模态控制器
+   * 
+   * @description 
+   * 初始化用户实例并添加所需图标
+   */
   constructor(private navCtrl: NavController, private modalCtrl: ModalController) { 
     this.currentUser = new CloudUser();
     addIcons({
@@ -83,7 +49,15 @@ export class Tab3Page {
     });
   }
 
-  handleAction(type: string) {
+  /**
+   * 处理按钮点击动作
+   * @param {string} type 动作类型
+   * @returns {void}
+   * 
+   * @example
+   * handleAction('feedback'); // 处理意见反馈
+   */
+  handleAction(type: string): void {
     switch(type) {
       case 'feedback':
         console.log('打开意见反馈');
@@ -96,36 +70,73 @@ export class Tab3Page {
         break;
     }
   }
-  async login() {
-    let user : any = new CloudUser();
-     user = await this.currentUser?.login("0224989","123456")
-      if(user?.id){
-        this.currentUser = user;
-      }
+
+  /**
+   * 用户登录
+   * @async
+   * @returns {Promise<void>}
+   * 
+   * @description
+   * 使用用户名和密码登录,成功后更新当前用户信息
+   */
+  async login(): Promise<void> {
+    let user: any = new CloudUser();
+    user = await this.currentUser?.login("0224989", "123456");
+    if(user?.id){
+      this.currentUser = user;
     }
-  logout() {
-   this.currentUser?.logout();
-   this.currentUser = undefined;
   }
-  async edit(){
+
+  /**
+   * 用户注销
+   * @returns {void}
+   * 
+   * @description
+   * 注销当前用户并清空用户信息
+   */
+  logout(): void {
+    this.currentUser?.logout();
+    this.currentUser = undefined;
+  }
+
+  /**
+   * 打开用户编辑模态框
+   * @async
+   * @returns {Promise<void>}
+   */
+  async edit(): Promise<void> {
     const modal = await this.modalCtrl.create({
-      component:ModalUserEditComponent,
+      component: ModalUserEditComponent,
     });
     modal.present();
-    const {data,role} = await modal.onWillDismiss();
+    const {data, role} = await modal.onWillDismiss();
   }
-  goToRecords() {
+
+  /**
+   * 导航到记录页面
+   * @returns {void}
+   */
+  goToRecords(): void {
     this.navCtrl.navigateForward(["tabs","tab3","page-records"]);
     console.log('Navigating to page-records');
   }
-  goToCollections() {
+
+  /**
+   * 导航到收藏页面
+   * @returns {void}
+   */
+  goToCollections(): void {
     this.navCtrl.navigateForward(["tabs","tab3","page-collections"]);
     console.log('Navigating to page-collections');
   }
-  goToDetail(recipeId: any) {
-    // this.navCtrl.navigateForward(["tabs", "tab1", "page-detail", recipe.objectId]);
+
+  /**
+   * 导航到食谱详情页面
+   * @param {any} recipeId 食谱ID
+   * @returns {void}
+   */
+  goToDetail(recipeId: any): void {
     this.navCtrl.navigateForward(`/tabs/tab1/page-detail/${recipeId}`);
     console.log('Navigating to page-detail');
   }
-
 }

+ 3 - 0
myapp/tsconfig.doc.json

@@ -0,0 +1,3 @@
+{
+    "include": ["src/**/*.ts"]
+}