|
@@ -8,12 +8,14 @@ import {
|
|
|
ionicStandaloneModules,
|
|
|
AlertController,
|
|
|
LoadingController,
|
|
|
+ ToastController,
|
|
|
} 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';
|
|
|
+import { InfiniteScrollCustomEvent } from '@ionic/core';
|
|
|
@Component({
|
|
|
selector: 'app-home',
|
|
|
templateUrl: './home.component.html',
|
|
@@ -90,6 +92,8 @@ export class HomeComponent implements OnInit {
|
|
|
old_city: string = ''; //市
|
|
|
isColumn: boolean = false; //单排
|
|
|
userList: Array<string> | any = [];
|
|
|
+ disbable: boolean = true;
|
|
|
+
|
|
|
constructor(
|
|
|
private loadingCtrl: LoadingController,
|
|
|
private alertController: AlertController,
|
|
@@ -99,7 +103,8 @@ export class HomeComponent implements OnInit {
|
|
|
private aiServ: AiChatService,
|
|
|
private datePipe: DatePipe,
|
|
|
private backgroundColorService: BackgroundColorService,
|
|
|
- public deviceSer:DeviceService
|
|
|
+ private toastController: ToastController,
|
|
|
+ public deviceSer: DeviceService
|
|
|
) {
|
|
|
// province.unshift({
|
|
|
// provinceName: '全部',
|
|
@@ -181,19 +186,24 @@ export class HomeComponent implements OnInit {
|
|
|
direction: 'vertical',
|
|
|
});
|
|
|
}
|
|
|
- async getRoom(type?: string) {
|
|
|
- console.log(type);
|
|
|
+ onChangeTab(type: string) {
|
|
|
+ // console.log(type);
|
|
|
+ if (type == this.oldCurrentValue) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.currentValue = type;
|
|
|
+ // console.log(this.currentValue);
|
|
|
+ this.roomList = [];
|
|
|
+ this.disbable = true;
|
|
|
+ this.getRoom();
|
|
|
+ }
|
|
|
+ async getRoom() {
|
|
|
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) {
|
|
@@ -201,10 +211,11 @@ export class HomeComponent implements OnInit {
|
|
|
}
|
|
|
this.userList = Array.from(this.connectTask.onlineUserList) || [];
|
|
|
// console.log(userList);
|
|
|
- switch (type) {
|
|
|
+ switch (this.currentValue) {
|
|
|
case 'follow':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
follow: true,
|
|
|
sex,
|
|
@@ -214,6 +225,7 @@ export class HomeComponent implements OnInit {
|
|
|
case 'recommend':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
recommend: true,
|
|
|
sex,
|
|
@@ -223,6 +235,7 @@ export class HomeComponent implements OnInit {
|
|
|
case 'news':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
sex,
|
|
|
city: this.city,
|
|
@@ -231,6 +244,7 @@ export class HomeComponent implements OnInit {
|
|
|
case '三星':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
star: '三星',
|
|
|
sex,
|
|
@@ -240,6 +254,7 @@ export class HomeComponent implements OnInit {
|
|
|
case '四星':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
star: '四星',
|
|
|
sex,
|
|
@@ -249,6 +264,7 @@ export class HomeComponent implements OnInit {
|
|
|
case '五星':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
star: '五星',
|
|
|
sex,
|
|
@@ -258,6 +274,7 @@ export class HomeComponent implements OnInit {
|
|
|
case '海外':
|
|
|
data = await this.aiServ.getRooms({
|
|
|
uid: uid,
|
|
|
+ skip: this.roomList.length,
|
|
|
// users: userList,
|
|
|
star: '海外',
|
|
|
sex,
|
|
@@ -268,9 +285,19 @@ export class HomeComponent implements OnInit {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- this.roomList = data;
|
|
|
- console.log(data);
|
|
|
+ if (data.length == 0) {
|
|
|
+ loading.dismiss();
|
|
|
+ const toast = await this.toastController.create({
|
|
|
+ message: '已加载全部内容',
|
|
|
+ duration: 1500,
|
|
|
+ color: 'warning',
|
|
|
+ });
|
|
|
+ toast.present();
|
|
|
+ return data.length;
|
|
|
+ }
|
|
|
+ this.roomList.push(...data);
|
|
|
loading.dismiss();
|
|
|
+ return data.length;
|
|
|
}
|
|
|
async presentAlert(item: any) {
|
|
|
const alert = await this.alertController.create({
|
|
@@ -311,6 +338,8 @@ export class HomeComponent implements OnInit {
|
|
|
return;
|
|
|
} else {
|
|
|
if (this.oldCurrentValue != this.currentValue) {
|
|
|
+ this.roomList = [];
|
|
|
+ this.disbable = true;
|
|
|
this.getRoom();
|
|
|
}
|
|
|
this.oldCurrentValue = this.currentValue;
|
|
@@ -322,6 +351,8 @@ export class HomeComponent implements OnInit {
|
|
|
localStorage.setItem('viewSex', e.detail.value);
|
|
|
if (e.detail.value == this.viewAnchor) return;
|
|
|
this.viewAnchor = e.detail.value;
|
|
|
+ this.roomList = [];
|
|
|
+ this.disbable = true;
|
|
|
this.getRoom();
|
|
|
}
|
|
|
search() {
|
|
@@ -334,6 +365,8 @@ export class HomeComponent implements OnInit {
|
|
|
changeCityCancel(type: string) {
|
|
|
if (type === 'confirm') {
|
|
|
if (this.city !== this.old_city) {
|
|
|
+ this.roomList = [];
|
|
|
+ this.disbable = true;
|
|
|
this.getRoom();
|
|
|
}
|
|
|
this.old_province = this.province;
|
|
@@ -361,4 +394,14 @@ export class HomeComponent implements OnInit {
|
|
|
}
|
|
|
console.log(this.province, this.city);
|
|
|
}
|
|
|
+
|
|
|
+ async onIonInfinite(ev: any) {
|
|
|
+ let result = await this.getRoom();
|
|
|
+ if (result == 0) {
|
|
|
+ this.disbable = false;
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ (ev as InfiniteScrollCustomEvent).target.complete();
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
}
|