fix: 评论系统全量检查修复(7 项 Gap 全部修复)
- Delete 权限:新增 requesterID/isAdmin 参数,Service 层鉴权(仅本人/管理员可删)
- 通知内容:改用 GetUsernameByID 显示真实用户名,非数字 UID
- SearchUsers:Repository 返回 exp,Service 调用 GetLevelByExp 计算等级
- 通知高亮:Notification 新增 CommentID 字段,消息链接支持 #comment-{id}
- 已删除提示:前端 hash 检测 + 3 秒超时 Toast "该评论已不存在"
- Admin CSS:移除不存在的 comments.css 引用
- 错误哨兵:改用 common.ErrCommentNotFound/ErrCommentEmpty/PermissionDenied
This commit is contained in:
@ -42,7 +42,11 @@
|
||||
{{if or (eq $m.NotifyType "post_approved") (eq $m.NotifyType "post_rejected")}}
|
||||
{{$link = printf "/posts/%d" (derefUint $m.RelatedID)}}
|
||||
{{else if or (eq $m.NotifyType "comment") (eq $m.NotifyType "comment_reply")}}
|
||||
{{$link = printf "/posts/%d#comments" (derefUint $m.RelatedID)}}
|
||||
{{if $m.CommentID}}
|
||||
{{$link = printf "/posts/%d#comment-%d" (derefUint $m.RelatedID) (derefUint $m.CommentID)}}
|
||||
{{else}}
|
||||
{{$link = printf "/posts/%d#comments" (derefUint $m.RelatedID)}}
|
||||
{{end}}
|
||||
{{else if or (eq $m.NotifyType "audit_approved") (eq $m.NotifyType "audit_rejected")}}
|
||||
{{$link = "/settings"}}
|
||||
{{end}}
|
||||
|
||||
@ -703,8 +703,55 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ====== Hash 定位:从消息通知跳转时滚动到评论区 ======
|
||||
if (window.location.hash === '#comments') {
|
||||
// ====== 评论高亮 + 已删除评论Toast ======
|
||||
function showToast(msg) {
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'toast';
|
||||
toast.textContent = msg;
|
||||
toast.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);background:rgba(0,0,0,0.85);color:#fff;padding:10px 24px;border-radius:6px;font-size:14px;z-index:9999;animation:fadeIn 0.3s ease';
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(function() {
|
||||
toast.style.opacity = '0';
|
||||
toast.style.transition = 'opacity 0.3s';
|
||||
setTimeout(function() { toast.remove(); }, 300);
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
function highlightComment(commentId) {
|
||||
var card = commentsList.querySelector('.comment-card[data-id="' + commentId + '"]') ||
|
||||
commentsList.querySelector('.comment-reply-card[data-id="' + commentId + '"]');
|
||||
if (card) {
|
||||
// 置顶:移动卡片到列表顶部
|
||||
commentsList.insertBefore(card, commentsList.firstChild);
|
||||
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
card.style.background = '#fff8e1';
|
||||
card.style.transition = 'background 1.5s';
|
||||
setTimeout(function() { card.style.background = ''; }, 2000);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析 hash(支持 #comment-{id}、#comments 以及回退)
|
||||
var hash = window.location.hash;
|
||||
var commentMatch = hash.match(/^#comment-(\d+)$/);
|
||||
if (commentMatch) {
|
||||
var targetCommentId = commentMatch[1];
|
||||
// 等待评论加载完成后查找
|
||||
var checkInterval = setInterval(function() {
|
||||
if (highlightComment(targetCommentId)) {
|
||||
clearInterval(checkInterval);
|
||||
}
|
||||
}, 300);
|
||||
// 3秒后超时(评论可能已被删除)
|
||||
setTimeout(function() {
|
||||
clearInterval(checkInterval);
|
||||
if (!commentsList.querySelector('.comment-card[data-id="' + targetCommentId + '"]') &&
|
||||
!commentsList.querySelector('.comment-reply-card[data-id="' + targetCommentId + '"]')) {
|
||||
showToast('该评论已不存在');
|
||||
}
|
||||
}, 3000);
|
||||
} else if (hash === '#comments') {
|
||||
setTimeout(function() {
|
||||
var section = document.getElementById('comments');
|
||||
if (section) {
|
||||
|
||||
Reference in New Issue
Block a user