feat: 对接稿件审核通知系统 + 消息页面系统消息区域
- 新增通知类型 post_approved / post_rejected
- PostService.Approve/Reject 完成后通知作者(通知失败不影响主流程)
- NotificationService 新增 NotifyPostApproved/NotifyPostRejected 方法
- 消息页面顶部增加系统消息标识和分隔线,之下为全部消息列表
- 稿件审核通过通知卡片点击跳转到 /posts/{id} 页面
- 稿件审核拒绝通知卡片点击跳转到 /studio/posts 创作中心
- 新增 postNotifier 接口遵循 ISP 原则
This commit is contained in:
@ -21,6 +21,15 @@
|
||||
</aside>
|
||||
|
||||
<div class="msg-main">
|
||||
<!-- 系统消息区域 -->
|
||||
<div class="msg-system-section">
|
||||
<div class="msg-system-header">
|
||||
<svg class="msg-system-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="18" height="18"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
|
||||
系统消息
|
||||
</div>
|
||||
<div class="msg-system-divider"></div>
|
||||
</div>
|
||||
|
||||
{{if .Messages}}
|
||||
<div class="msg-toolbar">
|
||||
{{if .UnreadCount}}
|
||||
@ -29,7 +38,18 @@
|
||||
</div>
|
||||
<div class="msg-list">
|
||||
{{range $i, $m := .Messages}}
|
||||
<div class="msg-card{{if not $m.IsRead}} unread{{end}}" data-id="{{$m.ID}}">
|
||||
{{$link := ""}}
|
||||
{{if or (eq $m.NotifyType "post_approved") (eq $m.NotifyType "post_rejected")}}
|
||||
{{if eq $m.NotifyType "post_approved"}}
|
||||
{{$link = printf "/posts/%d" $m.RelatedID}}
|
||||
{{else}}
|
||||
{{$link = "/studio/posts"}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{if $link}}
|
||||
<a href="{{$link}}" class="msg-card-link">
|
||||
{{end}}
|
||||
<div class="msg-card{{if not $m.IsRead}} unread{{end}}" data-id="{{$m.ID}}" data-type="{{$m.NotifyType}}" data-link="{{$link}}">
|
||||
<div class="msg-icon">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="20" height="20"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
|
||||
</div>
|
||||
@ -45,6 +65,9 @@
|
||||
<span class="msg-badge"></span>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if $link}}
|
||||
</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
@ -82,7 +105,10 @@
|
||||
var cards = document.querySelectorAll('.msg-card.unread');
|
||||
for (var i = 0; i < cards.length; i++) {
|
||||
(function (card) {
|
||||
card.addEventListener('click', function () {
|
||||
card.addEventListener('click', function (e) {
|
||||
var link = card.getAttribute('data-link');
|
||||
// 如果是可跳转的通知(post 审核),不阻止默认行为,只标记已读
|
||||
// 标记已读通过 fetch 发送,不阻止链接跳转
|
||||
var id = card.getAttribute('data-id');
|
||||
if (!id) return;
|
||||
var xhr = new XMLHttpRequest();
|
||||
@ -96,6 +122,15 @@
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
|
||||
// 如果有链接,在标记已读后跳转(非 post 通知直接标记已读)
|
||||
if (link) {
|
||||
e.preventDefault();
|
||||
var self = this;
|
||||
setTimeout(function () {
|
||||
window.location.href = link;
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
})(cards[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user