home.component.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. import { Component, OnInit } from '@angular/core';
  2. import * as Parse from 'parse';
  3. import { ActivatedRoute, Router } from '@angular/router';
  4. import { Swiper } from 'swiper';
  5. import { AiChatService } from '../../../services/aichart.service';
  6. import { ConnectTaskService } from '../../../services/connectTask.service';
  7. import {
  8. ionicStandaloneModules,
  9. AlertController,
  10. LoadingController,
  11. } from '../../ionic-standalone.modules';
  12. import { CommonModule, DatePipe } from '@angular/common';
  13. import { provinceMap } from '../../../services/address';
  14. import { FormsModule } from '@angular/forms';
  15. import { BackgroundColorService } from '../../../services/background-color.service';
  16. import { DeviceService } from '../../../services/device.service';
  17. @Component({
  18. selector: 'app-home',
  19. templateUrl: './home.component.html',
  20. styleUrls: ['./home.component.scss'],
  21. standalone: true,
  22. imports: [...ionicStandaloneModules, CommonModule, FormsModule],
  23. providers: [DatePipe],
  24. })
  25. export class HomeComponent implements OnInit {
  26. options: Array<any> = [
  27. {
  28. label: '关注',
  29. value: 'follow',
  30. icon: 'home-outline',
  31. color: 'primary',
  32. },
  33. {
  34. label: '热门',
  35. value: 'recommend',
  36. icon: 'home-outline',
  37. color: 'primary',
  38. },
  39. {
  40. label: '新人',
  41. value: 'news',
  42. icon: 'videocam-outline',
  43. color: 'danger',
  44. },
  45. {
  46. label: '三星',
  47. value: '三星',
  48. icon: 'videocam-outline',
  49. color: 'danger',
  50. },
  51. {
  52. label: '四星',
  53. value: '四星',
  54. icon: 'videocam-outline',
  55. color: 'danger',
  56. },
  57. {
  58. label: '五星',
  59. value: '五星',
  60. icon: 'people-outline',
  61. },
  62. {
  63. label: '海外',
  64. value: '海外',
  65. icon: 'people-outline',
  66. },
  67. ];
  68. currentValue: string = 'recommend';
  69. oldCurrentValue: string = 'recommend';
  70. isOpen: boolean = false; //显示选择弹窗
  71. banner: Array<Parse.Object> = [];
  72. roomList: Array<any> = [];
  73. pageSwiper: Swiper | undefined | any;
  74. notices: Array<any> = [];
  75. viewAnchor: string = localStorage.getItem('viewSex') || '女';
  76. get sex(): string {
  77. const map: any = {
  78. all: '全部',
  79. 男: '男主播',
  80. 女: '女主播',
  81. };
  82. return map[this.viewAnchor];
  83. }
  84. isOpenCity: boolean = false;
  85. provinceColumns = [];
  86. cityColumns = [];
  87. province: string = ''; //省份
  88. city: string = ''; //市
  89. old_province: string = ''; //省份
  90. old_city: string = ''; //市
  91. isColumn: boolean = false; //单排
  92. userList: Array<string> | any = [];
  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. private datePipe: DatePipe,
  101. private backgroundColorService: BackgroundColorService,
  102. public deviceSer:DeviceService
  103. ) {
  104. // province.unshift({
  105. // provinceName: '全部',
  106. // citys: [
  107. // {
  108. // cityName: '',
  109. // cityType: '',
  110. // },
  111. // ],
  112. // });
  113. this.provinceColumns = provinceMap.map((item) => item.provinceName);
  114. this.cityColumns = provinceMap[0].citys.map((item) => item.cityName);
  115. }
  116. ngOnInit() {
  117. // this.activateRoute.paramMap.subscribe(async (params) => {
  118. this.refresh();
  119. this.backgroundColorService.setBackgroundColor('#fe5559');
  120. // });
  121. }
  122. async refresh() {
  123. const loading = await this.loadingCtrl.create({
  124. message: '正在加载',
  125. });
  126. loading.present();
  127. await this.connectTask.init();
  128. await this.getBanner();
  129. await this.getNotice();
  130. await this.getRoom();
  131. setTimeout(() => {
  132. this.initSwiperTimeEvent();
  133. loading.dismiss();
  134. }, 100);
  135. }
  136. async getBanner() {
  137. let query = new Parse.Query('Banner');
  138. query.equalTo('company', this.aiServ.company);
  139. query.descending('index');
  140. query.equalTo('isEnabled', true);
  141. query.notEqualTo('isDeleted', true);
  142. let banner = await query.find();
  143. this.banner = banner;
  144. }
  145. async getNotice() {
  146. let query = new Parse.Query('Notice');
  147. query.equalTo('company', this.aiServ.company);
  148. query.notEqualTo('isDeleted', true);
  149. query.equalTo('type', 'application');
  150. query.select('title', 'content');
  151. query.descending('createdAt');
  152. this.notices = await query.find();
  153. }
  154. initSwiperTimeEvent() {
  155. // 初始化轮播图
  156. let swiper = new Swiper('.mySwiper', {
  157. loop: true, // 循环模式选项
  158. observer: false, //修改swiper自己或子元素时,自动初始化swiper
  159. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  160. autoplay: {
  161. delay: 3000,
  162. },
  163. pagination: {
  164. el: '.swiper-pagination',
  165. },
  166. });
  167. swiper.on('slideChange', function (event: any) {
  168. // console.log(event);
  169. });
  170. let swiperNot = new Swiper('.swiper-notice', {
  171. loop: true, // 循环模式选项
  172. observer: false, //修改swiper自己或子元素时,自动初始化swiper
  173. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  174. autoplay: {
  175. delay: 5000,
  176. },
  177. direction: 'vertical',
  178. });
  179. }
  180. async getRoom(type?: string) {
  181. console.log(type);
  182. const loading = await this.loadingCtrl.create({
  183. message: '正在加载',
  184. });
  185. loading.present();
  186. let data: Array<any> = [];
  187. if (type == this.oldCurrentValue) {
  188. loading.dismiss();
  189. return;
  190. }
  191. this.oldCurrentValue = this.currentValue;
  192. if (!type) type = this.currentValue;
  193. let uid = Parse.User.current()?.id;
  194. let sex = this.viewAnchor == 'all' ? null : this.viewAnchor;
  195. if (!this.connectTask.onlineUserList.size) {
  196. await this.connectTask.getOnlieUserList('user_connect_room');
  197. }
  198. this.userList = Array.from(this.connectTask.onlineUserList) || [];
  199. // console.log(userList);
  200. switch (type) {
  201. case 'follow':
  202. data = await this.aiServ.getRooms({
  203. uid: uid,
  204. // users: userList,
  205. follow: true,
  206. sex,
  207. city: this.city,
  208. });
  209. break;
  210. case 'recommend':
  211. data = await this.aiServ.getRooms({
  212. uid: uid,
  213. // users: userList,
  214. recommend: true,
  215. sex,
  216. city: this.city,
  217. });
  218. break;
  219. case 'news':
  220. data = await this.aiServ.getRooms({
  221. uid: uid,
  222. // users: userList,
  223. sex,
  224. city: this.city,
  225. });
  226. break;
  227. case '三星':
  228. data = await this.aiServ.getRooms({
  229. uid: uid,
  230. // users: userList,
  231. star: '三星',
  232. sex,
  233. city: this.city,
  234. });
  235. break;
  236. case '四星':
  237. data = await this.aiServ.getRooms({
  238. uid: uid,
  239. // users: userList,
  240. star: '四星',
  241. sex,
  242. city: this.city,
  243. });
  244. break;
  245. case '五星':
  246. data = await this.aiServ.getRooms({
  247. uid: uid,
  248. // users: userList,
  249. star: '五星',
  250. sex,
  251. city: this.city,
  252. });
  253. break;
  254. case '海外':
  255. data = await this.aiServ.getRooms({
  256. uid: uid,
  257. // users: userList,
  258. star: '海外',
  259. sex,
  260. city: this.city,
  261. });
  262. break;
  263. default:
  264. break;
  265. }
  266. this.roomList = data;
  267. console.log(data);
  268. loading.dismiss();
  269. }
  270. async presentAlert(item: any) {
  271. const alert = await this.alertController.create({
  272. header: item?.get('title') || '消息通知',
  273. subHeader: this.datePipe.transform(item?.createdAt, 'yyyy-MM-dd HH:mm')!,
  274. message: item?.get('content') || '',
  275. buttons: item?.get('url')
  276. ? [
  277. { text: '关闭' },
  278. {
  279. text: '确定',
  280. handler: () => {
  281. this.router.navigate([item?.get('url')]);
  282. },
  283. },
  284. ]
  285. : [{ text: '关闭' }],
  286. });
  287. await alert.present();
  288. }
  289. segmentChanged(e: any) {
  290. let { value } = e.detail;
  291. this.currentValue = value;
  292. }
  293. onIonChange(event: CustomEvent) {
  294. this.currentValue = event.detail.value;
  295. }
  296. /* 关闭弹窗回调 */
  297. onDidDismiss(event: CustomEvent) {
  298. this.isOpen = false;
  299. // console.log(this.currentValue);
  300. }
  301. cancel(type: string, value?: string) {
  302. console.log(type, value);
  303. if (type == 'cancel') {
  304. this.currentValue = this.oldCurrentValue;
  305. this.isOpen = false;
  306. return;
  307. } else {
  308. if (this.oldCurrentValue != this.currentValue) {
  309. this.getRoom();
  310. }
  311. this.oldCurrentValue = this.currentValue;
  312. this.isOpen = false;
  313. }
  314. }
  315. onChangeSex(e: any) {
  316. // console.log(e.detail.value);
  317. localStorage.setItem('viewSex', e.detail.value);
  318. if (e.detail.value == this.viewAnchor) return;
  319. this.viewAnchor = e.detail.value;
  320. this.getRoom();
  321. }
  322. search() {
  323. this.router.navigate(['live/search']);
  324. }
  325. toUrl(url: string) {
  326. url && this.router.navigate([url]);
  327. }
  328. changeCityCancel(type: string) {
  329. if (type === 'confirm') {
  330. if (this.city !== this.old_city) {
  331. this.getRoom();
  332. }
  333. this.old_province = this.province;
  334. this.old_city = this.city;
  335. } else {
  336. this.province = this.old_province;
  337. this.city = this.old_city;
  338. }
  339. this.isOpenCity = false;
  340. }
  341. onIonChangeCity(event: CustomEvent, type: string) {
  342. let val = event.detail.value;
  343. switch (type) {
  344. case 'province':
  345. this.province = event.detail.value;
  346. this.cityColumns = provinceMap
  347. .find((item) => item.provinceName === val)
  348. ?.citys.map((item) => item.cityName)!;
  349. console.log(this.cityColumns);
  350. this.city = this.cityColumns[0];
  351. break;
  352. case 'city':
  353. this.city = event.detail.value;
  354. break;
  355. }
  356. console.log(this.province, this.city);
  357. }
  358. }