From 372ab9d29317a978c6830d55eea0784ea89175e3 Mon Sep 17 00:00:00 2001 From: Mohan Date: Fri, 14 Aug 2026 18:11:09 +0800 Subject: [PATCH] feat(component): collapse comments longer than 4 lines --- src/components/CommentSection.vue | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/components/CommentSection.vue b/src/components/CommentSection.vue index 4cb298a..bc6068f 100644 --- a/src/components/CommentSection.vue +++ b/src/components/CommentSection.vue @@ -32,6 +32,29 @@ const authorName = ref('') const authorEmail = ref('') const content = ref('') const quotedComment = ref(null) +const overflowIds = ref>(new Set()) +const expandedIds = ref>(new Set()) + +function measureComment(id: number, el: Element | null) { + if (!el) return + const node = el as HTMLElement + const lh = parseFloat(getComputedStyle(node).lineHeight) || 22 + if (node.scrollHeight > lh * 4 + 2) { + if (!overflowIds.value.has(id)) { + overflowIds.value = new Set([...overflowIds.value, id]) + } + } +} + +function toggleExpand(id: number) { + const next = new Set(expandedIds.value) + if (next.has(id)) { + next.delete(id) + } else { + next.add(id) + } + expandedIds.value = next +} function escapeBrackets(text: string): string { return text.replace(/[<>]/g, (ch) => '\\' + ch) @@ -205,7 +228,20 @@ onMounted(() => { {{ comment.authorName }} {{ formatDate(comment.createdAt) }} -

+

+