From 0623120c00eac318a527189820c6578d8acd1d4a Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 11:06:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=8A=82=E6=97=A5=E7=A6=8F?= =?UTF-8?q?=E5=88=A9=E9=A2=86=E5=8F=96=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 6 +++ resources/js/chat-room/holiday-modal.js | 52 +++++++++++++++++++ .../chat/partials/holiday-modal.blade.php | 34 ++++++------ 3 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 resources/js/chat-room/holiday-modal.js diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 7560a47..0d7ffff 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -34,6 +34,7 @@ export { export { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js"; export { bindGameHallControls } from "./chat-room/game-hall.js"; export { bindGamePanelControls } from "./chat-room/game-panels.js"; +export { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js"; export { bankAction, bankLoadInfo, @@ -108,6 +109,7 @@ import { import { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js"; import { bindGameHallControls } from "./chat-room/game-hall.js"; import { bindGamePanelControls } from "./chat-room/game-panels.js"; +import { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js"; import { bankAction, bankLoadInfo, @@ -185,6 +187,8 @@ if (typeof window !== "undefined") { bindBaccaratLossCoverControls, bindGameHallControls, bindGamePanelControls, + bindHolidayModalControls, + openHolidayRunFromSystemMessage, loadAdminCurrentLossCoverEvent, openAdminBaccaratLossCoverModal, submitBaccaratLossCoverEvent, @@ -246,6 +250,7 @@ if (typeof window !== "undefined") { window.switchMobileTab = switchMobileTab; window.runFeatureShortcut = runFeatureShortcut; window.runToolbarAction = runToolbarAction; + window.openHolidayRunFromSystemMessage = openHolidayRunFromSystemMessage; window.closeAdminBaccaratLossCoverModal = closeAdminBaccaratLossCoverModal; window.closeCurrentBaccaratLossCoverEvent = closeCurrentBaccaratLossCoverEvent; window.openAdminBaccaratLossCoverModal = openAdminBaccaratLossCoverModal; @@ -273,6 +278,7 @@ if (typeof window !== "undefined") { bindBaccaratLossCoverControls(); bindGameHallControls(); bindGamePanelControls(); + bindHolidayModalControls(); bindBankControls(); bindFishingControls(); bindMarriageStatusControls(); diff --git a/resources/js/chat-room/holiday-modal.js b/resources/js/chat-room/holiday-modal.js new file mode 100644 index 0000000..a571ab8 --- /dev/null +++ b/resources/js/chat-room/holiday-modal.js @@ -0,0 +1,52 @@ +// 节日福利弹窗事件代理,承接从 Blade 内联 onclick 迁移出的公屏领取入口。 + +let holidayModalEventsBound = false; + +/** + * 从公屏系统消息中打开已缓存的节日福利批次。 + * + * @param {string|number} runId 福利批次 ID + * @returns {void} + */ +export function openHolidayRunFromSystemMessage(runId) { + const normalizedRunId = String(runId || ""); + const detail = window.__holidayRuns?.[normalizedRunId]; + const modal = document.getElementById("holiday-event-modal"); + + if (!normalizedRunId || !modal || typeof window.Alpine?.$data !== "function") { + return; + } + + if (!detail) { + window.chatDialog?.alert("当前福利批次信息未缓存,请等待下一轮广播或刷新页面后重试。", "提示", "#f59e0b"); + return; + } + + window.Alpine.$data(modal)?.open?.(detail); +} + +/** + * 绑定节日福利公屏按钮点击事件。 + * + * @returns {void} + */ +export function bindHolidayModalControls() { + if (holidayModalEventsBound || typeof document === "undefined") { + return; + } + + holidayModalEventsBound = true; + document.addEventListener("click", (event) => { + if (!(event.target instanceof Element)) { + return; + } + + const claimButton = event.target.closest("[data-holiday-run-id]"); + if (!claimButton) { + return; + } + + event.preventDefault(); + openHolidayRunFromSystemMessage(claimButton.getAttribute("data-holiday-run-id") || ""); + }); +} diff --git a/resources/views/chat/partials/holiday-modal.blade.php b/resources/views/chat/partials/holiday-modal.blade.php index 88e9071..4ccea1d 100644 --- a/resources/views/chat/partials/holiday-modal.blade.php +++ b/resources/views/chat/partials/holiday-modal.blade.php @@ -257,26 +257,20 @@ window.__holidayRuns = window.__holidayRuns || {}; /** - * 从公屏系统消息中打开指定节日福利批次弹窗。 + * 转义按钮属性值,避免福利批次 ID 写入 data 属性时破坏 HTML。 * - * @param {number|string} runId + * @param {number|string} value + * @returns {string} */ - window.openHolidayRunFromSystemMessage = function(runId) { - const normalizedRunId = String(runId); - const detail = window.__holidayRuns?.[normalizedRunId]; - const el = document.getElementById('holiday-event-modal'); - - if (!el || typeof Alpine === 'undefined') { - return; - } - - if (!detail) { - window.chatDialog?.alert('当前福利批次信息未缓存,请等待下一轮广播或刷新页面后重试。', '提示', '#f59e0b'); - return; - } - - Alpine.$data(el).open(detail); - }; + function escapeHolidayAttribute(value) { + return String(value).replace(/[&<>"']/g, (char) => ({ + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + })[char]); + } /** * 构建公屏系统消息里的领取按钮,便于多个消息场景复用一致视觉。 @@ -290,8 +284,10 @@ return ''; } + const safeRunId = escapeHolidayAttribute(runId); + return ` `; }