12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { Component } from '@angular/core';
- import { Router } from '@angular/router';
- import { ToastController } from '@ionic/angular';
- @Component({
- selector: 'app-tab3',
- templateUrl: 'tab3.page.html',
- styleUrls: ['tab3.page.scss']
- })
- export class Tab3Page {
- constructor(private toastController: ToastController,private router: Router) {}
- activeTab:string = 'explore';
- likedPosts: number[] = [];
- favoritePosts: number[] = [];
- followedUsers: number[] = [];
- changeTab(event:any){
- this.activeTab = event.detail.value
-
- }
- openSettingsPage() {
- // 打开设置页面
- this.router.navigate(['/settings']);
- }
- // navigateToPage(page: string) {
- // this.router.navigate([`/tabs/${page}`]);
- // }
- sendComment() {
- // 模拟发送评论的操作
- this.presentToast('评论已发送');
-
- }
- async presentToast(message: string) {
- const toast = await this.toastController.create({
- message: message,
- duration: 2000
- });
- toast.present();
- }
- likePost(postId: number) {
- if (this.isPostLiked(postId)) {
- this.likedPosts = this.likedPosts.filter(id => id !== postId);
- } else {
- this.likedPosts.push(postId);
- }
- }
- isPostLiked(postId: number): boolean {
- return this.likedPosts.includes(postId);
- }
- toggleFavorite(postId: number) {
- if (this.isPostFavorite(postId)) {
- this.favoritePosts = this.favoritePosts.filter(id => id !== postId);
- } else {
- this.favoritePosts.push(postId);
- }
- }
- isPostFavorite(postId: number): boolean {
- return this.favoritePosts.includes(postId);
- }
- toggleFollow(userId: number) {
- if (this.isUserFollowed(userId)) {
- this.followedUsers = this.followedUsers.filter(id => id !== userId);
- } else {
- this.followedUsers.push(userId);
- }
- }
- isUserFollowed(userId: number): boolean {
- return this.followedUsers.includes(userId);
- }
- }
|