forked from kingwrcy/moments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.vue
91 lines (81 loc) · 3.21 KB
/
Comment.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<div class="relative select-none">
<div class="dark:text-[#9F9F9F] ">
<span class="text-[#576b95] text-nowrap"><a class="cursor-pointer" v-if="comment.website" target="_blank"
:href="website">{{
comment.username ?? '匿名' }}</a>
<span v-else>{{ comment.username ?? '匿名' }}</span>
<b v-if="comment.author"
class="border text-xs border-[#C64A4A] rounded mx-0.5 px-0.5 text-[#C64A4A]">作者</b></span>
<span v-if="comment.replyTo" class="text-nowrap mx-1">回复<span class="text-[#576b95] ml-1"><a
class="cursor-pointer" v-if="comment.replyTo" target="_blank" :href="website">{{
comment.replyTo ?? '匿名' }}</a></span>
</span>
<span class="mr-0.5">:</span>
<span :title="`点击回复${comment.username}`" class="inline w-full break-all cursor-pointer"
@click="toggleUserComment">{{
comment.content }}</span>
<AlertDialog v-if="token">
<AlertDialogTrigger asChild>
<Trash2 :size=14 class="ml-2 cursor-pointer inline-block text-gray-300" />
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>确定删除评论吗?</AlertDialogTitle>
<AlertDialogDescription>
<div><span class="font-bold">评论内容</span>:</div>
<div class="text-wrap break-all">{{ comment.content }}</div>
<div class="my-2 text-red-400">无法恢复,你确定删除吗?</div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>取消</AlertDialogCancel>
<AlertDialogAction @click="removeComment">确定</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
<FriendsCommentInput @commentAdded="refreshComment" :memoId="comment.memoId" :commentId="comment.id"
:reply="comment.username" :replyId="comment.id" v-if="showUserCommentArray[index]" />
</div>
</template>
<script setup lang="ts">
import type { Comment } from '@/lib/types';
import { Trash2 } from 'lucide-vue-next'
import { toast } from 'vue-sonner';
const emit = defineEmits(['memo-update', 'comment-started'])
const token = useCookie('token')
const props = withDefaults(
defineProps<{
comment: Comment,
index: number
}>(), {}
)
const showUserCommentArray = useState<Array<boolean>>('showUserCommentArray_' + props.comment.memoId)
const website = computed(() => {
return props.comment.website?.startsWith('http') ? props.comment.website : `http://${props.comment.website}`
})
const refreshComment = async () => {
emit('memo-update')
showUserCommentArray.value[props.index] = false
}
const toggleUserComment = () => {
const open = showUserCommentArray.value[props.index]
showUserCommentArray.value = []
showUserCommentArray.value[props.index] = !open
emit('comment-started')
}
const removeComment = async () => {
const res = await $fetch('/api/comment/remove', {
method: 'POST',
body: JSON.stringify({
commentId: props.comment.id
})
})
if (res.success) {
toast.success('删除成功')
emit('memo-update')
}
}
</script>
<style scoped></style>