|
@@ -1,170 +1,173 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
-import { IonAvatar, IonButton, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
-import { CloudQuery } from 'src/lib/ncloud';
|
|
|
-import { CloudUser } from 'src/lib/ncloud';
|
|
|
-import { CloudObject } from 'src/lib/ncloud';
|
|
|
-import { CommonModule } from '@angular/common';
|
|
|
-import { FormsModule } from '@angular/forms';
|
|
|
-@Component({
|
|
|
- selector: 'app-tab3',
|
|
|
- templateUrl: 'tab3.page.html',
|
|
|
- styleUrls: ['tab3.page.scss'],
|
|
|
- standalone: true,
|
|
|
- imports:[IonHeader,IonToolbar,IonTitle,IonContent,IonCard,IonCardSubtitle
|
|
|
- ,IonCardHeader,IonCardTitle,IonCardContent,CommonModule,FormsModule,
|
|
|
- IonList,IonItem,IonAvatar,IonLabel,IonButton
|
|
|
- ,IonIcon
|
|
|
- ]
|
|
|
-})
|
|
|
-export class Tab3Page {
|
|
|
- posts: any[] = [];
|
|
|
- currentUser: CloudUser | undefined;
|
|
|
- newPostContent: string = ''; // 用于存储新动态的内容
|
|
|
- newPostImageUrl: string = ''; // 用于存储新动态的图片 URL(可选)
|
|
|
- commentInputs: { [key: string]: string } = {}; // 用于存储每个帖子的评论内容
|
|
|
- // commentsMap: { [key: string]: any[] } = {}; // 用于存储每个帖子的评论列表
|
|
|
+// import { Component, OnInit } from '@angular/core';
|
|
|
+// import { IonAvatar, IonButton, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
+// import { CloudQuery } from 'src/lib/ncloud';
|
|
|
+// import { CloudUser } from 'src/lib/ncloud';
|
|
|
+// import { CloudObject } from 'src/lib/ncloud';
|
|
|
+// import { CommonModule } from '@angular/common';
|
|
|
+// import { FormsModule } from '@angular/forms';
|
|
|
+// @Component({
|
|
|
+// selector: 'app-tab3',
|
|
|
+// templateUrl: 'tab3.page.html',
|
|
|
+// styleUrls: ['tab3.page.scss'],
|
|
|
+// standalone: true,
|
|
|
+// imports:[IonHeader,IonToolbar,IonTitle,IonContent,IonCard,IonCardSubtitle
|
|
|
+// ,IonCardHeader,IonCardTitle,IonCardContent,CommonModule,FormsModule,
|
|
|
+// IonList,IonItem,IonAvatar,IonLabel,IonButton
|
|
|
+// ,IonIcon
|
|
|
+// ]
|
|
|
+// })
|
|
|
+// export class Tab3Page {
|
|
|
+// posts: any[] = [];
|
|
|
+// currentUser: CloudUser | undefined;
|
|
|
+// newPostContent: string = ''; // 用于存储新动态的内容
|
|
|
+// newPostImageUrl: string = ''; // 用于存储新动态的图片 URL(可选)
|
|
|
+// commentInputs: { [key: string]: string } = {}; // 用于存储每个帖子的评论内容
|
|
|
+// // commentsMap: { [key: string]: any[] } = {}; // 用于存储每个帖子的评论列表
|
|
|
|
|
|
- constructor() {
|
|
|
- this.currentUser = new CloudUser();
|
|
|
- }
|
|
|
-
|
|
|
- async ngOnInit() {
|
|
|
- this.loadPosts();
|
|
|
- }
|
|
|
-
|
|
|
- async loadPosts() {
|
|
|
- const postQuery = new CloudQuery('Post');
|
|
|
- postQuery.include("user_id")
|
|
|
- this.posts = await postQuery.find();
|
|
|
+// constructor() {
|
|
|
+// this.currentUser = new CloudUser();
|
|
|
+// }
|
|
|
+
|
|
|
+// async ngOnInit() {
|
|
|
+// this.loadPosts();
|
|
|
+// }
|
|
|
+
|
|
|
+// async loadPosts() {
|
|
|
+// const postQuery = new CloudQuery('Post');
|
|
|
+// postQuery.include("user_id")
|
|
|
+// this.posts = await postQuery.find();
|
|
|
|
|
|
- console.log("获取的帖子:", this.posts); // 调试信息
|
|
|
-
|
|
|
- // 获取用户信息并添加到帖子中
|
|
|
- for (let post of this.posts) {
|
|
|
- // 获取该帖子的点赞用户信息
|
|
|
- console.log(post.id)
|
|
|
- this.getLikesForPost(post.id) || [];
|
|
|
- // console.log("获取的点赞信息:", a); // 调试信息
|
|
|
- // 获取该帖子的评论信息
|
|
|
- this.getCommentsForPost(post.id).then(comments=>{
|
|
|
- post.comments = comments
|
|
|
- }); // 直接将评论存储到 post 对象中
|
|
|
- // console.log("获取的评论信息:", post.comments); // 调试信息
|
|
|
+// console.log("获取的帖子:", this.posts); // 调试信息
|
|
|
+
|
|
|
+// // 获取用户信息并添加到帖子中
|
|
|
+// for (let post of this.posts) {
|
|
|
+// // 获取该帖子的点赞用户信息
|
|
|
+// console.log(post.id)
|
|
|
+// let likes=this.getLikesForPost(post.id) || [];
|
|
|
+// post.likeCount=likes?.length
|
|
|
+// // console.log("获取的点赞信息:", a); // 调试信息
|
|
|
+// // 获取该帖子的评论信息
|
|
|
+// this.getCommentsForPost(post.id).then(comments=>{
|
|
|
+// post.comments = comments
|
|
|
+// }); // 直接将评论存储到 post 对象中
|
|
|
+// // console.log("获取的评论信息:", post.comments); // 调试信息
|
|
|
|
|
|
|
|
|
- // 获取所有评论
|
|
|
- // this.commentsMap = {};
|
|
|
- // for (let post of this.posts) {
|
|
|
- // this.commentsMap[post.objectId] = await this.getCommentsForPost(post.objectId);
|
|
|
- // }
|
|
|
+// // 获取所有评论
|
|
|
+// // this.commentsMap = {};
|
|
|
+// // for (let post of this.posts) {
|
|
|
+// // this.commentsMap[post.objectId] = await this.getCommentsForPost(post.objectId);
|
|
|
+// // }
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// 获取某个帖子的评论
|
|
|
-async getCommentsForPost(postId: string) {
|
|
|
- const commentsQuery = new CloudQuery('Comments');
|
|
|
- commentsQuery.include("user_id")
|
|
|
- commentsQuery.equalTo('post_id', postId );
|
|
|
- const comments = await commentsQuery.find();
|
|
|
+// // 获取某个帖子的评论
|
|
|
+// async getCommentsForPost(postId: string) {
|
|
|
+// const commentsQuery = new CloudQuery('Comments');
|
|
|
+// commentsQuery.include("user_id")
|
|
|
+// commentsQuery.equalTo('post_id', postId );
|
|
|
+// const comments = await commentsQuery.find();
|
|
|
|
|
|
- console.log("获取的评论:", comments); // 查看获取的评论
|
|
|
+// console.log("获取的评论:", comments); // 查看获取的评论
|
|
|
|
|
|
- return comments; // 返回评论的详细信息
|
|
|
-}
|
|
|
+// return comments; // 返回评论的详细信息
|
|
|
+// }
|
|
|
|
|
|
- // 获取某个帖子的点赞用户信息
|
|
|
-async getLikesForPost(postId: string) {
|
|
|
- const likesQuery = new CloudQuery('Likes');
|
|
|
- likesQuery.equalTo('post_id', postId );
|
|
|
- const likes = await likesQuery.find();
|
|
|
- return likes
|
|
|
- ; // 返回点赞人的详细信息
|
|
|
-}
|
|
|
+// // 获取某个帖子的点赞用户信息
|
|
|
+// async getLikesForPost(postId: string) {
|
|
|
+// const likesQuery = new CloudQuery('Likes');
|
|
|
+// likesQuery.include("user_id")
|
|
|
+// likesQuery.equalTo('post_id', postId );
|
|
|
+// const likes = await likesQuery.find();
|
|
|
+// return likes
|
|
|
+// ; // 返回点赞人的详细信息
|
|
|
+// }
|
|
|
|
|
|
-async publishPost() {
|
|
|
+// async publishPost() {
|
|
|
|
|
|
- // console.log(this.newPostContent);
|
|
|
+// // console.log(this.newPostContent);
|
|
|
|
|
|
- if (!this.newPostContent) {
|
|
|
- console.error("动态内容不能为空");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 创建新的帖子对象
|
|
|
- const post = new CloudObject('Post');
|
|
|
- post.set({
|
|
|
- content: this.newPostContent,
|
|
|
- image_url: this.newPostImageUrl || '', // 如果有图片 URL,则使用
|
|
|
- user_id: this.currentUser?.id,
|
|
|
- });
|
|
|
-
|
|
|
- await post.save(); // 保存动态
|
|
|
-
|
|
|
- // 清空输入框
|
|
|
- this.newPostContent = '';
|
|
|
- this.newPostImageUrl = '';
|
|
|
-
|
|
|
- // 重新加载动态列表
|
|
|
- await this.loadPosts();
|
|
|
- }
|
|
|
-
|
|
|
-async likePost(postId: string) {
|
|
|
- if (!postId) {
|
|
|
- console.error(postId);
|
|
|
- return;
|
|
|
- }
|
|
|
+// if (!this.newPostContent) {
|
|
|
+// console.error("动态内容不能为空");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+// // 创建新的帖子对象
|
|
|
+// const post = new CloudObject('Post');
|
|
|
+// post.set({
|
|
|
+// content: this.newPostContent,
|
|
|
+// image_url: this.newPostImageUrl || '', // 如果有图片 URL,则使用
|
|
|
+// user_id: this.currentUser?.id,
|
|
|
+// });
|
|
|
+
|
|
|
+// await post.save(); // 保存动态
|
|
|
+
|
|
|
+// // 清空输入框
|
|
|
+// this.newPostContent = '';
|
|
|
+// this.newPostImageUrl = '';
|
|
|
+
|
|
|
+// // 重新加载动态列表
|
|
|
+// await this.loadPosts();
|
|
|
+// }
|
|
|
+
|
|
|
+// async likePost(postId: string) {
|
|
|
+// if (!postId) {
|
|
|
+// console.error(postId);
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
- // 创建新的点赞记录
|
|
|
- const like = new CloudObject('Likes');
|
|
|
- like.set({
|
|
|
- post_id: postId ,
|
|
|
- user_id: this.currentUser?.id ,
|
|
|
- });
|
|
|
+// // 创建新的点赞记录
|
|
|
+// const like = new CloudObject('Likes');
|
|
|
+// like.set({
|
|
|
+// post_id: postId ,
|
|
|
+// user_id: this.currentUser?.id ,
|
|
|
+// });
|
|
|
|
|
|
- await like.save(); // 保存点赞记录
|
|
|
+// await like.save(); // 保存点赞记录
|
|
|
|
|
|
|
|
|
- // 更新本地状态
|
|
|
- await this.loadPosts(); // 重新加载帖子以更新点赞状态
|
|
|
- }
|
|
|
+// // 更新本地状态
|
|
|
+// await this.loadPosts(); // 重新加载帖子以更新点赞状态
|
|
|
+// }
|
|
|
|
|
|
-async commentOnPost(postId: string, comment: string) {
|
|
|
+// async commentOnPost(postId: string, comment: string) {
|
|
|
|
|
|
- if (!postId || !comment) {
|
|
|
- console.error("postId or comment is undefined");
|
|
|
- return;
|
|
|
- }
|
|
|
+// if (!postId || !comment) {
|
|
|
+// console.error("postId or comment is undefined");
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
-// 创建新的评论对象
|
|
|
-const commentObj = new CloudObject('Comments');
|
|
|
-commentObj.set({
|
|
|
- post_id: postId ,
|
|
|
- user_id: this.currentUser?.id ,
|
|
|
- content: comment,
|
|
|
-});
|
|
|
-
|
|
|
-await commentObj.save(); // 保存评论记录
|
|
|
-
|
|
|
-
|
|
|
- // 更新本地状态
|
|
|
- await this.loadPosts(); // 重新加载帖子以更新评论
|
|
|
- }
|
|
|
-
|
|
|
- // 处理文件选择
|
|
|
-handleFileInput(event: any) {
|
|
|
- const file = event.target.files[0];
|
|
|
- if (file) {
|
|
|
- const reader = new FileReader();
|
|
|
- reader.onload = (e: any) => {
|
|
|
- this.newPostImageUrl = e.target.result; // 将图像数据设置为 Base64 格式
|
|
|
- };
|
|
|
- reader.readAsDataURL(file); // 读取文件为 Base64
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+// // 创建新的评论对象
|
|
|
+// const commentObj = new CloudObject('Comments');
|
|
|
+// commentObj.set({
|
|
|
+// post_id: postId ,
|
|
|
+// user_id: this.currentUser?.id ,
|
|
|
+// content: comment,
|
|
|
+// });
|
|
|
+
|
|
|
+// await commentObj.save(); // 保存评论记录
|
|
|
+
|
|
|
+
|
|
|
+// // 更新本地状态
|
|
|
+// await this.loadPosts(); // 重新加载帖子以更新评论
|
|
|
+// }
|
|
|
+
|
|
|
+// // 处理文件选择
|
|
|
+// handleFileInput(event: any) {
|
|
|
+// const file = event.target.files[0];
|
|
|
+// if (file) {
|
|
|
+// const reader = new FileReader();
|
|
|
+// reader.onload = (e: any) => {
|
|
|
+// this.newPostImageUrl = e.target.result; // 将图像数据设置为 Base64 格式
|
|
|
+// };
|
|
|
+// reader.readAsDataURL(file); // 读取文件为 Base64
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// }
|
|
|
+
|