迁移百家乐事件脚本

This commit is contained in:
2026-04-25 18:18:41 +08:00
parent 63f6dc7106
commit a5c43383e1
3 changed files with 135 additions and 83 deletions
@@ -716,87 +716,5 @@
};
}
// ─── WebSocket 监听 ──────────────────────────────────────────────
/** 收到开局事件:弹出押注面板 */
window.addEventListener('chat:baccarat.opened', (e) => {
const panel = document.getElementById('baccarat-panel');
if (panel) Alpine.$data(panel).openRound(e.detail);
});
/** 收到结算事件:展示骰子动画和结果 */
window.addEventListener('chat:baccarat.settled', (e) => {
const panel = document.getElementById('baccarat-panel');
if (panel) Alpine.$data(panel).showResult(e.detail);
});
/** 收到下注池更新:更新押注人数 */
window.addEventListener('chat:baccarat.pool_updated', (e) => {
const panel = document.getElementById('baccarat-panel');
if (panel) {
const pd = Alpine.$data(panel);
const data = e.detail;
// 判断 round_id 是否一致
if (pd.roundId === data.round_id) {
pd.betCountBig = data.bet_count_big;
pd.betCountSmall = data.bet_count_small;
pd.betCountTriple = data.bet_count_triple;
}
}
});
/** 页面空闲时:检查是否有进行中的局,有则自动恢复面板 */
document.addEventListener('DOMContentLoaded', () => window.deferChatGameBootstrap(async () => {
try {
// 先加载历史趋势
const histRes = await fetch('/baccarat/history');
const histData = await histRes.json();
const panel = document.getElementById('baccarat-panel');
if (panel) {
Alpine.$data(panel).history = (histData.history || []).reverse();
}
// 再检查是否有正在进行的局
const curRes = await fetch('/baccarat/current');
const curData = await curRes.json();
if (panel) {
Alpine.$data(panel).syncUserGold(curData.jjb);
}
if (curData.round && panel) {
const round = curData.round;
const seconds = round.seconds_left || 0;
const panelData = Alpine.$data(panel);
if (seconds > 0) {
// 有进行中的局且还在押注时间内 → 恢复押注面板
panelData.phase = 'betting';
panelData.roundId = round.id;
panelData.totalSeconds = 60; // 服务端配置的窗口
panelData.countdown = seconds;
panelData.totalBetBig = round.total_bet_big;
panelData.totalBetSmall = round.total_bet_small;
panelData.totalBetTriple = round.total_bet_triple;
panelData.betCountBig = round.bet_count_big;
panelData.betCountSmall = round.bet_count_small;
panelData.betCountTriple = round.bet_count_triple;
if (round.my_bet) {
panelData.myBet = true;
panelData.myBetType = round.my_bet.bet_type;
panelData.myBetAmount = round.my_bet.amount;
}
// 只显示悬浮按钮,不自动弹出全屏(避免打扰刚进入的用户)
panelData.updateFab(true);
} else {
panelData.setIdleState();
}
} else if (panel) {
Alpine.$data(panel).setIdleState();
}
} catch (e) {
console.warn('[百家乐] 初始化失败', e);
}
}));
{{-- 乐彩百家乐广播监听和页面恢复逻辑已迁移到 resources/js/chat-room/baccarat-events.js --}}
</script>