优化:禁言提示显示操作者 + 被禁言发言改用持久提示

- UserMuted 事件增加 operator 字段,禁言通知显示管理员名字
- 输入框 placeholder 显示操作者名字
- 被禁言用户发言时改为在包厢窗口显示红色持久提示(替代 alert 弹窗)
This commit is contained in:
2026-02-26 23:12:55 +08:00
parent 66f68bab85
commit 2d45e52591
3 changed files with 22 additions and 4 deletions

View File

@@ -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,
];
}

View File

@@ -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} 分钟"]);
}

View File

@@ -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 =
`<span style="color: #dc2626; font-weight: bold;">【提示】您正在禁言中,还需等待约 ${remainMin} 分钟(${remaining} 秒)后方可发言。</span>`;
const container2 = document.getElementById('say2');
if (container2) {
container2.appendChild(muteDiv);
container2.scrollTop = container2.scrollHeight;
}
return;
}