tab2.page.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { Component } from '@angular/core';
  2. import { ModalController, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonAvatar, IonButton, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton, IonFabList, IonFooter, IonInput } from '@ionic/angular/standalone';
  3. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  4. import { addIcons } from 'ionicons';
  5. import { airplane, bluetooth, call, wifi } from 'ionicons/icons';
  6. import { ArticleCardComponent } from '../component/article-card/article-card.component';
  7. import { CommonModule } from '@angular/common';
  8. import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
  9. import { NavigationLanComponent } from '../component/navigation-lan/navigation-lan.component';
  10. import { Router } from '@angular/router';
  11. import {
  12. chevronDownCircle,
  13. chevronForwardCircle,
  14. chevronUpCircle,
  15. colorPalette,
  16. document,
  17. globe,
  18. } from 'ionicons/icons';
  19. import { FormsModule } from '@angular/forms';
  20. addIcons({ airplane, bluetooth, call, wifi });
  21. addIcons({ chevronDownCircle, chevronForwardCircle, chevronUpCircle, colorPalette, document, globe });
  22. @Component({
  23. selector: 'app-tab2',
  24. templateUrl: 'tab2.page.html',
  25. styleUrls: ['tab2.page.scss'],
  26. standalone: true,
  27. imports: [
  28. IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
  29. IonLabel,IonItem,IonList,IonAvatar,ArticleCardComponent,CommonModule,IonButton,
  30. IonSegment, IonSegmentButton,NavigationLanComponent,
  31. IonSegmentContent,IonSegmentView,IonCardContent, IonCardTitle, IonCardHeader,IonCard,
  32. IonModal,IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton,IonFabList,IonFooter,
  33. IonInput,IonSegment,IonSegmentButton,FormsModule
  34. ]
  35. })
  36. export class Tab2Page {
  37. selectedSegment:string = '热点';
  38. segments = [ '热点', '专家科普', '睡眠', '生活', '男性', '女性', '两性', '辟谣', '母婴', '美容'];
  39. segmentChanged(event: any) {
  40. this.selectedSegment = event.detail.value;
  41. console.log(this.selectedSegment);
  42. this.loadCards(); // 重新加载卡片
  43. }
  44. /**
  45. * 轮播图
  46. */
  47. images = [
  48. 'https://picsum.photos/800/400?random=7',
  49. 'https://picsum.photos/800/400?random=8',
  50. 'https://picsum.photos/800/400?random=9',
  51. 'https://picsum.photos/800/400?random10',
  52. 'https://picsum.photos/800/400?random=11',
  53. 'https://picsum.photos/800/400?random=12',
  54. ];
  55. currentSlide = 0;
  56. intervalId: any;
  57. setSlidePosition() {
  58. // 这里不需要额外的逻辑,因为在 HTML 中已经通过绑定实现
  59. }
  60. nextSlide() {
  61. this.currentSlide = (this.currentSlide + 1) % this.images.length;
  62. }
  63. prevSlide() {
  64. this.currentSlide = (this.currentSlide - 1 + this.images.length) % this.images.length;
  65. }
  66. goToSlide(index: number) {
  67. this.currentSlide = index;
  68. }
  69. startAutoSlide() {
  70. this.intervalId = setInterval(() => this.nextSlide(), 3000);
  71. }
  72. products: Array<CloudObject> = []; // 当前显示的科普信息
  73. allCards: Array<CloudObject> = []; // 所有科普信息
  74. //搜索功能
  75. searchTerm: string = '';
  76. async searchProducts(event: any) {
  77. this.searchTerm = event.detail.value.toLowerCase();
  78. if (this.searchTerm) {
  79. this.products = this.allCards.filter(product =>
  80. product.get('topic').toLowerCase().includes(this.searchTerm) ||
  81. product.get('title').toLowerCase().includes(this.searchTerm) ||
  82. product.get('category').toLowerCase().includes(this.searchTerm) ||
  83. product.get('content')[0].toLowerCase().includes(this.searchTerm)
  84. );
  85. } else {
  86. this.products = [...this.allCards]; // 如果搜索词为空,则显示所有科普信息
  87. }
  88. }
  89. isModalOpen = false;
  90. currentProduct: any; // 当前选择的科普信息
  91. openDetailModal(product?: any) {
  92. let user = new CloudUser;
  93. if (!user.id){
  94. this.router.navigate(['/tabs/tab4'])
  95. return
  96. }
  97. this.isModalOpen = true;
  98. this.currentProduct = product;
  99. }
  100. closeDetailModal() {
  101. this.isModalOpen = false;
  102. this.currentProduct = null;
  103. }
  104. shareDetail = false;
  105. shareDetailModal() {
  106. this.shareDetail = true;
  107. // 在这里确保模态框的aria-hidden属性被正确处理
  108. // setTimeout(() => {
  109. // const modalElement = document.querySelector('ion-modal');
  110. // if (modalElement) {
  111. // modalElement.setAttribute('aria-hidden', 'false');
  112. // }
  113. // }, 0);
  114. }
  115. closeShareModal(){
  116. this.shareDetail = false;
  117. }
  118. copyLink() {
  119. console.log('复制链接');
  120. }
  121. // type:"HotDot"|"export"|"sleep"|"life"|"男"|"女" = "HotDot"
  122. constructor(
  123. private modalCtrl:ModalController,
  124. private router:Router,
  125. ) {
  126. }
  127. cards: Array<CloudObject> = []; // 当前显示的分类卡片
  128. // async typeChange(ev: any) {
  129. // this.type = ev?.detail?.value || ev?.value || 'HotDot';
  130. // console.log(this.type);
  131. // await this.loadCards(); // 重新加载卡片
  132. // }
  133. async loadAllCards() {
  134. const query = new CloudQuery('HotDot');
  135. this.allCards = await query.find();
  136. }
  137. async loadCards() {
  138. const query = new CloudQuery('HotDot');
  139. query.equalTo('category', this.selectedSegment);
  140. this.cards = await query.find();
  141. }
  142. publishHealthInfo() {
  143. // 这里可以添加发布求医信息的逻辑
  144. console.log('发布求医信息');
  145. }
  146. openAiKnowledge(){
  147. this.router.navigate(['tabs/ai-knowledge']);
  148. }
  149. ngOnInit() {
  150. this.loadAllCards();
  151. this.loadCards(); // 初始化时加载所有科普信息
  152. }
  153. comment:string = ''
  154. onCommentInput(e:any){
  155. this.comment = e.detail.value
  156. console.log(this.comment);
  157. }
  158. postComment(){
  159. console.log('发布评论');
  160. }
  161. }