|
@@ -2,55 +2,52 @@ import { DatePipe } from '@angular/common';
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { Router } from '@angular/router';
|
|
|
-import {
|
|
|
- IonicModule,
|
|
|
- LoadingController,
|
|
|
- ToastController,
|
|
|
-} from '@ionic/angular';
|
|
|
+import { LoadingController, ToastController } from '@ionic/angular';
|
|
|
import * as Parse from 'parse';
|
|
|
import { NavComponent } from '../../../app/components/nav/nav.component';
|
|
|
+import { ionicStandaloneModules } from '../../ionic-standalone.modules';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-search',
|
|
|
templateUrl: './search.component.html',
|
|
|
styleUrls: ['./search.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonicModule, FormsModule, DatePipe,NavComponent],
|
|
|
+ imports: [FormsModule, DatePipe, NavComponent, ...ionicStandaloneModules],
|
|
|
providers: [DatePipe],
|
|
|
})
|
|
|
export class SearchComponent implements OnInit {
|
|
|
- roomList:any = []
|
|
|
- company:string = Parse.User.current()?.get('company')
|
|
|
- value:String|undefined
|
|
|
- Search:any = []
|
|
|
- hots:Array<Parse.Object> = []
|
|
|
+ roomList: any = [];
|
|
|
+ company: string = Parse.User.current()?.get('company');
|
|
|
+ value: String | undefined;
|
|
|
+ Search: any = [];
|
|
|
+ hots: Array<Parse.Object> = [];
|
|
|
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
- public toastController: ToastController,
|
|
|
- ) { }
|
|
|
+ public toastController: ToastController
|
|
|
+ ) {}
|
|
|
|
|
|
- async presentToast(message:string) {
|
|
|
+ async presentToast(message: string) {
|
|
|
const toast = await this.toastController.create({
|
|
|
message: message,
|
|
|
- duration: 2000
|
|
|
+ duration: 2000,
|
|
|
});
|
|
|
toast.present();
|
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
|
- this.getLocalStorage()
|
|
|
- this.getRoom()
|
|
|
+ this.getLocalStorage();
|
|
|
+ this.getRoom();
|
|
|
}
|
|
|
|
|
|
// 热门搜索
|
|
|
async getRoom() {
|
|
|
- let query = new Parse.Query("Room")
|
|
|
- query.equalTo('company',this.company)
|
|
|
- query.limit(5)
|
|
|
+ let query = new Parse.Query('Room');
|
|
|
+ query.equalTo('company', this.company);
|
|
|
+ query.limit(5);
|
|
|
// query.descending("score")
|
|
|
- let res = await query.find()
|
|
|
- this.hots = res
|
|
|
+ let res = await query.find();
|
|
|
+ this.hots = res;
|
|
|
// console.log(res);
|
|
|
// if (res && res.length > 0) {
|
|
|
// res.forEach(item => {
|
|
@@ -60,50 +57,48 @@ export class SearchComponent implements OnInit {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
- getLocalStorage(){
|
|
|
- let storage = localStorage.getItem("Search");
|
|
|
- this.Search = storage && JSON.parse(storage)
|
|
|
+ getLocalStorage() {
|
|
|
+ let storage = localStorage.getItem('Search');
|
|
|
+ this.Search = storage && JSON.parse(storage);
|
|
|
console.log(this.Search);
|
|
|
}
|
|
|
|
|
|
- SearchHot(value: String){
|
|
|
- this.value = value
|
|
|
- this.toSearch()
|
|
|
+ SearchHot(value: String) {
|
|
|
+ this.value = value;
|
|
|
+ this.toSearch();
|
|
|
}
|
|
|
//搜索
|
|
|
- toSearch(){
|
|
|
- this.roomList = []
|
|
|
- if(!this.value || this.value?.trim() === ''){
|
|
|
- this.presentToast('请输入搜索内容')
|
|
|
- return
|
|
|
+ toSearch() {
|
|
|
+ this.roomList = [];
|
|
|
+ if (!this.value || this.value?.trim() === '') {
|
|
|
+ this.presentToast('请输入搜索内容');
|
|
|
+ return;
|
|
|
}
|
|
|
- this.getSearch()
|
|
|
- let storage = localStorage.getItem("Search");
|
|
|
- if(!storage){
|
|
|
- let searchs = [
|
|
|
- this.value,
|
|
|
- ]
|
|
|
- localStorage.setItem("Search",JSON.stringify(searchs));
|
|
|
- return
|
|
|
+ this.getSearch();
|
|
|
+ let storage = localStorage.getItem('Search');
|
|
|
+ if (!storage) {
|
|
|
+ let searchs = [this.value];
|
|
|
+ localStorage.setItem('Search', JSON.stringify(searchs));
|
|
|
+ return;
|
|
|
}
|
|
|
console.log(storage);
|
|
|
- let list = JSON.parse(storage)
|
|
|
- list.splice(0,0,this.value)
|
|
|
- let arr:any = new Set(list)
|
|
|
- list = Array.from(arr)
|
|
|
- if(list.length > 10){
|
|
|
- list.splice(-1,1)
|
|
|
+ let list = JSON.parse(storage);
|
|
|
+ list.splice(0, 0, this.value);
|
|
|
+ let arr: any = new Set(list);
|
|
|
+ list = Array.from(arr);
|
|
|
+ if (list.length > 10) {
|
|
|
+ list.splice(-1, 1);
|
|
|
}
|
|
|
- localStorage.setItem("Search",JSON.stringify(list));
|
|
|
- this.Search = list
|
|
|
+ localStorage.setItem('Search', JSON.stringify(list));
|
|
|
+ this.Search = list;
|
|
|
}
|
|
|
- async getSearch(){
|
|
|
- let query = new Parse.Query("Room")
|
|
|
- query.equalTo('company',this.company)
|
|
|
- query.equalTo('title',this.value)
|
|
|
- query.notEqualTo('isDeleted',true)
|
|
|
- let r = await query.find()
|
|
|
- this.roomList = r
|
|
|
- if(this.roomList.length == 0)this.presentToast('暂无搜索结果')
|
|
|
+ async getSearch() {
|
|
|
+ let query = new Parse.Query('Room');
|
|
|
+ query.equalTo('company', this.company);
|
|
|
+ query.equalTo('title', this.value);
|
|
|
+ query.notEqualTo('isDeleted', true);
|
|
|
+ let r = await query.find();
|
|
|
+ this.roomList = r;
|
|
|
+ if (this.roomList.length == 0) this.presentToast('暂无搜索结果');
|
|
|
}
|
|
|
}
|