迁移游戏延迟初始化脚本

This commit is contained in:
2026-04-25 14:03:15 +08:00
parent a766f2a9c5
commit 43d613bfb1
3 changed files with 41 additions and 20 deletions
+6
View File
@@ -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();
+34
View File
@@ -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;
}
+1 -20
View File
@@ -214,26 +214,7 @@
@include('chat.partials.daily-sign-in-modal')
{{-- ═══════════ 游戏面板(partials/games/ 子目录,各自独立,包含 CSS + HTML + JS ═══════════ --}}
<script>
/**
* 延迟执行非关键游戏初始化,避免首屏聊天室渲染时同时抢占网络和主线程。
*
* @param {Function} callback 初始化回调
* @param {number} timeout 最长等待时间
*/
window.deferChatGameBootstrap = function(callback, timeout = 2500) {
if (typeof callback !== 'function') {
return;
}
if ('requestIdleCallback' in window) {
window.requestIdleCallback(callback, { timeout });
return;
}
window.setTimeout(callback, Math.min(timeout, 1200));
};
</script>
{{-- 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')