home.component.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import * as Parse from 'parse';
  3. import { IonicModule } from '@ionic/angular';
  4. import { Router } from '@angular/router';
  5. import { AuthService } from '../../../services/auth.service';
  6. import { Swiper } from 'swiper';
  7. import { AiChatService } from '../../../services/aichart.service';
  8. @Component({
  9. selector: 'app-home',
  10. templateUrl: './home.component.html',
  11. styleUrls: ['./home.component.scss'],
  12. standalone: true,
  13. imports: [IonicModule],
  14. // schemas: [CUSTOM_ELEMENTS_SCHEMA],
  15. })
  16. export class HomeComponent implements OnInit {
  17. @ViewChild('modal') modal!: any;
  18. options: Array<any> = [
  19. {
  20. label: '关注',
  21. value: 'follow',
  22. icon: 'home-outline',
  23. color: 'primary',
  24. },
  25. {
  26. label: '推荐',
  27. value: 'recommend',
  28. icon: 'home-outline',
  29. color: 'primary',
  30. },
  31. {
  32. label: '新人',
  33. value: 'news',
  34. icon: 'videocam-outline',
  35. color: 'danger',
  36. },
  37. {
  38. label: '三星',
  39. value: '三星',
  40. icon: 'videocam-outline',
  41. color: 'danger',
  42. },
  43. {
  44. label: '四星',
  45. value: '四星',
  46. icon: 'videocam-outline',
  47. color: 'danger',
  48. },
  49. {
  50. label: '五星',
  51. value: '五星',
  52. icon: 'people-outline',
  53. },
  54. ];
  55. currentValue: string = 'recommend';
  56. oldCurrentValue: string = 'recommend';
  57. isOpen: boolean = false; //显示选择弹窗
  58. banner: Array<Parse.Object> = [];
  59. roomList: Array<any> = [];
  60. pageSwiper: Swiper | undefined | any;
  61. constructor(
  62. private router: Router,
  63. public authServ: AuthService,
  64. private aiServ: AiChatService
  65. ) {}
  66. ngOnInit() {
  67. this.refresh();
  68. }
  69. async refresh() {
  70. await this.getBanner();
  71. await this.getRoom();
  72. setTimeout(() => {
  73. this.initSwiperTimeEvent();
  74. }, 0);
  75. }
  76. async getBanner() {
  77. let query = new Parse.Query('Banner');
  78. query.equalTo('company', this.authServ.company);
  79. query.descending('index');
  80. query.equalTo('isEnabled', true);
  81. query.notEqualTo('isDeleted', true);
  82. let banner = await query.find();
  83. this.banner = banner;
  84. }
  85. initSwiperTimeEvent() {
  86. // 初始化轮播图
  87. let swiper = new Swiper('.mySwiper', {
  88. loop: true, // 循环模式选项
  89. observer: false, //修改swiper自己或子元素时,自动初始化swiper
  90. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  91. autoplay: {
  92. delay: 1500,
  93. },
  94. pagination: {
  95. el: '.swiper-pagination',
  96. },
  97. });
  98. swiper.on('slideChange', function (event: any) {
  99. // console.log(event);
  100. });
  101. }
  102. async getRoom(type?: string) {
  103. let data: Array<any> = [];
  104. if (!type) type = this.currentValue;
  105. console.log(type);
  106. let uid = Parse.User.current()?.id;
  107. switch (type) {
  108. case 'follow':
  109. data = await this.aiServ.getRooms({ uid: uid, follow: true });
  110. break;
  111. case 'recommend':
  112. data = await this.aiServ.getRooms({ uid: uid, recommend: true });
  113. break;
  114. case 'news':
  115. data = await this.aiServ.getRooms({ uid: uid });
  116. break;
  117. case '三星':
  118. data = await this.aiServ.getRooms({ uid: uid, star: '三星' });
  119. break;
  120. case '四星':
  121. data = await this.aiServ.getRooms({ uid: uid, star: '四星' });
  122. break;
  123. case '五星':
  124. data = await this.aiServ.getRooms({ uid: uid, star: '五星' });
  125. break;
  126. default:
  127. break;
  128. }
  129. this.roomList = data;
  130. console.log(data);
  131. // let query = new Parse.Query('Room');
  132. // query.equalTo('company', this.authServ.company);
  133. // query.equalTo('state', true);
  134. // query.notEqualTo('isDeleted', true);
  135. // let r = await query.find();
  136. // this.roomList = r;
  137. }
  138. segmentChanged(e: any) {
  139. let { value } = e.detail;
  140. this.currentValue = value;
  141. }
  142. onIonChange(event: CustomEvent) {
  143. this.currentValue = event.detail.value;
  144. }
  145. /* 关闭弹窗回调 */
  146. onDidDismiss(event: CustomEvent) {
  147. this.isOpen = false;
  148. console.log(this.currentValue);
  149. }
  150. cancel(type: string, value?: string) {
  151. console.log(type, value);
  152. if (type == 'cancel') {
  153. this.currentValue = this.oldCurrentValue;
  154. } else {
  155. this.oldCurrentValue = this.currentValue;
  156. }
  157. this.isOpen = false;
  158. this.modal.dismiss();
  159. this.getRoom()
  160. }
  161. search() {
  162. this.router.navigate(['live/search']);
  163. }
  164. toUrl(url: string) {
  165. this.router.navigate([url]);
  166. }
  167. }