home.component.ts 7.1 KB

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