diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 7242b1c..27cf6c6 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -507,40 +507,43 @@ document.getElementById('room-title-display').innerText = e.detail.title; }); - // ── 管理员全员清屏事件 ─────────────────────── - window.addEventListener('chat:screen-cleared', (e) => { - const operator = e.detail.operator; + // ── 管理员全员清屏事件(直接用 Echo 监听,不依赖编译产物) ─────── + if (window.Echo) { + window.Echo.join(`room.${window.chatContext.roomId}`) + .listen('ScreenCleared', (e) => { + const operator = e.operator; - // 清除公聊窗口(say1)所有消息 - const say1 = document.getElementById('say'); - if (say1) say1.innerHTML = ''; + // 清除公聊窗口(say1)所有消息 + const say1 = document.getElementById('say'); + if (say1) say1.innerHTML = ''; - // 清除包厢窗口(say2)中非悄悄话的消息 - const say2 = document.getElementById('say2'); - if (say2) { - const items = say2.querySelectorAll('.msg-line'); - items.forEach(item => { - // 保留悄悄话消息(含 msg-secret 类) - if (!item.querySelector('.msg-secret')) { - item.remove(); + // 清除包厢窗口(say2)中非悄悄话的消息 + const say2 = document.getElementById('say2'); + if (say2) { + const items = say2.querySelectorAll('.msg-line'); + items.forEach(item => { + // 保留悄悄话消息(含 msg-secret 类) + if (!item.querySelector('.msg-secret')) { + item.remove(); + } + }); + } + + // 显示清屏提示 + const sysDiv = document.createElement('div'); + sysDiv.className = 'msg-line'; + const now = new Date(); + const timeStr = now.getHours().toString().padStart(2, '0') + ':' + + now.getMinutes().toString().padStart(2, '0') + ':' + + now.getSeconds().toString().padStart(2, '0'); + sysDiv.innerHTML = + `🧹 管理员 ${operator} 已执行全员清屏(${timeStr})`; + if (say1) { + say1.appendChild(sysDiv); + say1.scrollTop = say1.scrollHeight; } }); - } - - // 显示清屏提示 - const sysDiv = document.createElement('div'); - sysDiv.className = 'msg-line'; - const now = new Date(); - const timeStr = now.getHours().toString().padStart(2, '0') + ':' + - now.getMinutes().toString().padStart(2, '0') + ':' + - now.getSeconds().toString().padStart(2, '0'); - sysDiv.innerHTML = - `🧹 管理员 ${operator} 已执行全员清屏(${timeStr})`; - if (say1) { - say1.appendChild(sysDiv); - say1.scrollTop = say1.scrollHeight; - } - }); + } // ── 发送消息(Enter 发送) ─────────────────────── document.getElementById('content').addEventListener('keydown', function(e) {