This commit is contained in:
2026-03-03 17:10:39 +08:00
parent 8660bbc348
commit b5b9f7db06
4 changed files with 33 additions and 4 deletions

View File

@@ -196,6 +196,26 @@
<!-- 通知面板脚本 -->
<script>
(function(){
let lastNotifCount = -1;
const notifSound = new Audio('data:audio/wav;base64,UklGRl9vT19teleQBAAAAAABAAEARKwAAIhYAQACABAAZGF0YU' + 'tvT19t');
// 创建通知提示音(简短的叮咚声)
function playNotifSound() {
try {
const ctx = new (window.AudioContext || window.webkitAudioContext)();
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain);
gain.connect(ctx.destination);
osc.frequency.setValueAtTime(880, ctx.currentTime);
osc.frequency.setValueAtTime(1100, ctx.currentTime + 0.1);
gain.gain.setValueAtTime(0.3, ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + 0.3);
osc.start(ctx.currentTime);
osc.stop(ctx.currentTime + 0.3);
} catch(e) {}
}
function toggleNotifPanel() {
const panel = document.getElementById('notifPanel');
panel.classList.toggle('hidden');
@@ -217,9 +237,14 @@
if (d.count > 0) {
badge.textContent = d.count > 99 ? '99+' : d.count;
badge.classList.remove('hidden');
// 有新通知时播放声音
if (lastNotifCount >= 0 && d.count > lastNotifCount) {
playNotifSound();
}
} else {
badge.classList.add('hidden');
}
lastNotifCount = d.count;
}).catch(()=>{});
}
updateNotifBadge();
@@ -274,11 +299,12 @@
}
function markRead(nid, el) {
fetch(`/api/notifications/${nid}/read`, {method:'POST'});
fetch(`/api/notifications/${nid}/read`, {method:'POST'}).then(()=>{
updateNotifBadge();
});
el.classList.remove('bg-blue-50/50');
const dot = el.querySelector('.bg-blue-500');
if (dot) dot.remove();
updateNotifBadge();
}
window.markRead = markRead;