tab1.page_20241224093033.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { Component,CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
  2. import { IonHeader, IonToolbar, IonTitle, IonContent, IonAvatar, IonButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonLabel, IonList,
  3. IonItem,IonIcon,IonInput,IonSearchbar} from '@ionic/angular/standalone';
  4. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  5. import { CommonModule } from '@angular/common';
  6. import { TopicDetailComponent } from '../topic-detail/topic-detail.component';
  7. import { Router } from '@angular/router';
  8. import { TopicDetail2Component } from '../topic-detail2/topic-detail2.component';
  9. import { TopicDetail3Component } from '../topic-detail3/topic-detail3.component';
  10. import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
  11. import { ModalController } from '@ionic/angular/standalone';
  12. import { openUserEvaModal } from '../user-evaluate/user-evaluate.component';
  13. import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
  14. @Component({
  15. selector: 'app-tab1',
  16. templateUrl: 'tab1.page.html',
  17. styleUrls: ['tab1.page.scss'],
  18. standalone: true,
  19. imports: [IonHeader,IonToolbar,IonTitle,IonContent,ExploreContainerComponent,
  20. IonButtons,IonButton,IonIcon,
  21. IonCard,IonCardContent,IonCardHeader,
  22. IonLabel,IonList,IonItem,IonAvatar,
  23. IonInput,IonSearchbar,
  24. CommonModule,
  25. TopicDetailComponent,TopicDetail2Component,TopicDetail3Component
  26. ],
  27. schemas: [CUSTOM_ELEMENTS_SCHEMA],
  28. })
  29. export class Tab1Page {
  30. onSearch(event: any) {
  31. const searchTerm = event.target.value; // 获取用户输入的搜索内容
  32. console.log('搜索内容:', searchTerm);
  33. // 在这里添加搜索逻辑,例如过滤列表或导航到搜索结果页面
  34. }
  35. topics = [
  36. {
  37. id: 1,
  38. title: '如何管理焦虑情绪',
  39. description: '了解焦虑的来源及应对策略',
  40. detailRoute: 'topic-detail',
  41. },
  42. {
  43. id: 2,
  44. title: '克服抑郁的有效方法',
  45. description: '探索抑郁症的应对技巧',
  46. detailRoute: 'topic-detail2'
  47. },
  48. {
  49. id: 3,
  50. title: '提升自信心的技巧',
  51. description: '学习如何建立自信',
  52. detailRoute: 'topic-detail2'
  53. }
  54. ];
  55. goPsysurvey() {
  56. this.router.navigate(['tabs/page-psysurvey'])
  57. }
  58. goDriftbottle() {
  59. this.router.navigate(['tabs/drift-bottle'])
  60. }
  61. viewDetails(topicId: number): void {
  62. let route: string;
  63. switch (topicId) {
  64. case 1:
  65. route = 'topic-detail';
  66. break;
  67. case 2:
  68. route = 'topic-detail2';
  69. break;
  70. case 3:
  71. route = 'topic-detail3';
  72. break;
  73. default:
  74. route = 'topic-detail'; // 默认路由
  75. }
  76. // 导航到指定的路由,并可以传递参数
  77. this.router.navigate([`tabs/${route}`, { id: topicId }]);
  78. }
  79. constructor(private router: Router,private modalCtrl: ModalController) {
  80. // 其他构造函数代码
  81. }
  82. matchedCounselor: { content: string; rating: number } | null = null;
  83. review: any = { rating: 5 }; // 示例数据
  84. // 创建一个方法,用于生成填充了 null 的数组
  85. createFilledArray(length: number): any[] {
  86. return Array(length).fill(null);
  87. }
  88. async evaluate() {
  89. // 处理点击评价的逻辑
  90. // 验证用户登录
  91. let currentUser = new CloudUser();
  92. let userPrompt = ``
  93. if(!currentUser?.id){
  94. console.log("用户未登录,请登录后重试")
  95. let user = await openUserLoginModal(this.modalCtrl)
  96. if(!user?.id){
  97. console.log("用户登录失败");
  98. return
  99. }
  100. else {
  101. console.log("当前用户ID:", currentUser.id);
  102. }
  103. }
  104. // 打开评价模态框
  105. const evaluationResult = await openUserEvaModal(this.modalCtrl);
  106. // 如果评价成功,重新加载评价列表
  107. if (evaluationResult) {
  108. await this.loadChatEvaluateList(); // 重新加载评价列表
  109. }
  110. }
  111. ngOnInit() {
  112. this.loadChatEvaluateList()
  113. }
  114. chatevaluateList:Array<CloudObject>=[]
  115. async loadChatEvaluateList(){
  116. let query = new CloudQuery("ChatEvaluate");
  117. this.chatevaluateList = await query.find()
  118. }
  119. }