From 2d45e52591c20ebb8abb5528026b46ff29da4c42 Mon Sep 17 00:00:00 2001 From: lkddi Date: Thu, 26 Feb 2026 23:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E7=A6=81=E8=A8=80?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=98=BE=E7=A4=BA=E6=93=8D=E4=BD=9C=E8=80=85?= =?UTF-8?q?=20+=20=E8=A2=AB=E7=A6=81=E8=A8=80=E5=8F=91=E8=A8=80=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E6=8C=81=E4=B9=85=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserMuted 事件增加 operator 字段,禁言通知显示管理员名字 - 输入框 placeholder 显示操作者名字 - 被禁言用户发言时改为在包厢窗口显示红色持久提示(替代 alert 弹窗) --- app/Events/UserMuted.php | 4 +++- app/Http/Controllers/AdminCommandController.php | 7 ++++++- resources/views/chat/partials/scripts.blade.php | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/Events/UserMuted.php b/app/Events/UserMuted.php index 358df97..5f75907 100644 --- a/app/Events/UserMuted.php +++ b/app/Events/UserMuted.php @@ -32,6 +32,7 @@ class UserMuted implements ShouldBroadcast public readonly string $username, public readonly int $muteTime, public readonly string $message = '', + public readonly string $operator = '', ) {} /** @@ -54,12 +55,13 @@ class UserMuted implements ShouldBroadcast public function broadcastWith(): array { $statusMessage = $this->message ?: ($this->muteTime > 0 - ? "用户 [{$this->username}] 已被禁言 {$this->muteTime} 分钟。" + ? "管理员 [{$this->operator}] 已将 [{$this->username}] 禁言 {$this->muteTime} 分钟。" : "用户 [{$this->username}] 已被解除禁言。"); return [ 'username' => $this->username, 'mute_time' => $this->muteTime, + 'operator' => $this->operator, 'message' => $statusMessage, ]; } diff --git a/app/Http/Controllers/AdminCommandController.php b/app/Http/Controllers/AdminCommandController.php index efbaf90..f85a63d 100644 --- a/app/Http/Controllers/AdminCommandController.php +++ b/app/Http/Controllers/AdminCommandController.php @@ -178,7 +178,12 @@ class AdminCommandController extends Controller SaveMessageJob::dispatch($msg); // 广播禁言事件(前端禁用输入框) - broadcast(new \App\Events\UserMuted($roomId, $targetUsername, $duration, "管理员 {$admin->username} 已将您禁言 {$duration} 分钟")); + broadcast(new \App\Events\UserMuted( + roomId: $roomId, + username: $targetUsername, + muteTime: $duration, + operator: $admin->username, + )); return response()->json(['status' => 'success', 'message' => "已禁言 {$targetUsername} {$duration} 分钟"]); } diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 11f41aa..301714b 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -474,8 +474,9 @@ if (d.username === window.chatContext.username && d.mute_time > 0) { isMutedUntil = Date.now() + d.mute_time * 60 * 1000; const contentInput = document.getElementById('content'); + const operatorName = d.operator || '管理员'; if (contentInput) { - contentInput.placeholder = `您已被禁言 ${d.mute_time} 分钟,解禁后方可发言...`; + contentInput.placeholder = `${operatorName} 已将您禁言 ${d.mute_time} 分钟,解禁后方可发言...`; contentInput.disabled = true; // 到期自动恢复 setTimeout(() => { @@ -549,7 +550,17 @@ // 前端禁言检查 if (isMutedUntil > Date.now()) { const remaining = Math.ceil((isMutedUntil - Date.now()) / 1000); - alert(`您正在禁言中,还有 ${remaining} 秒后解禁。`); + const remainMin = Math.ceil(remaining / 60); + // 在聊天窗口显示持久提示,避免弹窗消失太快 + const muteDiv = document.createElement('div'); + muteDiv.className = 'msg-line'; + muteDiv.innerHTML = + `【提示】您正在禁言中,还需等待约 ${remainMin} 分钟(${remaining} 秒)后方可发言。`; + const container2 = document.getElementById('say2'); + if (container2) { + container2.appendChild(muteDiv); + container2.scrollTop = container2.scrollHeight; + } return; }