tab2.page.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 } 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 } 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. addIcons({ airplane, bluetooth, call, wifi });
  20. addIcons({ chevronDownCircle, chevronForwardCircle, chevronUpCircle, colorPalette, document, globe });
  21. @Component({
  22. selector: 'app-tab2',
  23. templateUrl: 'tab2.page.html',
  24. styleUrls: ['tab2.page.scss'],
  25. standalone: true,
  26. imports: [
  27. IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
  28. IonLabel,IonItem,IonList,IonAvatar,ArticleCardComponent,CommonModule,IonButton,
  29. IonSegment, IonSegmentButton,NavigationLanComponent,
  30. IonSegmentContent,IonSegmentView,IonCardContent, IonCardTitle, IonCardHeader,IonCard,
  31. IonModal,IonIcon, IonButtons, IonSearchbar, IonFab, IonFabButton,IonFabList,
  32. ]
  33. })
  34. export class Tab2Page {
  35. /**
  36. * 轮播图
  37. */
  38. images = [
  39. 'https://picsum.photos/800/400?random=1',
  40. 'https://picsum.photos/800/400?random=2',
  41. 'https://picsum.photos/800/400?random=3',
  42. 'https://picsum.photos/800/400?random=4',
  43. 'https://picsum.photos/800/400?random=5',
  44. 'https://picsum.photos/800/400?random=6',
  45. ];
  46. currentSlide = 0;
  47. intervalId: any;
  48. setSlidePosition() {
  49. // 这里不需要额外的逻辑,因为在 HTML 中已经通过绑定实现
  50. }
  51. nextSlide() {
  52. this.currentSlide = (this.currentSlide + 1) % this.images.length;
  53. }
  54. prevSlide() {
  55. this.currentSlide = (this.currentSlide - 1 + this.images.length) % this.images.length;
  56. }
  57. goToSlide(index: number) {
  58. this.currentSlide = index;
  59. }
  60. startAutoSlide() {
  61. this.intervalId = setInterval(() => this.nextSlide(), 3000);
  62. }
  63. products: Array<CloudObject> = []; // 当前显示的科普信息
  64. allCards: Array<CloudObject> = []; // 所有科普信息
  65. //搜索功能
  66. searchTerm: string = '';
  67. async searchProducts(event: any) {
  68. this.searchTerm = event.detail.value.toLowerCase();
  69. if (this.searchTerm) {
  70. this.products = this.allCards.filter(product =>
  71. product.get('topic').toLowerCase().includes(this.searchTerm) ||
  72. product.get('title').toLowerCase().includes(this.searchTerm) ||
  73. product.get('category').toLowerCase().includes(this.searchTerm) ||
  74. product.get('content')[0].toLowerCase().includes(this.searchTerm)
  75. );
  76. } else {
  77. this.products = [...this.allCards]; // 如果搜索词为空,则显示所有科普信息
  78. }
  79. }
  80. isModalOpen = false;
  81. currentProduct: any; // 当前选择的科普信息
  82. openDetailModal(product?: any) {
  83. this.isModalOpen = true;
  84. this.currentProduct = product;
  85. }
  86. closeDetailModal() {
  87. this.isModalOpen = false;
  88. this.currentProduct = null;
  89. }
  90. shareDetail = false;
  91. shareDetailModal() {
  92. this.shareDetail = true;
  93. // 在这里确保模态框的aria-hidden属性被正确处理
  94. // setTimeout(() => {
  95. // const modalElement = document.querySelector('ion-modal');
  96. // if (modalElement) {
  97. // modalElement.setAttribute('aria-hidden', 'false');
  98. // }
  99. // }, 0);
  100. }
  101. closeShareModal(){
  102. this.shareDetail = false;
  103. }
  104. copyLink() {
  105. console.log('复制链接');
  106. }
  107. type:"hotdot"|"export"|"sleep"|"life"|"男"|"女" = "hotdot"
  108. constructor(
  109. private modalCtrl:ModalController,
  110. private router:Router,
  111. ) {
  112. this.loadCards(); // 初始化时加载所有科普信息
  113. }
  114. cards: Array<CloudObject> = []; // 当前显示的分类卡片
  115. async typeChange(ev: any) {
  116. this.type = ev?.detail?.value || ev?.value || 'hotdot';
  117. console.log(this.type);
  118. await this.loadCards(); // 重新加载卡片
  119. }
  120. async loadCards() {
  121. const query = new CloudQuery('HotDot');
  122. this.allCards = await query.find(); // 执行查询并获取结果
  123. this.cards = this.allCards.filter((card) => card.get('category').toLowerCase().includes(this.type));
  124. }
  125. publishHealthInfo() {
  126. // 这里可以添加发布求医信息的逻辑
  127. console.log('发布求医信息');
  128. }
  129. openAiKnowledge(){
  130. this.router.navigate(['tabs/ai-knowledge']);
  131. }
  132. ngOnInit() {
  133. }
  134. }