From 48d646d723ac215bb8a9d48f231f066eb8c84272 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 18:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E4=BA=94=E5=AD=90=E6=A3=8B?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E5=85=A5=E5=8F=A3=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 9 ++++ resources/js/chat-room/gomoku-controls.js | 49 +++++++++++++++++++ .../partials/games/gomoku-panel.blade.php | 12 +---- 3 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 resources/js/chat-room/gomoku-controls.js diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index d9c45f6..ab2f424 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -29,6 +29,7 @@ * - game-hall.js:处理娱乐大厅弹窗和游戏入口卡片。 * - game-bootstrap.js:提供非关键游戏延迟初始化工具。 * - game-panels.js:处理通用游戏面板关闭事件。 + * - gomoku-controls.js:处理五子棋外部打开和接受邀请入口。 * - horse-race-fab.js:处理赛马竞猜悬浮按钮拖动与打开面板。 * - holiday-modal.js:处理节日福利弹窗、广播监听、领取状态和系统消息入口。 * - initial-state.js:恢复首屏历史消息、欢迎消息、入场特效和挂起婚姻事件。 @@ -107,6 +108,7 @@ export { export { bindGameHallControls, closeGameHall, openGameHall } from "./chat-room/game-hall.js"; export { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js"; export { bindGamePanelControls } from "./chat-room/game-panels.js"; +export { acceptGomokuInvite, bindGomokuControls, openGomokuPanel } from "./chat-room/gomoku-controls.js"; export { bindHorseRaceFabControls, horseRaceFab } from "./chat-room/horse-race-fab.js"; export { bindHolidayModalControls, @@ -252,6 +254,7 @@ import { import { bindGameHallControls, closeGameHall, openGameHall } from "./chat-room/game-hall.js"; import { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js"; import { bindGamePanelControls } from "./chat-room/game-panels.js"; +import { acceptGomokuInvite, bindGomokuControls, openGomokuPanel } from "./chat-room/gomoku-controls.js"; import { bindHorseRaceFabControls, horseRaceFab } from "./chat-room/horse-race-fab.js"; import { bindHolidayModalControls, @@ -404,6 +407,9 @@ if (typeof window !== "undefined") { bindGameBootstrapControls, deferChatGameBootstrap, bindGamePanelControls, + acceptGomokuInvite, + bindGomokuControls, + openGomokuPanel, bindHorseRaceFabControls, horseRaceFab, bindHolidayModalControls, @@ -564,6 +570,8 @@ if (typeof window !== "undefined") { window.deferChatGameBootstrap = deferChatGameBootstrap; window.lotteryPanel = lotteryPanel; window.openGameHall = openGameHall; + window.acceptGomokuInvite = acceptGomokuInvite; + window.openGomokuPanel = openGomokuPanel; window.horseRaceFab = horseRaceFab; window.openLotteryPanel = openLotteryPanel; window.openBankModal = openBankModal; @@ -644,6 +652,7 @@ if (typeof window !== "undefined") { bindGameHallControls(); bindGameBootstrapControls(); bindGamePanelControls(); + bindGomokuControls(); bindHorseRaceFabControls(); bindHolidayModalControls(); bindChatInitialStateControls(); diff --git a/resources/js/chat-room/gomoku-controls.js b/resources/js/chat-room/gomoku-controls.js new file mode 100644 index 0000000..f37fcc0 --- /dev/null +++ b/resources/js/chat-room/gomoku-controls.js @@ -0,0 +1,49 @@ +// 五子棋外部入口控制,负责从工具栏或邀请消息打开棋盘。 + +/** + * 读取五子棋面板 Alpine 状态。 + * + * @returns {Record|null} + */ +function getGomokuPanelState() { + const panel = document.getElementById("gomoku-panel"); + + if (!panel || typeof window.Alpine?.$data !== "function") { + return null; + } + + return window.Alpine.$data(panel); +} + +/** + * 从外部打开五子棋面板。 + * + * @returns {void} + */ +export function openGomokuPanel() { + getGomokuPanelState()?.open(); +} + +/** + * 接受 PvP 邀请并打开棋盘。 + * + * @param {number|string} gameId 对局 ID + * @returns {void} + */ +export function acceptGomokuInvite(gameId) { + getGomokuPanelState()?.openAndJoin(gameId); +} + +/** + * 挂载五子棋全局入口,兼容广播监听和存量 Blade 调用。 + * + * @returns {void} + */ +export function bindGomokuControls() { + if (typeof window === "undefined") { + return; + } + + window.openGomokuPanel = openGomokuPanel; + window.acceptGomokuInvite = acceptGomokuInvite; +} diff --git a/resources/views/chat/partials/games/gomoku-panel.blade.php b/resources/views/chat/partials/games/gomoku-panel.blade.php index 3966ac2..691db3a 100644 --- a/resources/views/chat/partials/games/gomoku-panel.blade.php +++ b/resources/views/chat/partials/games/gomoku-panel.blade.php @@ -938,15 +938,5 @@ }; } - /** 从外部打开五子棋面板 */ - window.openGomokuPanel = function() { - const panel = document.getElementById('gomoku-panel'); - if (panel) Alpine.$data(panel).open(); - }; - - /** 接受 PvP 邀请并打开棋盘 */ - window.acceptGomokuInvite = function(gameId) { - const panel = document.getElementById('gomoku-panel'); - if (panel) Alpine.$data(panel).openAndJoin(gameId); - }; + {{-- 五子棋外部打开入口已迁移到 resources/js/chat-room/gomoku-controls.js --}}