home.component.ts 3.4 KB

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