From 789f5e9ad1e0e10126ff25079b012a6167bc4a1b Mon Sep 17 00:00:00 2001 From: anghunk Date: Fri, 30 Jan 2026 15:52:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(widget):=20=E5=B0=86=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=95=B0=E7=BB=9F=E8=AE=A1=E7=A7=BB=E8=87=B3=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E4=B8=8B=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将评论总数统计从头部区域移动到主评论表单下方、评论列表上方,使布局更符合逻辑流。 同时更新相关选择器以正确获取评论数元素。 --- docs/widget/src/core/CWDComments.js | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/widget/src/core/CWDComments.js b/docs/widget/src/core/CWDComments.js index e2be762..8c4fbfe 100644 --- a/docs/widget/src/core/CWDComments.js +++ b/docs/widget/src/core/CWDComments.js @@ -301,7 +301,7 @@ export class CWDComments { existingSuccess.remove(); } - // 创建头部统计 + // 创建头部点赞区域 let header = this.mountPoint.querySelector('.cwd-comments-header'); if (!header) { header = document.createElement('div'); @@ -318,16 +318,9 @@ export class CWDComments {
已有 0人喜欢~
-

- 共 0 条评论 -

`; this.mountPoint.appendChild(header); } - const countEl = header.querySelector('.cwd-comments-count-number'); - if (countEl) { - countEl.textContent = state.pagination.totalCount; - } this._initLikeButton(header); @@ -350,6 +343,25 @@ export class CWDComments { this.commentForm.render(); } + // 创建评论数统计(放在主评论表单下方、评论列表上方) + let countHeading = this.mountPoint.querySelector('.cwd-comments-count'); + if (!countHeading) { + countHeading = document.createElement('h3'); + countHeading.className = 'cwd-comments-count'; + countHeading.innerHTML = ` + 共 0 条评论 + `; + if (this.formContainer && this.formContainer.parentNode === this.mountPoint) { + this.mountPoint.insertBefore(countHeading, this.formContainer.nextSibling); + } else { + this.mountPoint.appendChild(countHeading); + } + } + const countEl = this.mountPoint.querySelector('.cwd-comments-count-number'); + if (countEl) { + countEl.textContent = state.pagination.totalCount; + } + // 创建评论列表 if (!this.commentList) { const listContainer = document.createElement('div'); @@ -460,9 +472,9 @@ export class CWDComments { existingSuccess.remove(); } - // 更新头部统计 + // 更新点赞和评论数统计 const header = this.mountPoint?.querySelector('.cwd-comments-header'); - const countEl = header?.querySelector('.cwd-comments-count-number'); + const countEl = this.mountPoint?.querySelector('.cwd-comments-count-number'); if (countEl) { countEl.textContent = state.pagination.totalCount; }