优化:禁言提示显示操作者 + 被禁言发言改用持久提示
- UserMuted 事件增加 operator 字段,禁言通知显示管理员名字 - 输入框 placeholder 显示操作者名字 - 被禁言用户发言时改为在包厢窗口显示红色持久提示(替代 alert 弹窗)
This commit is contained in:
@@ -32,6 +32,7 @@ class UserMuted implements ShouldBroadcast
|
|||||||
public readonly string $username,
|
public readonly string $username,
|
||||||
public readonly int $muteTime,
|
public readonly int $muteTime,
|
||||||
public readonly string $message = '',
|
public readonly string $message = '',
|
||||||
|
public readonly string $operator = '',
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,12 +55,13 @@ class UserMuted implements ShouldBroadcast
|
|||||||
public function broadcastWith(): array
|
public function broadcastWith(): array
|
||||||
{
|
{
|
||||||
$statusMessage = $this->message ?: ($this->muteTime > 0
|
$statusMessage = $this->message ?: ($this->muteTime > 0
|
||||||
? "用户 [{$this->username}] 已被禁言 {$this->muteTime} 分钟。"
|
? "管理员 [{$this->operator}] 已将 [{$this->username}] 禁言 {$this->muteTime} 分钟。"
|
||||||
: "用户 [{$this->username}] 已被解除禁言。");
|
: "用户 [{$this->username}] 已被解除禁言。");
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'username' => $this->username,
|
'username' => $this->username,
|
||||||
'mute_time' => $this->muteTime,
|
'mute_time' => $this->muteTime,
|
||||||
|
'operator' => $this->operator,
|
||||||
'message' => $statusMessage,
|
'message' => $statusMessage,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,12 @@ class AdminCommandController extends Controller
|
|||||||
SaveMessageJob::dispatch($msg);
|
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} 分钟"]);
|
return response()->json(['status' => 'success', 'message' => "已禁言 {$targetUsername} {$duration} 分钟"]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -474,8 +474,9 @@
|
|||||||
if (d.username === window.chatContext.username && d.mute_time > 0) {
|
if (d.username === window.chatContext.username && d.mute_time > 0) {
|
||||||
isMutedUntil = Date.now() + d.mute_time * 60 * 1000;
|
isMutedUntil = Date.now() + d.mute_time * 60 * 1000;
|
||||||
const contentInput = document.getElementById('content');
|
const contentInput = document.getElementById('content');
|
||||||
|
const operatorName = d.operator || '管理员';
|
||||||
if (contentInput) {
|
if (contentInput) {
|
||||||
contentInput.placeholder = `您已被禁言 ${d.mute_time} 分钟,解禁后方可发言...`;
|
contentInput.placeholder = `${operatorName} 已将您禁言 ${d.mute_time} 分钟,解禁后方可发言...`;
|
||||||
contentInput.disabled = true;
|
contentInput.disabled = true;
|
||||||
// 到期自动恢复
|
// 到期自动恢复
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -549,7 +550,17 @@
|
|||||||
// 前端禁言检查
|
// 前端禁言检查
|
||||||
if (isMutedUntil > Date.now()) {
|
if (isMutedUntil > Date.now()) {
|
||||||
const remaining = Math.ceil((isMutedUntil - Date.now()) / 1000);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user