feat: comments use timeline

This commit is contained in:
tim
2025-07-07 15:57:02 +08:00
parent 09c32059b6
commit 2d99f195ca
3 changed files with 33 additions and 9 deletions
@@ -25,6 +25,7 @@ export default {
.timeline { .timeline {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%;
} }
.timeline-item { .timeline-item {
+16 -5
View File
@@ -6,11 +6,11 @@
...(level > 0 ? { /*borderLeft: '1px solid #e0e0e0', */borderBottom: 'none' } : {}) ...(level > 0 ? { /*borderLeft: '1px solid #e0e0e0', */borderBottom: 'none' } : {})
}" }"
> >
<div class="user-avatar-container"> <!-- <div class="user-avatar-container">
<div class="user-avatar-item"> <div class="user-avatar-item">
<img class="user-avatar-item-img" :src="comment.avatar" alt="avatar" /> <img class="user-avatar-item-img" :src="comment.avatar" alt="avatar" />
</div> </div>
</div> </div> -->
<div class="info-content"> <div class="info-content">
<div class="info-content-header"> <div class="info-content-header">
<div class="user-name">{{ comment.userName }}</div> <div class="user-name">{{ comment.userName }}</div>
@@ -45,13 +45,23 @@
{{ comment.reply.length }}条回复 {{ comment.reply.length }}条回复
</div> </div>
<div v-if="showReplies" class="reply-list"> <div v-if="showReplies" class="reply-list">
<CommentItem <BaseTimeline :items="comment.reply" >
<template #item="{ item }">
<CommentItem
:key="item.id"
:comment="item"
:level="level + 1"
:default-show-replies="item.openReplies"
/>
</template>
</BaseTimeline>
<!-- <CommentItem
v-for="r in comment.reply" v-for="r in comment.reply"
:key="r.id" :key="r.id"
:comment="r" :comment="r"
:level="level + 1" :level="level + 1"
:default-show-replies="r.openReplies" :default-show-replies="r.openReplies"
/> /> -->
</div> </div>
</div> </div>
</div> </div>
@@ -61,6 +71,7 @@
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import CommentEditor from './CommentEditor.vue' import CommentEditor from './CommentEditor.vue'
import { renderMarkdown } from '../utils/markdown' import { renderMarkdown } from '../utils/markdown'
import BaseTimeline from './BaseTimeline.vue'
import { API_BASE_URL, toast } from '../main' import { API_BASE_URL, toast } from '../main'
import { getToken } from '../utils/auth' import { getToken } from '../utils/auth'
const CommentItem = { const CommentItem = {
@@ -150,7 +161,7 @@ const CommentItem = {
return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply } return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply }
} }
} }
CommentItem.components = { CommentItem, CommentEditor } CommentItem.components = { CommentItem, CommentEditor, BaseTimeline }
export default CommentItem export default CommentItem
</script> </script>
+16 -4
View File
@@ -68,14 +68,24 @@
<CommentEditor @submit="postComment" :loading="isWaitingPostingComment" /> <CommentEditor @submit="postComment" :loading="isWaitingPostingComment" />
<div class="comments-container"> <div class="comments-container">
<CommentItem <BaseTimeline :items="comments" >
<template #item="{ item }">
<CommentItem
:key="item.id"
:comment="item"
:level="level + 1"
:default-show-replies="item.openReplies"
/>
</template>
</BaseTimeline>
<!-- <CommentItem
v-for="comment in comments" v-for="comment in comments"
:key="comment.id" :key="comment.id"
:comment="comment" :comment="comment"
:level="0" :level="0"
:default-show-replies="comment.openReplies" :default-show-replies="comment.openReplies"
ref="postItems" ref="postItems"
/> /> -->
</div> </div>
</div> </div>
@@ -100,6 +110,7 @@ import { ref, computed, onMounted, nextTick } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import CommentItem from '../components/CommentItem.vue' import CommentItem from '../components/CommentItem.vue'
import CommentEditor from '../components/CommentEditor.vue' import CommentEditor from '../components/CommentEditor.vue'
import BaseTimeline from '../components/BaseTimeline.vue'
import { renderMarkdown } from '../utils/markdown' import { renderMarkdown } from '../utils/markdown'
import { API_BASE_URL, toast } from '../main' import { API_BASE_URL, toast } from '../main'
import { getToken } from '../utils/auth' import { getToken } from '../utils/auth'
@@ -108,7 +119,7 @@ hatch.register()
export default { export default {
name: 'PostPageView', name: 'PostPageView',
components: { CommentItem, CommentEditor }, components: { CommentItem, CommentEditor, BaseTimeline },
setup() { setup() {
const route = useRoute() const route = useRoute()
const postId = route.params.id const postId = route.params.id
@@ -133,7 +144,8 @@ export default {
avatar: c.author.avatar, avatar: c.author.avatar,
text: c.content, text: c.content,
reply: (c.replies || []).map(mapComment), reply: (c.replies || []).map(mapComment),
openReplies: false openReplies: false,
src: c.author.avatar,
}) })
const findCommentPath = (id, list) => { const findCommentPath = (id, list) => {