home.component.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import { Component, OnInit } from '@angular/core';
  2. import * as Parse from 'parse';
  3. import {
  4. AlertController,
  5. IonicModule,
  6. LoadingController,
  7. } from '@ionic/angular';
  8. import { ActivatedRoute, Router } from '@angular/router';
  9. import { Swiper } from 'swiper';
  10. import { AiChatService } from '../../../services/aichart.service';
  11. import { ConnectTaskService } from '../../../services/connectTask.service';
  12. @Component({
  13. selector: 'app-home',
  14. templateUrl: './home.component.html',
  15. styleUrls: ['./home.component.scss'],
  16. standalone: true,
  17. imports: [IonicModule],
  18. // schemas: [CUSTOM_ELEMENTS_SCHEMA],
  19. })
  20. export class HomeComponent implements OnInit {
  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: '三星',
  43. icon: 'videocam-outline',
  44. color: 'danger',
  45. },
  46. {
  47. label: '四星',
  48. value: '四星',
  49. icon: 'videocam-outline',
  50. color: 'danger',
  51. },
  52. {
  53. label: '五星',
  54. value: '五星',
  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<any> = [];
  63. pageSwiper: Swiper | undefined | any;
  64. notices: Array<any> = [
  65. {
  66. title: '【公告】',
  67. content:
  68. '欢迎来到直播间,请遵守直播规则,禁止一切违法直播行为,否则封号处理。',
  69. time: '2022-06-01',
  70. },
  71. {
  72. title: '【公告】',
  73. content:
  74. '欢迎来到直播间,请遵守直播规则,禁止一切违法直播行为,否则封号处理。',
  75. time: '2022-06-01',
  76. },
  77. {
  78. title: '【公告】',
  79. content:
  80. '欢迎来到直播间,请遵守直播规则,禁止一切违法直播行为,否则封号处理。',
  81. time: '2022-06-01',
  82. },
  83. ];
  84. viewAnchor: string = localStorage.getItem('viewSex') || '女';
  85. get sex(): string {
  86. const map: any = {
  87. all: '全部',
  88. 男: '男主播',
  89. 女: '女主播',
  90. };
  91. return map[this.viewAnchor];
  92. }
  93. constructor(
  94. private loadingCtrl: LoadingController,
  95. private alertController: AlertController,
  96. private activateRoute: ActivatedRoute,
  97. private connectTask: ConnectTaskService,
  98. private router: Router,
  99. private aiServ: AiChatService
  100. ) {}
  101. ngOnInit() {
  102. // this.activateRoute.paramMap.subscribe(async (params) => {
  103. this.refresh();
  104. // });
  105. }
  106. async refresh() {
  107. await this.connectTask.init();
  108. await this.getBanner();
  109. await this.getRoom();
  110. setTimeout(() => {
  111. this.initSwiperTimeEvent();
  112. }, 0);
  113. }
  114. async getBanner() {
  115. let query = new Parse.Query('Banner');
  116. query.equalTo('company', this.aiServ.company);
  117. query.descending('index');
  118. query.equalTo('isEnabled', true);
  119. query.notEqualTo('isDeleted', true);
  120. let banner = await query.find();
  121. this.banner = banner;
  122. }
  123. initSwiperTimeEvent() {
  124. // 初始化轮播图
  125. let swiper = new Swiper('.mySwiper', {
  126. loop: true, // 循环模式选项
  127. observer: false, //修改swiper自己或子元素时,自动初始化swiper
  128. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  129. autoplay: {
  130. delay: 3000,
  131. },
  132. pagination: {
  133. el: '.swiper-pagination',
  134. },
  135. });
  136. swiper.on('slideChange', function (event: any) {
  137. // console.log(event);
  138. });
  139. let swiperNot = new Swiper('.swiper-notice', {
  140. loop: true, // 循环模式选项
  141. observer: false, //修改swiper自己或子元素时,自动初始化swiper
  142. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  143. autoplay: {
  144. delay: 5000,
  145. },
  146. direction: 'vertical',
  147. });
  148. }
  149. async getRoom(type?: string) {
  150. const loading = await this.loadingCtrl.create({
  151. message: '正在加载',
  152. });
  153. loading.present();
  154. let data: Array<any> = [];
  155. if (type == this.currentValue) {
  156. return;
  157. }
  158. if (!type) type = this.currentValue;
  159. let uid = Parse.User.current()?.id;
  160. let sex = this.viewAnchor == 'all' ? null : this.viewAnchor;
  161. if(!this.connectTask.onlineUserList.size){
  162. await this.connectTask.getOnlieUserList('user_connect_room')
  163. }
  164. const userList = Array.from(this.connectTask.onlineUserList)
  165. console.log(userList);
  166. switch (type) {
  167. case 'follow':
  168. data = await this.aiServ.getRooms({
  169. uid: uid,
  170. users: userList,
  171. follow: true,
  172. sex,
  173. });
  174. break;
  175. case 'recommend':
  176. data = await this.aiServ.getRooms({
  177. uid: uid,
  178. users: userList,
  179. recommend: true,
  180. sex,
  181. });
  182. break;
  183. case 'news':
  184. data = await this.aiServ.getRooms({ uid: uid, users: userList, sex });
  185. break;
  186. case '三星':
  187. data = await this.aiServ.getRooms({
  188. uid: uid,
  189. users: userList,
  190. star: '三星',
  191. sex,
  192. });
  193. break;
  194. case '四星':
  195. data = await this.aiServ.getRooms({
  196. uid: uid,
  197. users: userList,
  198. star: '四星',
  199. sex,
  200. });
  201. break;
  202. case '五星':
  203. data = await this.aiServ.getRooms({
  204. uid: uid,
  205. users: userList,
  206. star: '五星',
  207. sex,
  208. });
  209. break;
  210. default:
  211. break;
  212. }
  213. this.roomList = data;
  214. console.log(data);
  215. loading.dismiss();
  216. }
  217. async presentAlert(item: any) {
  218. const alert = await this.alertController.create({
  219. header: item.title || '消息通知',
  220. message:
  221. item.content || 'A message should be a short, complete sentence.',
  222. buttons: ['关闭'],
  223. });
  224. await alert.present();
  225. }
  226. segmentChanged(e: any) {
  227. let { value } = e.detail;
  228. this.currentValue = value;
  229. }
  230. onIonChange(event: CustomEvent) {
  231. this.currentValue = event.detail.value;
  232. }
  233. /* 关闭弹窗回调 */
  234. onDidDismiss(event: CustomEvent) {
  235. this.isOpen = false;
  236. // console.log(this.currentValue);
  237. }
  238. cancel(type: string, value?: string) {
  239. // console.log(type, value);
  240. if (type == 'cancel') {
  241. this.currentValue = this.oldCurrentValue;
  242. this.isOpen = false;
  243. return;
  244. } else {
  245. if (this.oldCurrentValue != this.currentValue) {
  246. this.getRoom();
  247. }
  248. this.oldCurrentValue = this.currentValue;
  249. this.isOpen = false;
  250. }
  251. }
  252. onChangeSex(e: any) {
  253. // console.log(e.detail.value);
  254. localStorage.setItem('viewSex', e.detail.value);
  255. if (e.detail.value == this.viewAnchor) return;
  256. this.viewAnchor = e.detail.value;
  257. this.getRoom();
  258. }
  259. search() {
  260. this.router.navigate(['live/search']);
  261. }
  262. toUrl(url: string) {
  263. this.router.navigate([url]);
  264. }
  265. }