From abb551222241d36b0503436382bb253543c951fe Mon Sep 17 00:00:00 2001 From: pllx Date: Tue, 28 Apr 2026 14:40:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=AC=A2=E8=BF=8E=E8=AF=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=B3=E4=B8=8B=E8=A7=92=E5=BC=B9=E7=AA=97=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=EF=BC=9B=E7=A6=81=E6=AD=A2=E5=AF=B9=E3=80=8C=E5=A4=A7?= =?UTF-8?q?=E5=AE=B6=E3=80=8D=E5=8F=91=E9=80=81=E6=AC=A2=E8=BF=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 11 +++++++++++ resources/js/chat-room/chat-events.js | 4 ++-- resources/views/chat/partials/scripts.blade.php | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 63f015c..647116d 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -449,6 +449,17 @@ class ChatController extends Controller $messageData = array_merge($messageData, $imagePayload); } + // 欢迎动作:增加右下角弹窗通知(内容含发送者信息) + if (($data['action'] ?? '') === '欢迎') { + $messageData['toast_notification'] = [ + 'title' => '👋 欢迎', + 'message' => strip_tags($pureContent), + 'icon' => '👋', + 'color' => '#e11d48', + 'duration' => 8000, + ]; + } + // 6.5 将用户当前激活的消息装扮注入广播 payload(气泡样式 + 昵称颜色),前端据此渲染消息外观 $decorations = app(\App\Services\DecorationService::class)->getDecorationsForMessage($user); $messageData = array_merge($messageData, $decorations); diff --git a/resources/js/chat-room/chat-events.js b/resources/js/chat-room/chat-events.js index 73644df..9088835 100644 --- a/resources/js/chat-room/chat-events.js +++ b/resources/js/chat-room/chat-events.js @@ -370,8 +370,8 @@ export function bindChatEvents() { window.showVipPresenceBanner(msg); } - // 若消息携带 toast_notification 字段且当前用户是接收者或为公屏广播,弹右下角小卡片 - if (msg.toast_notification && (msg.to_user === window.chatContext?.username || msg.to_user === '大家')) { + // 若消息携带 toast_notification 字段且当前用户是接收者或为公屏广播或为欢迎动作,弹右下角小卡片 + if (msg.toast_notification && (msg.to_user === window.chatContext?.username || msg.to_user === '大家' || msg.action === '欢迎')) { const t = msg.toast_notification; window.chatToast?.show({ title: t.title || "通知", diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index a6e6164..2ddde11 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -111,7 +111,11 @@ */ function sendWelcomeTpl(tpl) { const toUser = document.getElementById('to_user')?.value || '大家'; - const name = toUser === '大家' ? '大家' : toUser; + if (toUser === '大家') { + window.chatDialog?.alert('欢迎语不能对「大家」发送,请先选择具体用户。', '🚫 提示', '#cc4444'); + return; + } + const name = toUser; const prefix = window.chatContext?.welcomePrefix || window.chatContext?.username || ''; const body = tpl.replace(/\{name\}/g, name); const msg = `${prefix}:${body}`;