tab1.page.ts 4.5 KB

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