吴雨瞳添加了注释

master
wyt 6 months ago
parent 129274a270
commit 3807f33ed0

@ -1,78 +1,105 @@
<template>
<!-- 回复项容器 -->
<div>
<div class="flex space-x-3 xl:space-x-5">
<!-- 回复者头像组件使用回复数据中的头像地址 -->
<Avatar :url="reply.avatar" />
<!-- 回复内容区域设置背景内边距圆角等样式 -->
<div class="reply bg-white flex flex-col p-3 rounded-md relative shadow-md">
<!-- 回复内容将换行符替换为<br>标签以正确显示换行 -->
<p class="commentContent" v-html="commentContent.replaceAll('\n', '<br>')" />
<!-- 回复元信息区域回复者昵称时间和回复按钮 -->
<div class="flex justify-between mt-2 text-xs text-gray-400 space-x-3 md:space-x-16">
<span> {{ reply.nickname }} | {{ time }}</span>
<div>
<!-- 回复按钮点击显示回复表单针对该回复的嵌套回复 -->
<span @click="clickOnSonReply" class="cursor-pointer reply-button">Reply</span>
</div>
</div>
</div>
</div>
<!-- 空链接可能用于后续扩展 -->
<a href="" target="_blank"></a>
<!-- 回复表单组件通过v-show控制显示/隐藏用于嵌套回复 -->
<CommentReplyForm
class="mt-5"
v-show="show"
:replyUserId="reply.userId"
:initialContent="replyContent"
@changeShow="changeShow" />
class="mt-5"
v-show="show"
:replyUserId="reply.userId"
:initialContent="replyContent"
@changeShow="changeShow" />
</div>
</template>
<script lang="ts">
// VueAPI
import { computed, defineComponent, reactive, toRefs } from 'vue'
//
import Avatar from '@/components/Avatar.vue'
//
import CommentReplyForm from './CommentReplyForm.vue'
//
export default defineComponent({
components: {
Avatar,
CommentReplyForm
Avatar, //
CommentReplyForm //
},
props: ['reply', 'commentUserId'],
props: ['reply', 'commentUserId'], // ID
setup(props) {
//
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.reply.createTime) as any,
show: false as any
replyContent: '' as any, //
time: formatTime(props.reply.createTime) as any, //
show: false as any //
})
// @
const clickOnSonReply = () => {
reactiveData.replyContent = '@' + props.reply.nickname
reactiveData.show = true
reactiveData.replyContent = '@' + props.reply.nickname // @
reactiveData.show = true //
}
//
const changeShow = () => {
reactiveData.show = false
}
// @
const commentContent = computed(() => {
//
if (props.reply.replyUserId !== props.commentUserId) {
// @
return (
`<a href="${props.reply.replyWebsite}" target="_blank" class="reply-link">@${props.reply.replyNickname}&nbsp</a>` +
props.reply.commentContent
`<a href="${props.reply.replyWebsite}" target="_blank" class="reply-link">@${props.reply.replyNickname}&nbsp</a>` +
props.reply.commentContent
)
} else {
//
return props.reply.commentContent
}
})
return {
...toRefs(reactiveData),
commentContent,
clickOnSonReply,
changeShow
...toRefs(reactiveData), // ref
commentContent, //
clickOnSonReply, //
changeShow //
}
}
})
</script>
<style lang="scss" scoped>
//
.reply::before {
content: '';
position: absolute;
@ -84,12 +111,18 @@ 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;
@ -97,8 +130,10 @@ export default defineComponent({
word-break: break-all;
}
</style>
// @
<style lang="scss">
.reply-link {
color: var(--text-accent);
}
</style>
</style>
Loading…
Cancel
Save