123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
- import { Router } from '@angular/router';
- import { ToastController } from '@ionic/angular';
- import * as Parse from "parse"
- import Swiper from 'swiper';
- @Component({
- selector: 'app-tab3',
- templateUrl: 'tab3.page.html',
- styleUrls: ['tab3.page.scss']
- })
- export class Tab3Page implements OnInit {
- @ViewChild("slide1Comp") slide1Comp:ElementRef |undefined
- ngOnInit() {
- this.getReply()
- // 延迟500毫秒加载
- setTimeout(() => {
- this.initSwiper();
- }, 500);
- }
- slide1:Swiper|undefined
- initSwiper(){
- console.log(this.slide1Comp)
- this.slide1 = new Swiper(this.slide1Comp?.nativeElement, {
- loop:true,
- autoplay:{
- delay:500,
- },
- mousewheel: {
- forceToAxis: true,
- },
- pagination:{
- el:".swiper-pagination",
- clickable:true
- }
- });
- }
- constructor(private toastController: ToastController,private router: Router) {}
- activeTab:string = 'explore';
- likedPosts: number[] = [];
- favoritePosts: number[] = [];
- followedUsers: number[] = [];
- changeTab(event:any){
- this.activeTab = event.detail.value
-
- }
- /**
- * 查询评论列表
- */
- replyList:any [] = []
- async getReply(){
- let query = new Parse.Query("Discuss")
- query.include("user")
- this.replyList = await query.find()
- console.log(this.replyList);
- }
- /**
- * 保存评论
- */
- currentUser:any
- comment = ''
- async saveComment(){
- this.currentUser = Parse.User.current();
- let com = Parse.Object.extend("Discuss")
- com = new com()
- com.set('user',{__type:'Pointer',className:'_User',objectId:this.currentUser?.id})
- com.set('reply',this.comment)
- try {
- await com.save();
- console.log('保存成功');
- this.getReply()
- this.comment = ''
- } catch (error) {
- console.error('保存失败',error);
- }
- }
- 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);
- }
- goToAIChatPage() {
- this.router.navigate(['/aichat']); // 导航到AI对话页面
- }
-
- }
|