fix: 修复@提及uid始终为0的BUG + 空@提示优化

- SearchUsersByLevel SQL id列别名改为uid,修复GORM字段名映射导致uid=0
- @空输入时悬浮窗显示'输入以查找用户'而非空白
- 清理历史脏数据(uid=0的mention记录)
This commit is contained in:
2026-06-03 00:55:51 +08:00
parent 4ac4f64f33
commit be8ce04334
2 changed files with 20 additions and 3 deletions

View File

@ -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).

View File

@ -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 = '';