|
@@ -11,7 +11,7 @@ import { CloudObject } from 'src/lib/ncloud';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { IonModal } from '@ionic/angular/standalone';
|
|
|
|
|
|
-addIcons({ellipsisHorizontal,bookmarkOutline,heartOutline,shareSocialOutline,happyOutline,chatbubbleEllipsesOutline})
|
|
|
+addIcons({ ellipsisHorizontal, bookmarkOutline, heartOutline, shareSocialOutline, happyOutline, chatbubbleEllipsesOutline })
|
|
|
|
|
|
|
|
|
@Component({
|
|
@@ -19,7 +19,7 @@ addIcons({ellipsisHorizontal,bookmarkOutline,heartOutline,shareSocialOutline,hap
|
|
|
templateUrl: './post-detail.component.html',
|
|
|
styleUrls: ['./post-detail.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonContent, IonIcon, IonButton, CommonModule, CustomHeaderComponent,IonTextarea,IonFooter,FormsModule,IonModal]
|
|
|
+ imports: [IonContent, IonIcon, IonButton, CommonModule, CustomHeaderComponent, IonTextarea, IonFooter, FormsModule, IonModal]
|
|
|
})
|
|
|
export class PostDetailComponent implements OnInit {
|
|
|
postId: string | any;
|
|
@@ -62,97 +62,97 @@ export class PostDetailComponent implements OnInit {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // 加载与当前帖子相关的评论
|
|
|
- async loadComments() {
|
|
|
- const query = new CloudQuery("comment");
|
|
|
- query.equalTo("post", { "__type": "Pointer", "className": "post", "objectId": this.postId }); // 根据帖子ID查询评论
|
|
|
- query.include('user'); // 包含 user 属性
|
|
|
+ // 加载与当前帖子相关的评论
|
|
|
+ async loadComments() {
|
|
|
+ const query = new CloudQuery("comment");
|
|
|
+ query.equalTo("postID", { "__type": "Pointer", "className": "post", "objectId": this.postId }); // 根据帖子ID查询评论
|
|
|
+ query.include('UserID'); // 包含 user 属性
|
|
|
this.comments = await query.find(); // 获取评论
|
|
|
console.log('加载的评论:', this.comments);
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-tocomment(){
|
|
|
- this.isfooter = false; // 切换底部栏的显示样式
|
|
|
- console.log(this.isfooter);
|
|
|
-}
|
|
|
-
|
|
|
-notcomment(){
|
|
|
- this.isfooter = true; // 切换底部栏的显示样式
|
|
|
-}
|
|
|
-
|
|
|
-async submitComment() {
|
|
|
- if (this.newComment.trim()) {
|
|
|
-// 创建新的评论对象
|
|
|
-const comment = new CloudObject("comment");
|
|
|
-const user = new CloudUser();
|
|
|
-const currentUser = await user.current(); // 获取当前用户信息
|
|
|
-if (currentUser) {
|
|
|
-// 设置评论的字段
|
|
|
-await comment.set({
|
|
|
- user: new CloudUser().toPointer(), // 指向当前用户
|
|
|
- post: { "__type": "Pointer", "className": "post", "objectId": this.post.id }, // 帖子指针
|
|
|
- content: this.newComment.trim(), // 评论内容
|
|
|
- heart: 0 // 初始点赞数为0
|
|
|
-});
|
|
|
-
|
|
|
-// 保存评论
|
|
|
-await comment.save().then(() => {
|
|
|
- console.log('评论已保存:', this.newComment);
|
|
|
- this.newComment = ''; // 清空输入框
|
|
|
-})
|
|
|
-await this.loadComments(); // 加载新评论
|
|
|
-}
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-//用户评论时间
|
|
|
-formatTimeAgo(date: any): string {
|
|
|
-const date1 = new Date(date);
|
|
|
-const now = new Date();
|
|
|
-const seconds = Math.floor((now.getTime() - date1.getTime()) / 1000);
|
|
|
-//console.log("date1.getTime()",date1.getTime());
|
|
|
-//console.log("now.getTime()",now.getTime());
|
|
|
-//console.log("seconds",seconds);
|
|
|
-
|
|
|
-let interval = Math.floor(seconds / 31536000);
|
|
|
-if (interval >= 1) return interval + " 年前";
|
|
|
-interval = Math.floor(seconds / 2592000);
|
|
|
-if (interval >= 1) return interval + " 个月前";
|
|
|
-interval = Math.floor(seconds / 86400);
|
|
|
-if (interval >= 1) return interval + " 天前";
|
|
|
-interval = Math.floor(seconds / 3600);
|
|
|
-if (interval >= 1) return interval + " 小时前";
|
|
|
-interval = Math.floor(seconds / 60);
|
|
|
-if (interval >= 1) return interval + " 分钟前";
|
|
|
-return "刚刚";
|
|
|
-}
|
|
|
-
|
|
|
-isEmojiPickerOpen: boolean = false; // 控制表情选择器的打开状态
|
|
|
-emojis: string[] = ['😀', '😃', '😄', '😁', '😆', '😅', '🤣', '😂', '🙂', '🙃', '🫠', '😉', '😊', '😇', '🥰', '😍', '🤩', '😘',
|
|
|
- '😗', '☺️', '😚', '😙', '🥲', '😋', '😛', '😜', '🤪', '😝', '🤑', '🤗', '🤭', '🫢', '🫣', '🤫', '🤔', '🫡', '🤐', '🤨', '😐',
|
|
|
- '😑', '😶', '🫥', '😶🌫️', '😏', '😒', '🙄', '😬', '😮💨', '🤥', '🫨', '🙂↔️', '🙂↕️', '😌', '😔', '😪', '🤤', '😴', '', '😷',
|
|
|
- '🤒', '🤕', '🤢', '🤮', '🤧', '🥵', '🥶', '🥴', '😵', '😵💫', '🤯', '🤠', '🥳', '🥸', '😎', '🤓', '🧐', '😕', '🫤', '😟',
|
|
|
- '🙁', '☹️', '😮', '😯', '😲', '😳', '🥺', '🥹', '😦', '😧', '😨', '😰', '😥', '😢', '😭', '😱', '😖', '😣', '😞', '😓',
|
|
|
- '😩', '😫', '🥱', '😤', '😡', '😠', '🤬', '😈', '👿', '💀', '☠️', '💩', '🤡', '👹', '👺', '👻', '👽', '👾', '🤖', '😺',
|
|
|
- '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊', '💌', '💘', '❤️', '🖤', '💋', '💯', '💢', '💥', '💫',
|
|
|
- '💦', '💤']; // 表情数组
|
|
|
-// 打开表情选择器
|
|
|
-openEmojiPicker() {
|
|
|
-this.isEmojiPickerOpen = true;
|
|
|
-}
|
|
|
-
|
|
|
-// 关闭表情选择器
|
|
|
-closeEmojiPicker() {
|
|
|
-this.isEmojiPickerOpen = false; // 关闭模态框
|
|
|
-}
|
|
|
-
|
|
|
-// 添加表情到输入框
|
|
|
-addEmoji(emoji: string) {
|
|
|
-this.newComment += emoji; // 将选中的表情添加到输入框
|
|
|
-this.closeEmojiPicker(); // 关闭模态框
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+ tocomment() {
|
|
|
+ this.isfooter = false; // 切换底部栏的显示样式
|
|
|
+ console.log(this.isfooter);
|
|
|
+ }
|
|
|
+
|
|
|
+ notcomment() {
|
|
|
+ this.isfooter = true; // 切换底部栏的显示样式
|
|
|
+ }
|
|
|
+
|
|
|
+ async submitComment() {
|
|
|
+ if (this.newComment.trim()) {
|
|
|
+ // 创建新的评论对象
|
|
|
+ const comment = new CloudObject("comment");
|
|
|
+ const user = new CloudUser();
|
|
|
+ const currentUser = await user.current(); // 获取当前用户信息
|
|
|
+ if (currentUser) {
|
|
|
+ // 设置评论的字段
|
|
|
+ await comment.set({
|
|
|
+ UserID: new CloudUser().toPointer(), // 指向当前用户
|
|
|
+ postID: { "__type": "Pointer", "className": "post", "objectId": this.post.id }, // 帖子指针
|
|
|
+ content: this.newComment.trim(), // 评论内容
|
|
|
+ heart: 0 // 初始点赞数为0
|
|
|
+ });
|
|
|
+
|
|
|
+ // 保存评论
|
|
|
+ await comment.save().then(() => {
|
|
|
+ console.log('评论已保存:', this.newComment);
|
|
|
+ this.newComment = ''; // 清空输入框
|
|
|
+ })
|
|
|
+ await this.loadComments(); // 加载新评论
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户评论时间
|
|
|
+ formatTimeAgo(date: any): string {
|
|
|
+ const date1 = new Date(date);
|
|
|
+ const now = new Date();
|
|
|
+ const seconds = Math.floor((now.getTime() - date1.getTime()) / 1000);
|
|
|
+ //console.log("date1.getTime()",date1.getTime());
|
|
|
+ //console.log("now.getTime()",now.getTime());
|
|
|
+ //console.log("seconds",seconds);
|
|
|
+
|
|
|
+ let interval = Math.floor(seconds / 31536000);
|
|
|
+ if (interval >= 1) return interval + " 年前";
|
|
|
+ interval = Math.floor(seconds / 2592000);
|
|
|
+ if (interval >= 1) return interval + " 个月前";
|
|
|
+ interval = Math.floor(seconds / 86400);
|
|
|
+ if (interval >= 1) return interval + " 天前";
|
|
|
+ interval = Math.floor(seconds / 3600);
|
|
|
+ if (interval >= 1) return interval + " 小时前";
|
|
|
+ interval = Math.floor(seconds / 60);
|
|
|
+ if (interval >= 1) return interval + " 分钟前";
|
|
|
+ return "刚刚";
|
|
|
+ }
|
|
|
+
|
|
|
+ isEmojiPickerOpen: boolean = false; // 控制表情选择器的打开状态
|
|
|
+ emojis: string[] = ['😀', '😃', '😄', '😁', '😆', '😅', '🤣', '😂', '🙂', '🙃', '🫠', '😉', '😊', '😇', '🥰', '😍', '🤩', '😘',
|
|
|
+ '😗', '☺️', '😚', '😙', '🥲', '😋', '😛', '😜', '🤪', '😝', '🤑', '🤗', '🤭', '🫢', '🫣', '🤫', '🤔', '🫡', '🤐', '🤨', '😐',
|
|
|
+ '😑', '😶', '🫥', '😶🌫️', '😏', '😒', '🙄', '😬', '😮💨', '🤥', '🫨', '🙂↔️', '🙂↕️', '😌', '😔', '😪', '🤤', '😴', '', '😷',
|
|
|
+ '🤒', '🤕', '🤢', '🤮', '🤧', '🥵', '🥶', '🥴', '😵', '😵💫', '🤯', '🤠', '🥳', '🥸', '😎', '🤓', '🧐', '😕', '🫤', '😟',
|
|
|
+ '🙁', '☹️', '😮', '😯', '😲', '😳', '🥺', '🥹', '😦', '😧', '😨', '😰', '😥', '😢', '😭', '😱', '😖', '😣', '😞', '😓',
|
|
|
+ '😩', '😫', '🥱', '😤', '😡', '😠', '🤬', '😈', '👿', '💀', '☠️', '💩', '🤡', '👹', '👺', '👻', '👽', '👾', '🤖', '😺',
|
|
|
+ '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊', '💌', '💘', '❤️', '🖤', '💋', '💯', '💢', '💥', '💫',
|
|
|
+ '💦', '💤']; // 表情数组
|
|
|
+ // 打开表情选择器
|
|
|
+ openEmojiPicker() {
|
|
|
+ this.isEmojiPickerOpen = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭表情选择器
|
|
|
+ closeEmojiPicker() {
|
|
|
+ this.isEmojiPickerOpen = false; // 关闭模态框
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加表情到输入框
|
|
|
+ addEmoji(emoji: string) {
|
|
|
+ this.newComment += emoji; // 将选中的表情添加到输入框
|
|
|
+ this.closeEmojiPicker(); // 关闭模态框
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|