123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- import { Component, OnInit } from '@angular/core';
- import * as Parse from 'parse';
- import { ActivatedRoute, Router } from '@angular/router';
- import { Swiper } from 'swiper';
- import { AiChatService } from '../../../services/aichart.service';
- import { ConnectTaskService } from '../../../services/connectTask.service';
- import {
- ionicStandaloneModules,
- AlertController,
- LoadingController,
- } from '../../ionic-standalone.modules';
- import { CommonModule, DatePipe } from '@angular/common';
- import { provinceMap } from '../../../services/address';
- import { FormsModule } from '@angular/forms';
- import { BackgroundColorService } from '../../../services/background-color.service';
- import { DeviceService } from '../../../services/device.service';
- @Component({
- selector: 'app-home',
- templateUrl: './home.component.html',
- styleUrls: ['./home.component.scss'],
- standalone: true,
- imports: [...ionicStandaloneModules, CommonModule, FormsModule],
- providers: [DatePipe],
- })
- export class HomeComponent implements OnInit {
- options: Array<any> = [
- {
- label: '关注',
- value: 'follow',
- icon: 'home-outline',
- color: 'primary',
- },
- {
- label: '热门',
- value: 'recommend',
- icon: 'home-outline',
- color: 'primary',
- },
- {
- label: '新人',
- value: 'news',
- icon: 'videocam-outline',
- color: 'danger',
- },
- {
- label: '三星',
- value: '三星',
- icon: 'videocam-outline',
- color: 'danger',
- },
- {
- label: '四星',
- value: '四星',
- icon: 'videocam-outline',
- color: 'danger',
- },
- {
- label: '五星',
- value: '五星',
- icon: 'people-outline',
- },
- {
- label: '海外',
- value: '海外',
- icon: 'people-outline',
- },
- ];
- currentValue: string = 'recommend';
- oldCurrentValue: string = 'recommend';
- isOpen: boolean = false; //显示选择弹窗
- banner: Array<Parse.Object> = [];
- roomList: Array<any> = [];
- pageSwiper: Swiper | undefined | any;
- notices: Array<any> = [];
- viewAnchor: string = localStorage.getItem('viewSex') || '女';
- get sex(): string {
- const map: any = {
- all: '全部',
- 男: '男主播',
- 女: '女主播',
- };
- return map[this.viewAnchor];
- }
- isOpenCity: boolean = false;
- provinceColumns = [];
- cityColumns = [];
- province: string = ''; //省份
- city: string = ''; //市
- old_province: string = ''; //省份
- old_city: string = ''; //市
- isColumn: boolean = false; //单排
- userList: Array<string> | any = [];
- constructor(
- private loadingCtrl: LoadingController,
- private alertController: AlertController,
- // private activateRoute: ActivatedRoute,
- private connectTask: ConnectTaskService,
- private router: Router,
- private aiServ: AiChatService,
- private datePipe: DatePipe,
- private backgroundColorService: BackgroundColorService,
- public deviceSer:DeviceService
- ) {
- // province.unshift({
- // provinceName: '全部',
- // citys: [
- // {
- // cityName: '',
- // cityType: '',
- // },
- // ],
- // });
- this.provinceColumns = provinceMap.map((item) => item.provinceName);
- this.cityColumns = provinceMap[0].citys.map((item) => item.cityName);
- }
- ngOnInit() {
- // this.activateRoute.paramMap.subscribe(async (params) => {
- this.refresh();
- this.backgroundColorService.setBackgroundColor('#fe5559');
- // });
- }
- async refresh() {
- const loading = await this.loadingCtrl.create({
- message: '正在加载',
- });
- loading.present();
- await this.connectTask.init();
- await this.getBanner();
- await this.getNotice();
- await this.getRoom();
- setTimeout(() => {
- this.initSwiperTimeEvent();
- loading.dismiss();
- }, 100);
- }
- async getBanner() {
- let query = new Parse.Query('Banner');
- query.equalTo('company', this.aiServ.company);
- query.descending('index');
- query.equalTo('isEnabled', true);
- query.notEqualTo('isDeleted', true);
- let banner = await query.find();
- this.banner = banner;
- }
- async getNotice() {
- let query = new Parse.Query('Notice');
- query.equalTo('company', this.aiServ.company);
- query.notEqualTo('isDeleted', true);
- query.equalTo('type', 'application');
- query.select('title', 'content');
- query.descending('createdAt');
- this.notices = await query.find();
- }
- initSwiperTimeEvent() {
- // 初始化轮播图
- let swiper = new Swiper('.mySwiper', {
- loop: true, // 循环模式选项
- observer: false, //修改swiper自己或子元素时,自动初始化swiper
- observeParents: true, //修改swiper的父元素时,自动初始化swiper
- autoplay: {
- delay: 3000,
- },
- pagination: {
- el: '.swiper-pagination',
- },
- });
- swiper.on('slideChange', function (event: any) {
- // console.log(event);
- });
- let swiperNot = new Swiper('.swiper-notice', {
- loop: true, // 循环模式选项
- observer: false, //修改swiper自己或子元素时,自动初始化swiper
- observeParents: true, //修改swiper的父元素时,自动初始化swiper
- autoplay: {
- delay: 5000,
- },
- direction: 'vertical',
- });
- }
- async getRoom(type?: string) {
- console.log(type);
- const loading = await this.loadingCtrl.create({
- message: '正在加载',
- });
- loading.present();
- let data: Array<any> = [];
- if (type == this.oldCurrentValue) {
- loading.dismiss();
- return;
- }
- this.oldCurrentValue = this.currentValue;
- if (!type) type = this.currentValue;
- let uid = Parse.User.current()?.id;
- let sex = this.viewAnchor == 'all' ? null : this.viewAnchor;
- if (!this.connectTask.onlineUserList.size) {
- await this.connectTask.getOnlieUserList('user_connect_room');
- }
- this.userList = Array.from(this.connectTask.onlineUserList) || [];
- // console.log(userList);
- switch (type) {
- case 'follow':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- follow: true,
- sex,
- city: this.city,
- });
- break;
- case 'recommend':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- recommend: true,
- sex,
- city: this.city,
- });
- break;
- case 'news':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- sex,
- city: this.city,
- });
- break;
- case '三星':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- star: '三星',
- sex,
- city: this.city,
- });
- break;
- case '四星':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- star: '四星',
- sex,
- city: this.city,
- });
- break;
- case '五星':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- star: '五星',
- sex,
- city: this.city,
- });
- break;
- case '海外':
- data = await this.aiServ.getRooms({
- uid: uid,
- // users: userList,
- star: '海外',
- sex,
- city: this.city,
- });
- break;
- default:
- break;
- }
- this.roomList = data;
- console.log(data);
- loading.dismiss();
- }
- async presentAlert(item: any) {
- const alert = await this.alertController.create({
- header: item?.get('title') || '消息通知',
- subHeader: this.datePipe.transform(item?.createdAt, 'yyyy-MM-dd HH:mm')!,
- message: item?.get('content') || '',
- buttons: item?.get('url')
- ? [
- { text: '关闭' },
- {
- text: '确定',
- handler: () => {
- this.router.navigate([item?.get('url')]);
- },
- },
- ]
- : [{ text: '关闭' }],
- });
- await alert.present();
- }
- segmentChanged(e: any) {
- let { value } = e.detail;
- this.currentValue = value;
- }
- onIonChange(event: CustomEvent) {
- this.currentValue = event.detail.value;
- }
- /* 关闭弹窗回调 */
- onDidDismiss(event: CustomEvent) {
- this.isOpen = false;
- // console.log(this.currentValue);
- }
- cancel(type: string, value?: string) {
- console.log(type, value);
- if (type == 'cancel') {
- this.currentValue = this.oldCurrentValue;
- this.isOpen = false;
- return;
- } else {
- if (this.oldCurrentValue != this.currentValue) {
- this.getRoom();
- }
- this.oldCurrentValue = this.currentValue;
- this.isOpen = false;
- }
- }
- onChangeSex(e: any) {
- // console.log(e.detail.value);
- localStorage.setItem('viewSex', e.detail.value);
- if (e.detail.value == this.viewAnchor) return;
- this.viewAnchor = e.detail.value;
- this.getRoom();
- }
- search() {
- this.router.navigate(['live/search']);
- }
- toUrl(url: string) {
- url && this.router.navigate([url]);
- }
- changeCityCancel(type: string) {
- if (type === 'confirm') {
- if (this.city !== this.old_city) {
- this.getRoom();
- }
- this.old_province = this.province;
- this.old_city = this.city;
- } else {
- this.province = this.old_province;
- this.city = this.old_city;
- }
- this.isOpenCity = false;
- }
- onIonChangeCity(event: CustomEvent, type: string) {
- let val = event.detail.value;
- switch (type) {
- case 'province':
- this.province = event.detail.value;
- this.cityColumns = provinceMap
- .find((item) => item.provinceName === val)
- ?.citys.map((item) => item.cityName)!;
- console.log(this.cityColumns);
- this.city = this.cityColumns[0];
- break;
- case 'city':
- this.city = event.detail.value;
- break;
- }
- console.log(this.province, this.city);
- }
- }
|