tab3.page.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Component } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { ToastController } from '@ionic/angular';
  4. @Component({
  5. selector: 'app-tab3',
  6. templateUrl: 'tab3.page.html',
  7. styleUrls: ['tab3.page.scss']
  8. })
  9. export class Tab3Page {
  10. constructor(private toastController: ToastController,private router: Router) {}
  11. activeTab:string = 'explore';
  12. likedPosts: number[] = [];
  13. favoritePosts: number[] = [];
  14. followedUsers: number[] = [];
  15. changeTab(event:any){
  16. this.activeTab = event.detail.value
  17. }
  18. openSettingsPage() {
  19. // 打开设置页面
  20. this.router.navigate(['/settings']);
  21. }
  22. // navigateToPage(page: string) {
  23. // this.router.navigate([`/tabs/${page}`]);
  24. // }
  25. sendComment() {
  26. // 模拟发送评论的操作
  27. this.presentToast('评论已发送');
  28. }
  29. async presentToast(message: string) {
  30. const toast = await this.toastController.create({
  31. message: message,
  32. duration: 2000
  33. });
  34. toast.present();
  35. }
  36. likePost(postId: number) {
  37. if (this.isPostLiked(postId)) {
  38. this.likedPosts = this.likedPosts.filter(id => id !== postId);
  39. } else {
  40. this.likedPosts.push(postId);
  41. }
  42. }
  43. isPostLiked(postId: number): boolean {
  44. return this.likedPosts.includes(postId);
  45. }
  46. toggleFavorite(postId: number) {
  47. if (this.isPostFavorite(postId)) {
  48. this.favoritePosts = this.favoritePosts.filter(id => id !== postId);
  49. } else {
  50. this.favoritePosts.push(postId);
  51. }
  52. }
  53. isPostFavorite(postId: number): boolean {
  54. return this.favoritePosts.includes(postId);
  55. }
  56. toggleFollow(userId: number) {
  57. if (this.isUserFollowed(userId)) {
  58. this.followedUsers = this.followedUsers.filter(id => id !== userId);
  59. } else {
  60. this.followedUsers.push(userId);
  61. }
  62. }
  63. isUserFollowed(userId: number): boolean {
  64. return this.followedUsers.includes(userId);
  65. }
  66. }