소스 검색

add:main search

娱乐之上 4 달 전
부모
커밋
cc25235ab3
6개의 변경된 파일189개의 추가작업 그리고 17개의 파일을 삭제
  1. 10 1
      server/import/README.md
  2. 23 1
      src/app/tab1/tab1.page.html
  3. 135 2
      src/app/tab1/tab1.page.ts
  4. 1 1
      src/modules/feiwu/fiml/fiml.page.html
  5. 13 11
      src/modules/feiwu/fiml/fiml.page.ts
  6. 7 1
      src/modules/server/firm.serve.ts

+ 10 - 1
server/import/README.md

@@ -50,4 +50,13 @@
 
 
   # 星星打分系统
-  - 我正在编写一个影视的页面,前端框架使用ionic7的angular版本,数据请求使用Parse JS SDK。 其中影视的Schema名称为Film,字段name:String 影视名称、detail:String 对该影视介绍、rating:Number 评分(十分制)、image:string 图标地址。现在我要制作一个可以给每个影视评分的评分系统,评价的分数还要与rating取平均值,再传回Film的rating中。
+  - 我正在编写一个影视的页面,前端框架使用ionic7的angular版本,数据请求使用Parse JS SDK。 其中影视的Schema名称为Film,字段name:String 影视名称、detail:String 对该影视介绍、rating:Number 评分(十分制)、image:string 图标地址。现在我要制作一个可以给每个影视评分的评分系统,评价的分数还要与rating取平均值,再传回Film的rating中。
+
+
+
+
+
+
+
+  # 主页面搜索功能
+  - 我正在编写一个搜索功能,前端框架使用ionic7的angular版本,搜索的数据是Parse JS SDK中的五个Schema,这五个Schema的名称分别为Film、LQLBook、LQLGame、LQLMusic、LQLOutdoor,通过检索这五个Schema的name来搜索对应的对象,且每填写一个字都能搜索出对应的对象。请帮我完成我所说的功能。

+ 23 - 1
src/app/tab1/tab1.page.html

@@ -6,7 +6,29 @@
 
 <ion-content color="light">
   <!-- 搜索栏 -->
-  <ion-searchbar></ion-searchbar>
+  <ion-toolbar>
+    <ion-searchbar [(ngModel)]="searchTerm" (ionChange)="search()"></ion-searchbar>
+    
+    
+  </ion-toolbar>
+  <ion-list>
+    <ion-button *ngFor="let filmresult of filmsearchResults" routerLink="/feiwu/film-detail/{{filmresult.id}}">
+      {{ filmresult.get('name') }}
+    </ion-button>
+    <ion-button *ngFor="let bookresult of booksearchResults" routerLink="/feiwu/book-detail/{{bookresult.id}}">
+      {{ bookresult.get('name') }}
+    </ion-button>
+    <ion-button *ngFor="let gameresult of gamesearchResults" routerLink="/feiwu/game-detail/{{gameresult.id}}">
+      {{ gameresult.get('name') }}
+    </ion-button>
+    <ion-button *ngFor="let musicresult of musicsearchResults" routerLink="/feiwu/music-detail/{{musicresult.id}}">
+      {{ musicresult.get('name') }}
+    </ion-button>
+    <ion-button *ngFor="let outdoorresult of outdoorsearchResults" routerLink="/feiwu/outdoor-detail/{{outdoorresult.id}}">
+      {{ outdoorresult.get('name') }}
+    </ion-button>
+  </ion-list>
+
 
   <!-- 分类选项 -->
   <ion-segment>

+ 135 - 2
src/app/tab1/tab1.page.ts

@@ -1,8 +1,15 @@
 
 import { Router } from '@angular/router';
-import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
+import { Component, ElementRef, OnInit, ViewChild,ChangeDetectorRef } from '@angular/core';
 
 import Swiper from 'swiper';
+import Parse from 'parse';
+import { FilmService } from 'src/modules/server/firm.serve';
+import { BookService } from 'src/modules/server/book.serve';
+import { MusicService } from 'src/modules/server/music.serve';
+import { GameService } from 'src/modules/server/game.serve';
+import { OutdoorService } from 'src/modules/server/outdoor.serve';
+
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
@@ -12,8 +19,20 @@ import Swiper from 'swiper';
 
 export class Tab1Page implements OnInit {
  
+  
   @ViewChild("slide1Comp") slide1Comp:ElementRef |undefined
-  constructor() { }
+
+
+  constructor(private cdr: ChangeDetectorRef,
+    private filmService: FilmService,
+    private router: Router,
+    private bookService: BookService,
+    private musicService: MusicService,
+    private gameService: GameService,
+    private outdoorService: OutdoorService,
+  ) { }
+  
+
 
   ngOnInit() {
     // 延迟500毫秒加载
@@ -45,7 +64,121 @@ export class Tab1Page implements OnInit {
     },1000)
   }
 
+  
+
+  filmsearchResults: any[] = [];
+  booksearchResults: any[] = [];
+  gamesearchResults: any[] = [];
+  musicsearchResults: any[] = [];
+  outdoorsearchResults: any[] = [];
+  searchTerm: string = '';
+  searchName: string = '';
+
+  async search(){
+    const queryParams = {
+      name: this.searchTerm
+      
+    };
+    
+    this.filmsearchResults=await this.filmService.searchFilm(queryParams);
+    this.booksearchResults=await this.bookService.getBooks(queryParams);
+    this.musicsearchResults=await this.musicService.getMusics(queryParams);
+    this.gamesearchResults=await this.gameService.getGames(queryParams);
+    this.outdoorsearchResults=await this.outdoorService.getOutdoors(queryParams);
+    
+    const keywords = ['影', '视', '影片']; // 定义多个关键词
+    if (keywords.some(keyword => this.searchTerm.toLowerCase().includes(keyword))) {
+      this.router.navigate(['/feiwu/fiml']); // 如果包含任何一个关键词,则跳转到“影视”界面
+    }
+    const keywords2 = ['书', '小说']; // 定义多个关键词
+    if (keywords2.some(keyword2 => this.searchTerm.toLowerCase().includes(keyword2))) {
+      this.router.navigate(['/feiwu/book']); // 如果包含任何一个关键词,则跳转到“影视”界面
+    }
+    const keywords3 = ['音乐', '歌', '曲','听']; // 定义多个关键词
+    if (keywords3.some(keyword3 => this.searchTerm.toLowerCase().includes(keyword3))) {
+      this.router.navigate(['/feiwu/music']); // 如果包含任何一个关键词,则跳转到“影视”界面
+    }
+    const keywords4 = ['游戏', '玩']; // 定义多个关键词
+    if (keywords4.some(keyword4 => this.searchTerm.toLowerCase().includes(keyword4))) {
+      this.router.navigate(['/feiwu/game']); // 如果包含任何一个关键词,则跳转到“影视”界面
+    }
+    const keywords5 = ['运动', '户外', '锻炼','健']; // 定义多个关键词
+    if (keywords5.some(keyword5=> this.searchTerm.toLowerCase().includes(keyword5))) {
+      this.router.navigate(['/feiwu/outdoor']); // 如果包含任何一个关键词,则跳转到“影视”界面
+    }
+
+
+
+    
+   if(!this.searchTerm)
+    {
+      this.filmsearchResults = []
+      this.booksearchResults = []
+      this.gamesearchResults = []
+      this.musicsearchResults = []
+      this.outdoorsearchResults =[] 
+  }
+
+  
+  }
+
+
+
+  // async search(keyword: string) {
+  //   const Film = Parse.Object.extend('Film');
+  //   const LQLBook = Parse.Object.extend('LQLBook');
+  //   const LQLGame = Parse.Object.extend('LQLGame');
+  //   const LQLMusic = Parse.Object.extend('LQLMusic');
+  //   const LQLOutdoor = Parse.Object.extend('LQLOutdoor');
+
+  //   const filmQuery = new Parse.Query(Film);
+  //   const bookQuery = new Parse.Query(LQLBook);
+  //   const gameQuery = new Parse.Query(LQLGame);
+  //   const musicQuery = new Parse.Query(LQLMusic);
+  //   const outdoorQuery = new Parse.Query(LQLOutdoor);
+
+  //   filmQuery.startsWith('name', keyword);
+  //   bookQuery.startsWith('name', keyword);
+  //   gameQuery.startsWith('name', keyword);
+  //   musicQuery.startsWith('name', keyword);
+  //   outdoorQuery.startsWith('name', keyword);
+
+  //   const filmresults = await filmQuery.find();
+  //   const bookresults = await bookQuery.find();
+  //   const gameresults = await gameQuery.find();
+  //   const musicresults = await musicQuery.find();
+  //   const outdoorresults = await outdoorQuery.find();
+
+  //   this.filmsearchResults = filmresults.map(filmresult => filmresult.toJSON());
+  //   this.booksearchResults = bookresults.map(bookresult => bookresult.toJSON());
+  //   this.gamesearchResults = gameresults.map(gameresult => gameresult.toJSON());
+  //   this.musicsearchResults = musicresults.map(musicresult => musicresult.toJSON());
+  //   this.outdoorsearchResults = outdoorresults.map(outdoorresult => outdoorresult.toJSON());
+
+  
+  // if(!this.searchTerm)
+  // {
+  //   this.filmsearchResults = []
+  //   this.booksearchResults = []
+  //   this.gamesearchResults = []
+  //   this.musicsearchResults = []
+  //   this.outdoorsearchResults =[] 
+  // }
+  //   this.cdr.detectChanges();
+  // }
+
+}
+
+function searchContent(event: Event | undefined, CustomEvent: { new <T>(type: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>; prototype: CustomEvent; }) {
+  throw new Error('Function not implemented.');
 }
 
 
 
+
+
+
+
+
+ 
+

+ 1 - 1
src/modules/feiwu/fiml/fiml.page.html

@@ -10,7 +10,7 @@
  <ion-content>
   <ion-searchbar [(ngModel)]="searchName" (ionInput)="loadFilms()"></ion-searchbar>
   
-  <ion-segment [(ngModel)]="selectedRating" (ionChange)="loadFilms()"></ion-segment>
+  <!-- <ion-segment [(ngModel)]="selectedRating" (ionChange)="loadFilms()"></ion-segment> -->
     
   
   <ion-button (click)="toggleSort()">Sort by Rating</ion-button>

+ 13 - 11
src/modules/feiwu/fiml/fiml.page.ts

@@ -26,7 +26,20 @@ export class FimlPage implements OnInit {
   ) { 
     
   }
+  
+  async loadFilms() {
+    const queryParams = {
+      name: this.searchName,
+      details: this.searchDetails,
+      rating: this.selectedRating,
+      sortByRating:this.sortByRating
+      
+    };
+    this.films=await this.filmService.getFilms(queryParams);
+    //this.score=this.selectedRating;
+  }
 
+  
   async updateFilmRating(film:Parse.Object,score:any){
     if(!score) return
     let rating = await this.checkExists(film)
@@ -63,17 +76,6 @@ export class FimlPage implements OnInit {
     this.loadFilms();
   }
 
-  async loadFilms() {
-    const queryParams = {
-      name: this.searchName,
-      details: this.searchDetails,
-      rating: this.selectedRating,
-      sortByRating:this.sortByRating
-      
-    };
-    this.films=await this.filmService.getFilms(queryParams);
-    //this.score=this.selectedRating;
-  }
 
   toggleSort() {
     if (this.isAscending) {

+ 7 - 1
src/modules/server/firm.serve.ts

@@ -27,7 +27,13 @@ export class FilmService {
    return await query.find();
  }
 
-
+ async searchFilm(queryParams: any):Promise<Parse.Object[]>{
+  const query = new Parse.Query(this.Film);
+  if (queryParams.name) {
+    query.contains('name', queryParams.name);
+  }
+  return await query.find();
+ }
  
   // async getFilms(): Promise<any[]> {
   //   const Film = Parse.Object.extend('Film');