浏览代码

暂存版

s202226701053 6 月之前
父节点
当前提交
582eba2616

+ 1 - 1
E-Cover-app/src/app/tab3/tab3.page.html

@@ -47,7 +47,7 @@
   </div>
   <!--统计版图-->
   <ion-card style="--background:white;box-shadow: none;border-bottom-left-radius: 0;
-  border-bottom-right-radius: 0;">
+  border-bottom-right-radius: 0;top:-20px;">
     <div class="card">
       <p>赞过帖子</p>
       <p>11</p>

+ 1 - 1
E-Cover-app/src/app/tab3/tab3.page.scss

@@ -12,7 +12,6 @@ ion-content {
         border-radius: 20px;
         --background: none;
         color: white;
-        top: -20px;
 
         p {
             margin: 0;
@@ -133,6 +132,7 @@ ion-content {
     margin: 15px 2%;
     border-radius: 10px;
     padding: 10px;
+    top: -20px;
 }
 
 #myPost {

+ 2 - 2
E-Cover-app/src/lib/component/post-detail/post-detail.component.html

@@ -43,7 +43,7 @@
       <div class="comment-box">
         <div class="comment-left">
           <div class="comment-avatar">
-            <img src="{{ comment.get('user')?.avatar }}" alt="User Avatar" class="comment-avatar-image">
+            <img src="{{ comment.get('UserID')?.avatar }}" alt="User Avatar" class="comment-avatar-image">
           </div>
           <span class="floor">{{comments.indexOf(comment) + 1}}L</span>
         </div>
@@ -51,7 +51,7 @@
         <div class="comment-middle">
   
           <div class="comment-content">
-            <span class="comment-username">{{ comment.get('user')?.username }}</span>
+            <span class="comment-username">{{ comment.get('UserID')?.name }}</span>
             <p class="comment-text">{{ comment.get('content') }}</p>
             <span class="time-ago">{{ formatTimeAgo(comment.createdAt) }}</span>
           </div>

+ 89 - 89
E-Cover-app/src/lib/component/post-detail/post-detail.component.ts

@@ -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(); // 关闭模态框
+  }
 
 
 

+ 1 - 1
E-Cover-app/src/lib/component/post-list/post-list.component.html

@@ -6,7 +6,7 @@
         alt="User Avatar" class="avatar-image" />
     </div>
     <div class="user-info">
-      <span class="username">{{ post.get('UserID')?.username || "该用户还没有名字" }}</span>
+      <span class="username">{{ post.get('UserID')?.name || "该用户还没有名字" }}</span>
       <ion-icon name="ellipsis-horizontal" class="more-icon"></ion-icon>
     </div>
   </div>

+ 3 - 1
E-Cover-app/src/lib/component/post-list/post-list.component.ts

@@ -28,11 +28,13 @@ export class PostListComponent implements OnInit {
     console.log(query);
     query.include('UserID'); // 包含 user 属性
     this.posts = await query.find(); // 使用 find 方法获取所有帖子
+    // 按评论数降序排序帖子
+    this.posts.sort((a, b) => (b.commentCount || 0) - (a.commentCount || 0));
     console.log(this.posts);
      // 获取每个帖子的评论数
      for (let post of this.posts) {
       const commentQuery = new CloudQuery('comment');
-      commentQuery.equalTo('post', post.toPointer()); // 根据帖子指针查询评论
+      commentQuery.equalTo('postID', post.toPointer()); // 根据帖子指针查询评论
       const comments = await commentQuery.find(); // 获取评论
       post.commentCount = comments.length; // 将评论数存储在帖子对象中
       console.log('帖子评论数',post.commentCount);