吴雨瞳添加了注释

master
wyt 6 months ago
parent a281f31711
commit 0a0ed8f6ef

@ -1,28 +1,36 @@
<template>
<!-- 评论项容器设置外边距和最大宽度 -->
<div class="mt-5 max-w-full">
<div class="flex space-x-3 xl:space-x-5">
<!-- 评论者头像组件使用评论数据中的头像地址 -->
<Avatar :url="comment.avatar" />
<div class="max-w-full-calc space-y-5">
<!-- 评论内容区域设置背景内边距圆角等样式 -->
<div class="bg-white text-primary p-4 rounded-md relative shadow-md reply" style="width: fit-content">
<!-- 评论内容将换行符替换为<br>标签以正确显示换行 -->
<p class="commentContent" v-html="comment.commentContent.replaceAll('\n', '<br>')" />
<!-- 评论元信息区域评论者昵称时间和回复按钮 -->
<div class="flex justify-between mt-3 text-xs text-gray-400 space-x-3 md:space-x-16">
<span>{{ comment.nickname }} | {{ time }}</span>
<div>
<!-- 回复按钮点击显示回复表单 -->
<span @click="clickOnReply" class="cursor-pointer reply-button">Reply</span>
</div>
</div>
</div>
<!-- 回复表单组件通过v-show控制显示/隐藏 -->
<CommentReplyForm
v-show="show"
:replyUserId="comment.userId"
:initialContent="replyContent"
@changeShow="changeShow" />
v-show="show"
:replyUserId="comment.userId"
:initialContent="replyContent"
@changeShow="changeShow" />
<!-- 评论的回复列表使用过渡组实现动画效果 -->
<transition-group name="fade">
<CommentReplyItem
v-for="reply in comment.replyDTOs"
:key="reply.id"
:reply="reply"
:commentUserId="comment.userId" />
v-for="reply in comment.replyDTOs"
:key="reply.id"
:reply="reply"
:commentUserId="comment.userId" />
</transition-group>
</div>
</div>
@ -30,50 +38,68 @@
</template>
<script lang="ts">
// VueAPI
import { defineComponent, reactive, ref, toRefs, provide } from 'vue'
//
import Avatar from '@/components/Avatar.vue'
//
import CommentReplyItem from './CommentReplyItem.vue'
//
import CommentReplyForm from './CommentReplyForm.vue'
//
export default defineComponent({
components: {
Avatar,
CommentReplyItem,
CommentReplyForm
Avatar, //
CommentReplyItem, //
CommentReplyForm //
},
props: ['comment', 'index'],
props: ['comment', 'index'], //
setup(props) {
//
const comment: any = props.comment
// ID
provide('parentId', comment.id)
provide('index', props.index)
//
const formatTime = (time: any): any => {
let date = new Date(time)
let year = date.getFullYear()
let month = date.getMonth() + 1
let month = date.getMonth() + 1 // 01
let day = date.getDate()
return year + '-' + month + '-' + day
}
//
const reactiveData = reactive({
replyContent: '' as any,
time: formatTime(props.comment.createTime) as any,
show: false as any
replyContent: '' as any, //
time: formatTime(props.comment.createTime) as any, //
show: false as any //
})
//
const changeShow = () => {
reactiveData.show = false
}
//
const clickOnReply = () => {
reactiveData.replyContent = 'add reply...'
reactiveData.show = true
reactiveData.replyContent = 'add reply...' //
reactiveData.show = true //
}
return {
...toRefs(reactiveData),
clickOnReply,
changeShow
...toRefs(reactiveData), // ref
clickOnReply, //
changeShow //
}
}
})
</script>
<style lang="scss" scoped>
//
.reply::before {
content: '';
position: absolute;
@ -85,16 +111,22 @@ export default defineComponent({
left: -8px;
top: 14px;
}
//
.reply {
background: var(--background-primary);
}
//
.reply-button {
color: var(--text-accent);
}
//
.commentContent {
line-height: 26px;
white-space: pre-line;
word-wrap: break-word;
word-break: break-all;
}
</style>
</style>
Loading…
Cancel
Save