diff --git a/frontend/admin.html b/frontend/admin.html index d71fb01..5280d7a 100644 --- a/frontend/admin.html +++ b/frontend/admin.html @@ -504,15 +504,15 @@ let notifPage=1; function notifTypeIcon(type){const map={repayment_due:"📅",repayment_overdue:"⚠️",system:"📢",account:"👤"};return map[type]||"📩";} function timeAgo(dt){const diff=(Date.now()-new Date(dt).getTime())/1000;if(diff<60)return "刚刚";if(diff<3600)return Math.floor(diff/60)+"分钟前";if(diff<86400)return Math.floor(diff/3600)+"小时前";return Math.floor(diff/86400)+"天前";} -function toggleNotifDropdown(e){e.stopPropagation();const dd=$("notifDropdown");dd.classList.toggle("show");if(dd.classList.contains("show"))loadNotifications();} +function toggleNotifDropdown(e){e.stopPropagation();const dd=$('notifDropdown');dd.classList.toggle('show');if(dd.classList.contains('show'))loadNotifications();} document.addEventListener("click",function(){$("notifDropdown")?.classList.remove("show");}); -async function loadNotifications(){const res=await apiFetch("/notifications?size=20");if(!res||!res.ok)return;const data=await res.json();renderNotifBadge(data.unread);renderNotifList(data.items);} -function renderNotifBadge(unread){const badge=$("notifBadge");if(unread>0){badge.style.display="";badge.textContent=unread>99?"99+":unread;}else{badge.style.display="none";}} -function renderNotifList(items){const el=$("notifList");if(!items.length){el.innerHTML="
暂无通知
";return;}el.innerHTML=items.map(n=>`
${notifTypeIcon(n.type)}
${n.title}
${n.message}
${timeAgo(n.created_at)}
`).join("");} +async function loadNotifications(){const res=await apiFetch('/notifications?size=20');if(!res||!res.ok)return;const data=await res.json();renderNotifBadge(data.unread);renderNotifList(data.items);} +function renderNotifBadge(unread){const badge=$("notifBadge");if(unread>0){badge.style.display='';badge.textContent=unread>99?'99+':unread;}else{badge.style.display='none';}} +function renderNotifList(items){const el=$("notifList");if(!items.length){el.innerHTML='
暂无通知
';return;}el.innerHTML=items.map(n=>`
${notifTypeIcon(n.type)}
${n.title}
${n.message}
${timeAgo(n.created_at)}
`).join('');} -async function readNotif(id){await apiFetch("/notifications/"+id+"/read",{method:"PUT"});loadNotifications();} -async function markAllNotifRead(){await apiFetch("/notifications/read-all",{method:"PUT"});loadNotifications();} +async function readNotif(id){await apiFetch('/notifications/'+id+'/read',{method:'PUT'});loadNotifications();} +async function markAllNotifRead(){await apiFetch('/notifications/read-all',{method:'PUT'});loadNotifications();} init();