From 645fe2a8303a0ac5c9c5a5af72487cdca01a3edf Mon Sep 17 00:00:00 2001 From: pllx Date: Tue, 5 May 2026 21:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=8B=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E9=80=9A=E7=9F=A5=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/GameBetBroadcastService.php | 3 ++ resources/js/chat-room/chat-events.js | 32 +++++++++++++++++++ resources/js/chat-room/toast.js | 13 -------- .../partials/toast-notification.blade.php | 11 ++++++- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/app/Services/GameBetBroadcastService.php b/app/Services/GameBetBroadcastService.php index c839988..6c01d91 100644 --- a/app/Services/GameBetBroadcastService.php +++ b/app/Services/GameBetBroadcastService.php @@ -36,6 +36,7 @@ class GameBetBroadcastService toastMessage: "{$username} 押注 {$formattedAmount} 金币({$betLabel})", toastIcon: '🎲', toastColor: '#d97706', + toastActorUsername: $username, ); } @@ -54,6 +55,7 @@ class GameBetBroadcastService toastMessage: "{$username} 押注 {$formattedAmount} 金币({$horseName})", toastIcon: '🐎', toastColor: '#d97706', + toastActorUsername: $username, ); } @@ -73,6 +75,7 @@ class GameBetBroadcastService toastIcon: '🎟️', toastColor: '#dc2626', action: '大声宣告', + toastActorUsername: $username, ); } diff --git a/resources/js/chat-room/chat-events.js b/resources/js/chat-room/chat-events.js index 90d449b..f41ea31 100644 --- a/resources/js/chat-room/chat-events.js +++ b/resources/js/chat-room/chat-events.js @@ -84,6 +84,34 @@ function shouldSkipToastForCurrentUser(toastNotification) { return String(toastNotification.actor_username || "") === String(window.chatContext?.username || ""); } +/** + * 判断当前是否为手机浏览器视口。 + * + * @returns {boolean} + */ +function isMobileToastViewport() { + return window.matchMedia?.("(max-width: 640px)")?.matches === true; +} + +/** + * 手机端只隐藏无本人关联的公屏全局 Toast。 + * + * @param {Record} message 聊天消息载荷 + * @param {Record} toastNotification 右下角通知载荷 + * @returns {boolean} + */ +function shouldHideGlobalToastOnMobile(message, toastNotification) { + if (!isMobileToastViewport() || message?.to_user !== '大家') { + return false; + } + + const currentUsername = String(window.chatContext?.username || ""); + const actorUsername = String(toastNotification?.actor_username || ""); + const targetUsername = String(toastNotification?.target_username || ""); + + return actorUsername !== currentUsername && targetUsername !== currentUsername; +} + // ── 禁言逻辑 ── function handleMutedEvent(e) { const state = getState(); @@ -435,6 +463,10 @@ export function bindChatEvents() { return; } + if (shouldHideGlobalToastOnMobile(msg, t)) { + return; + } + window.chatToast?.show({ title: t.title || "通知", message: t.message || "", diff --git a/resources/js/chat-room/toast.js b/resources/js/chat-room/toast.js index 843b145..29492e0 100644 --- a/resources/js/chat-room/toast.js +++ b/resources/js/chat-room/toast.js @@ -16,15 +16,6 @@ function dismissToast(card) { window.setTimeout(() => card.remove(), 400); } -/** - * 判断当前是否应在手机视口隐藏 Toast。 - * - * @returns {boolean} - */ -function shouldHideToastOnMobile() { - return window.matchMedia?.("(max-width: 640px)")?.matches === true; -} - /** * 关闭容器内所有 Toast 卡片。 * @@ -92,10 +83,6 @@ function createChatToast(container) { duration = 6000, action = null, }) { - if (shouldHideToastOnMobile()) { - return; - } - const card = document.createElement("div"); card.className = "chat-toast-card"; card.style.cssText = ` diff --git a/resources/views/chat/partials/toast-notification.blade.php b/resources/views/chat/partials/toast-notification.blade.php index fdffde1..24af252 100644 --- a/resources/views/chat/partials/toast-notification.blade.php +++ b/resources/views/chat/partials/toast-notification.blade.php @@ -40,7 +40,16 @@ @media (max-width: 640px) { #chat-toast-container { - display: none !important; + right: 12px !important; + bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important; + left: 12px !important; + align-items: stretch; + } + + #chat-toast-container .chat-toast-card { + width: 100% !important; + min-width: 0 !important; + max-width: none !important; } }