notice.component.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { Component, OnInit } from '@angular/core';
  2. import { IonicModule } from '@ionic/angular';
  3. import * as Parse from 'parse';
  4. import { InfiniteScrollCustomEvent } from '@ionic/angular';
  5. import { Router } from '@angular/router';
  6. import { AiChatService } from '../../../services/aichart.service';
  7. import { SharedModule } from '../../shared.module';
  8. // import { MessageService } from '../../../services/message.service';
  9. @Component({
  10. selector: 'app-notice',
  11. templateUrl: './notice.component.html',
  12. styleUrls: ['./notice.component.scss'],
  13. standalone: true,
  14. imports: [IonicModule, SharedModule],
  15. })
  16. export class NoticeComponent implements OnInit {
  17. active: string = 'notice';
  18. noticeList: Array<any> = [
  19. {
  20. avatar: '/img/notice.png',
  21. name: '系统消息',
  22. content: '',
  23. createdAt: new Date(),
  24. },
  25. ];
  26. alertButtons = [
  27. {
  28. text: '取消',
  29. role: 'cancel',
  30. handler: () => {
  31. console.log('Alert canceled');
  32. },
  33. },
  34. {
  35. text: '确认',
  36. role: 'confirm',
  37. handler: () => {
  38. console.log('Alert confirmed');
  39. },
  40. },
  41. ];
  42. friends: Array<any> = [];
  43. times: number = 0;
  44. timer: any;
  45. showModal: boolean = false; //是否长按弹窗
  46. currentObject: any; //当前选择对象
  47. constructor(
  48. private router: Router,
  49. private aiSer: AiChatService,
  50. // public msgServe: MessageService
  51. ) {}
  52. ngOnInit() {
  53. this.refresh();
  54. }
  55. async refresh() {
  56. let uid: any = Parse.User.current()?.id;
  57. let resultFriends = await this.aiSer.getFriends(uid);
  58. this.friends = resultFriends['data'];
  59. console.log(this.friends);
  60. let resChat = await this.aiSer.getLinkUsers(uid);
  61. resChat?.data && this.noticeList.push(...resChat.data);
  62. }
  63. segmentChanged(e: any) {
  64. let { value } = e.detail;
  65. this.active = value;
  66. }
  67. /* 手指按下 */
  68. startPress() {
  69. this.showModal = false;
  70. if (this.times >= 500) {
  71. console.log(this.times);
  72. this.times = 0;
  73. this.showModal = true;
  74. return;
  75. }
  76. this.timer = setTimeout(() => {
  77. this.times += 500;
  78. this.startPress();
  79. }, 500);
  80. }
  81. /* 触摸屏幕并移动,取消长按事件 */
  82. onMousemove(e: any) {
  83. clearTimeout(this.timer);
  84. // this.showModal = false;
  85. this.times = 0;
  86. }
  87. /* 手指抬起 */
  88. stopPress() {
  89. clearTimeout(this.timer);
  90. this.times = 0;
  91. }
  92. onIonInfinite(ev: any) {
  93. console.log(ev);
  94. setTimeout(() => {
  95. (ev as InfiniteScrollCustomEvent).target.complete();
  96. }, 500);
  97. }
  98. toUrl(url: string) {
  99. if (this.showModal) return;
  100. this.router.navigate([url]);
  101. }
  102. }