|
|
|
@ -2,7 +2,13 @@
|
|
|
|
|
<div class="post-detail-container">
|
|
|
|
|
<!-- 作者信息栏 -->
|
|
|
|
|
<div class="author-info" v-if="author && author.userName">
|
|
|
|
|
<img :src="author.userAvatar || require('@/assets/default-avatar/boy_1.png')" alt="头像" class="author-avatar" />
|
|
|
|
|
<img
|
|
|
|
|
:src="author.userAvatar || require('@/assets/default-avatar/boy_1.png')"
|
|
|
|
|
alt="头像"
|
|
|
|
|
class="author-avatar"
|
|
|
|
|
@click="goUserHome(author.userId)"
|
|
|
|
|
style="cursor: pointer;"
|
|
|
|
|
/>
|
|
|
|
|
<div class="author-details">
|
|
|
|
|
<h3 class="author-name">{{ author.userName || '匿名用户' }}</h3>
|
|
|
|
|
<p class="author-stats">粉丝数:{{ author.followers ?? 0 }}</p>
|
|
|
|
@ -18,7 +24,7 @@
|
|
|
|
|
<h1 class="post-title">{{ postDetailStore.post?.title || '' }}</h1>
|
|
|
|
|
<p class="post-body">{{ postDetailStore.post?.content || '' }}</p>
|
|
|
|
|
<div class="post-stats">
|
|
|
|
|
<span> 热度 {{ postDetailStore.post?.likeCount ?? 0 }}</span>
|
|
|
|
|
<span> 浏览量 {{ postDetailStore.post?.likeCount ?? 0 }}</span>
|
|
|
|
|
<span> 点赞 {{ postDetailStore.post?.favoriteCount ?? 0 }}</span>
|
|
|
|
|
<span> 评论 {{ postDetailStore.post?.commentCount ?? 0 }}</span>
|
|
|
|
|
</div>
|
|
|
|
@ -32,7 +38,13 @@
|
|
|
|
|
<h2 class="comments-title">评论</h2>
|
|
|
|
|
<ul class="comments-list">
|
|
|
|
|
<li v-for="comment in postDetailStore.comments" :key="comment.id" class="comment-item">
|
|
|
|
|
<img :src="comment.userAvatar || require('@/assets/default-avatar/boy_1.png')" alt="评论者头像" class="comment-avatar" />
|
|
|
|
|
<img
|
|
|
|
|
:src="comment.userAvatar || require('@/assets/default-avatar/boy_1.png')"
|
|
|
|
|
alt="评论者头像"
|
|
|
|
|
class="comment-avatar"
|
|
|
|
|
@click="goUserHome(comment.userId)"
|
|
|
|
|
style="cursor: pointer;"
|
|
|
|
|
/>
|
|
|
|
|
<div class="comment-content">
|
|
|
|
|
<p class="comment-name">{{ comment.userName || '匿名用户' }}</p>
|
|
|
|
|
<p class="comment-text">{{ comment.content || '' }}</p>
|
|
|
|
@ -41,15 +53,21 @@
|
|
|
|
|
<span class="comment-likes">赞 {{ comment.likeCount ?? 0 }}</span>
|
|
|
|
|
<span v-if="comment.replyCount > 0">
|
|
|
|
|
<button @click="loadReplies(comment)">
|
|
|
|
|
{{ comment.replies && comment.replies.length > 0 ? '收起回复' : '展开回复' }} ({{ comment.replyCount }})
|
|
|
|
|
{{ comment.showReplies> 0 ? '收起回复' : '展开回复' }} ({{ comment.replyCount }})
|
|
|
|
|
</button>
|
|
|
|
|
</span>
|
|
|
|
|
<button class="reply-btn" @click="startReply(comment)">回复</button>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- 子评论列表 -->
|
|
|
|
|
<ul v-if="comment.replies && comment.replies.length > 0" class="replies-list">
|
|
|
|
|
<ul v-if="comment.showReplies && comment.replies && comment.replies.length > 0" class="replies-list">
|
|
|
|
|
<li v-for="reply in comment.replies" :key="reply.id" class="comment-item reply-item">
|
|
|
|
|
<img :src="reply.userAvatar || require('@/assets/default-avatar/boy_1.png')" alt="评论者头像" class="comment-avatar" />
|
|
|
|
|
<img
|
|
|
|
|
:src="reply.userAvatar || require('@/assets/default-avatar/boy_1.png')"
|
|
|
|
|
alt="评论者头像"
|
|
|
|
|
class="comment-avatar"
|
|
|
|
|
@click="goUserHome(reply.userId)"
|
|
|
|
|
style="cursor: pointer;"
|
|
|
|
|
/>
|
|
|
|
|
<div class="comment-content">
|
|
|
|
|
<p class="comment-name">
|
|
|
|
|
{{ reply.userName || '匿名用户' }}
|
|
|
|
@ -89,10 +107,11 @@
|
|
|
|
|
|
|
|
|
|
<script setup lang="js" name="PostDetail">
|
|
|
|
|
import { ref, computed, onMounted , onUnmounted, watch } from 'vue';
|
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
import { useRoute,useRouter } from 'vue-router';
|
|
|
|
|
import { usePostDetailStore } from '@/stores/postdetail.js';
|
|
|
|
|
import { useUserStore } from '@/stores/user.js';
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const postDetailStore = usePostDetailStore();
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
@ -106,7 +125,9 @@ const isFollowing = ref(false);
|
|
|
|
|
const toggleFollow = () => {
|
|
|
|
|
isFollowing.value = !isFollowing.value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const goUserHome = (userId) => {
|
|
|
|
|
if (userId) router.push({name: 'UserPage',params: { userId: userId }})
|
|
|
|
|
}
|
|
|
|
|
function startReply(comment) {
|
|
|
|
|
replyingComment.value = comment;
|
|
|
|
|
}
|
|
|
|
@ -132,7 +153,14 @@ function handleScroll() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function loadReplies(comment) {
|
|
|
|
|
if (!comment.repliesLoading && !comment.repliesFinished) {
|
|
|
|
|
// 如果已经展开,则收起
|
|
|
|
|
if (comment.showReplies) {
|
|
|
|
|
comment.showReplies = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 否则展开并加载
|
|
|
|
|
comment.showReplies = true;
|
|
|
|
|
if (!comment.repliesLoading && !comment.repliesFinished && comment.replies.length === 0) {
|
|
|
|
|
postDetailStore.fetchReplies(comment.id, comment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -157,7 +185,9 @@ const sendComment = () => {
|
|
|
|
|
topId: replyingComment.value ? replyingComment.value.topId : null,
|
|
|
|
|
isLike: false,
|
|
|
|
|
}
|
|
|
|
|
postDetailStore.addComment(newCommentData);
|
|
|
|
|
console.log('回复:', replyingComment.value);
|
|
|
|
|
console.log('发送评论:', newCommentData);
|
|
|
|
|
postDetailStore.sendComment(newCommentData);
|
|
|
|
|
newComment.value = '';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|