comment.component.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3. import {
  4. ionicStandaloneModules,
  5. LoadingController,
  6. } from '../../ionic-standalone.modules';
  7. import * as Parse from 'parse';
  8. import { AiChatService } from '../../../services/aichart.service';
  9. import { InfiniteScrollCustomEvent } from '@ionic/core';
  10. import { NavComponent } from '../../../app/components/nav/nav.component';
  11. @Component({
  12. selector: 'app-comment',
  13. templateUrl: './comment.component.html',
  14. styleUrls: ['./comment.component.scss'],
  15. standalone: true,
  16. imports: [...ionicStandaloneModules, NavComponent],
  17. })
  18. export class CommentComponent implements OnInit {
  19. rid: string = '';
  20. commentList: Array<Parse.Object> = [];
  21. constructor(
  22. private activateRoute: ActivatedRoute,
  23. private loadingCtrl: LoadingController,
  24. public aiChatServ: AiChatService
  25. ) {}
  26. ngOnInit() {
  27. this.activateRoute.paramMap.subscribe(async (params) => {
  28. let rid = params.get('rid');
  29. this.rid = rid;
  30. this.getCommentLeng();
  31. });
  32. }
  33. async getCommentLeng() {
  34. const loading = await this.loadingCtrl.create({
  35. message: '加载中',
  36. });
  37. loading.present();
  38. let queryPost = new Parse.Query('DramaPostLog');
  39. queryPost.equalTo('room', this.rid);
  40. queryPost.notEqualTo('isDeleted', true);
  41. queryPost.include('user');
  42. queryPost.descending('createdAt');
  43. queryPost.equalTo('isVerify', true);
  44. queryPost.limit(20);
  45. queryPost.skip(this.commentList.length);
  46. let r = await queryPost.find();
  47. this.commentList.push(...r);
  48. loading.dismiss();
  49. return r;
  50. }
  51. async onIonInfinite(ev: any) {
  52. let result = await this.getCommentLeng();
  53. if (result.length == 0) {
  54. (ev as InfiniteScrollCustomEvent).target.disabled = true;
  55. }
  56. setTimeout(() => {
  57. (ev as InfiniteScrollCustomEvent).target.complete();
  58. }, 500);
  59. }
  60. }