diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index f52d53b..5f34b4b 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -39,6 +39,7 @@ export { } from "./chat-room/baccarat-loss-cover-admin.js"; export { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js"; export { bindGameHallControls } from "./chat-room/game-hall.js"; +export { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js"; export { bindGamePanelControls } from "./chat-room/game-panels.js"; export { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js"; export { @@ -121,6 +122,7 @@ import { } from "./chat-room/baccarat-loss-cover-admin.js"; import { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js"; import { bindGameHallControls } from "./chat-room/game-hall.js"; +import { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js"; import { bindGamePanelControls } from "./chat-room/game-panels.js"; import { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js"; import { @@ -214,6 +216,8 @@ if (typeof window !== "undefined") { closeCurrentBaccaratLossCoverEvent, bindBaccaratLossCoverControls, bindGameHallControls, + bindGameBootstrapControls, + deferChatGameBootstrap, bindGamePanelControls, bindHolidayModalControls, openHolidayRunFromSystemMessage, @@ -298,6 +302,7 @@ if (typeof window !== "undefined") { window.bankShowMsg = bankShowMsg; window.closeBankModal = closeBankModal; window.fetchBankRanking = fetchBankRanking; + window.deferChatGameBootstrap = deferChatGameBootstrap; window.openBankModal = openBankModal; window.switchBankTab = switchBankTab; window.toggleBankRankSort = toggleBankRankSort; @@ -321,6 +326,7 @@ if (typeof window !== "undefined") { bindBaccaratLossCoverAdminControls(); bindBaccaratLossCoverControls(); bindGameHallControls(); + bindGameBootstrapControls(); bindGamePanelControls(); bindHolidayModalControls(); bindBankControls(); diff --git a/resources/js/chat-room/game-bootstrap.js b/resources/js/chat-room/game-bootstrap.js new file mode 100644 index 0000000..0d8a92a --- /dev/null +++ b/resources/js/chat-room/game-bootstrap.js @@ -0,0 +1,34 @@ +// 聊天室游戏延迟初始化工具,避免非关键游戏逻辑抢占首屏渲染资源。 + +/** + * 延迟执行非关键游戏初始化。 + * + * @param {Function} callback + * @param {number} [timeout] + * @returns {void} + */ +export function deferChatGameBootstrap(callback, timeout = 2500) { + if (typeof callback !== "function") { + return; + } + + if ("requestIdleCallback" in window) { + window.requestIdleCallback(callback, { timeout }); + return; + } + + window.setTimeout(callback, Math.min(timeout, 1200)); +} + +/** + * 暴露游戏延迟初始化入口给存量游戏面板脚本。 + * + * @returns {void} + */ +export function bindGameBootstrapControls() { + if (typeof window === "undefined") { + return; + } + + window.deferChatGameBootstrap = deferChatGameBootstrap; +} diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index dc605cb..b3c0b5a 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -214,26 +214,7 @@ @include('chat.partials.daily-sign-in-modal') {{-- ═══════════ 游戏面板(partials/games/ 子目录,各自独立,包含 CSS + HTML + JS) ═══════════ --}} - + {{-- deferChatGameBootstrap 已迁移到 resources/js/chat-room/game-bootstrap.js --}} @include('chat.partials.games.baccarat-panel') @include('chat.partials.games.slot-machine') @include('chat.partials.games.mystery-box')