From be8ce04334a972094ed65baa0ef61815277cdb0b Mon Sep 17 00:00:00 2001 From: Victor_Jay Date: Wed, 3 Jun 2026 00:55:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D@=E6=8F=90=E5=8F=8Auid?= =?UTF-8?q?=E5=A7=8B=E7=BB=88=E4=B8=BA0=E7=9A=84BUG=20+=20=E7=A9=BA@?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SearchUsersByLevel SQL id列别名改为uid,修复GORM字段名映射导致uid=0 - @空输入时悬浮窗显示'输入以查找用户'而非空白 - 清理历史脏数据(uid=0的mention记录) --- internal/repository/comment_mention_repo.go | 2 +- .../MetaLab-2026/static/js/post-comments.js | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/repository/comment_mention_repo.go b/internal/repository/comment_mention_repo.go index d7f63b5..647ba0a 100644 --- a/internal/repository/comment_mention_repo.go +++ b/internal/repository/comment_mention_repo.go @@ -80,7 +80,7 @@ func (r *CommentRepo) SearchUsersByLevel(keyword string, minLevel int, limit int threshold := model.LevelThresholds[minLevel] err := r.db.Table("users"). - Select("id, username, avatar, exp"). + Select("id AS uid, username, avatar, exp"). Where("username LIKE ? AND exp >= ? AND deleted_at IS NULL", "%"+keyword+"%", threshold). Order("exp DESC"). Limit(limit). diff --git a/templates/MetaLab-2026/static/js/post-comments.js b/templates/MetaLab-2026/static/js/post-comments.js index d013c84..26809bd 100644 --- a/templates/MetaLab-2026/static/js/post-comments.js +++ b/templates/MetaLab-2026/static/js/post-comments.js @@ -296,9 +296,9 @@ clearTimeout(searchTimer); - // 仅输入 @ 时,显示空白下拉 + // 仅输入 @ 时,显示提示 if (query.length === 0) { - showMention(input, [], ''); + showEmptyHint(input); return; } @@ -366,6 +366,23 @@ dropdown.style.left = Math.min(pos.left, window.innerWidth - 230) + 'px'; } + function showEmptyHint(input) { + var dropdown = mentionDropdown; + dropdown.innerHTML = ''; + var hint = document.createElement('div'); + hint.className = 'mention-no-result'; + hint.textContent = '输入以查找用户'; + dropdown.appendChild(hint); + + var cursorIdx = input.selectionStart; + var pos = getCursorPixelPos(input, cursorIdx); + dropdown.style.display = 'block'; + dropdown.style.width = '220px'; + var dropHeight = dropdown.offsetHeight || 36; + dropdown.style.top = (pos.top - dropHeight - 4 + window.scrollY) + 'px'; + dropdown.style.left = Math.min(pos.left, window.innerWidth - 230) + 'px'; + } + function hideMention() { mentionDropdown.style.display = 'none'; mentionDropdown.innerHTML = '';