tab1.page.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { Router } from '@angular/router';
  2. import { Component, ElementRef, OnInit, ViewChild,ChangeDetectorRef } from '@angular/core';
  3. import Swiper from 'swiper';
  4. import Parse from 'parse';
  5. import { FilmService } from 'src/modules/server/firm.serve';
  6. import { BookService } from 'src/modules/server/book.serve';
  7. import { MusicService } from 'src/modules/server/music.serve';
  8. import { GameService } from 'src/modules/server/game.serve';
  9. import { OutdoorService } from 'src/modules/server/outdoor.serve';
  10. @Component({
  11. selector: 'app-tab1',
  12. templateUrl: 'tab1.page.html',
  13. styleUrls: ['tab1.page.scss']
  14. })
  15. export class Tab1Page implements OnInit {
  16. @ViewChild("slide1Comp") slide1Comp:ElementRef |undefined
  17. constructor(private cdr: ChangeDetectorRef,
  18. private filmService: FilmService,
  19. private router: Router,
  20. private bookService: BookService,
  21. private musicService: MusicService,
  22. private gameService: GameService,
  23. private outdoorService: OutdoorService,
  24. ) { }
  25. ngOnInit() {
  26. // 延迟500毫秒加载
  27. setTimeout(() => {
  28. this.initSwiper();
  29. }, 500);
  30. }
  31. // 初始化轮播图
  32. slide1:Swiper|undefined
  33. initSwiper(){
  34. console.log(this.slide1Comp)
  35. this.slide1 = new Swiper(this.slide1Comp?.nativeElement, {
  36. loop:true,
  37. autoplay:{
  38. delay:200,
  39. },
  40. mousewheel: {
  41. forceToAxis: true,
  42. },
  43. pagination:{
  44. el:".swiper-pagination",
  45. clickable:true
  46. }
  47. });
  48. setInterval(()=>{
  49. this.slide1?.slideNext();
  50. },1000)
  51. }
  52. filmsearchResults: any[] = [];
  53. booksearchResults: any[] = [];
  54. gamesearchResults: any[] = [];
  55. musicsearchResults: any[] = [];
  56. outdoorsearchResults: any[] = [];
  57. searchTerm: string = '';
  58. searchName: string = '';
  59. async search(){
  60. const queryParams = {
  61. name: this.searchTerm
  62. };
  63. this.filmsearchResults=await this.filmService.searchFilm(queryParams);
  64. this.booksearchResults=await this.bookService.getBooks(queryParams);
  65. this.musicsearchResults=await this.musicService.getMusics(queryParams);
  66. this.gamesearchResults=await this.gameService.getGames(queryParams);
  67. this.outdoorsearchResults=await this.outdoorService.getOutdoors(queryParams);
  68. const keywords = ['影', '视', '影片']; // 定义多个关键词
  69. if (keywords.some(keyword => this.searchTerm.toLowerCase().includes(keyword))) {
  70. this.router.navigate(['/feiwu/fiml']); // 如果包含任何一个关键词,则跳转到“影视”界面
  71. }
  72. const keywords2 = ['书', '小说']; // 定义多个关键词
  73. if (keywords2.some(keyword2 => this.searchTerm.toLowerCase().includes(keyword2))) {
  74. this.router.navigate(['/feiwu/book']); // 如果包含任何一个关键词,则跳转到“影视”界面
  75. }
  76. const keywords3 = ['音乐', '歌', '曲','听']; // 定义多个关键词
  77. if (keywords3.some(keyword3 => this.searchTerm.toLowerCase().includes(keyword3))) {
  78. this.router.navigate(['/feiwu/music']); // 如果包含任何一个关键词,则跳转到“影视”界面
  79. }
  80. const keywords4 = ['游戏', '玩']; // 定义多个关键词
  81. if (keywords4.some(keyword4 => this.searchTerm.toLowerCase().includes(keyword4))) {
  82. this.router.navigate(['/feiwu/game']); // 如果包含任何一个关键词,则跳转到“影视”界面
  83. }
  84. const keywords5 = ['运动', '户外', '锻炼','健']; // 定义多个关键词
  85. if (keywords5.some(keyword5=> this.searchTerm.toLowerCase().includes(keyword5))) {
  86. this.router.navigate(['/feiwu/outdoor']); // 如果包含任何一个关键词,则跳转到“影视”界面
  87. }
  88. if(!this.searchTerm)
  89. {
  90. this.filmsearchResults = []
  91. this.booksearchResults = []
  92. this.gamesearchResults = []
  93. this.musicsearchResults = []
  94. this.outdoorsearchResults =[]
  95. }
  96. }
  97. // async search(keyword: string) {
  98. // const Film = Parse.Object.extend('Film');
  99. // const LQLBook = Parse.Object.extend('LQLBook');
  100. // const LQLGame = Parse.Object.extend('LQLGame');
  101. // const LQLMusic = Parse.Object.extend('LQLMusic');
  102. // const LQLOutdoor = Parse.Object.extend('LQLOutdoor');
  103. // const filmQuery = new Parse.Query(Film);
  104. // const bookQuery = new Parse.Query(LQLBook);
  105. // const gameQuery = new Parse.Query(LQLGame);
  106. // const musicQuery = new Parse.Query(LQLMusic);
  107. // const outdoorQuery = new Parse.Query(LQLOutdoor);
  108. // filmQuery.startsWith('name', keyword);
  109. // bookQuery.startsWith('name', keyword);
  110. // gameQuery.startsWith('name', keyword);
  111. // musicQuery.startsWith('name', keyword);
  112. // outdoorQuery.startsWith('name', keyword);
  113. // const filmresults = await filmQuery.find();
  114. // const bookresults = await bookQuery.find();
  115. // const gameresults = await gameQuery.find();
  116. // const musicresults = await musicQuery.find();
  117. // const outdoorresults = await outdoorQuery.find();
  118. // this.filmsearchResults = filmresults.map(filmresult => filmresult.toJSON());
  119. // this.booksearchResults = bookresults.map(bookresult => bookresult.toJSON());
  120. // this.gamesearchResults = gameresults.map(gameresult => gameresult.toJSON());
  121. // this.musicsearchResults = musicresults.map(musicresult => musicresult.toJSON());
  122. // this.outdoorsearchResults = outdoorresults.map(outdoorresult => outdoorresult.toJSON());
  123. // if(!this.searchTerm)
  124. // {
  125. // this.filmsearchResults = []
  126. // this.booksearchResults = []
  127. // this.gamesearchResults = []
  128. // this.musicsearchResults = []
  129. // this.outdoorsearchResults =[]
  130. // }
  131. // this.cdr.detectChanges();
  132. // }
  133. }
  134. function searchContent(event: Event | undefined, CustomEvent: { new <T>(type: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>; prototype: CustomEvent; }) {
  135. throw new Error('Function not implemented.');
  136. }