百家乐修复:①页面加载时检查进行中的局并显示FAB ②FAB点击同时恢复倒计时 ③解决刷新页面/错过WebSocket而看不到下注入口的问题
This commit is contained in:
@@ -241,13 +241,20 @@
|
||||
{{-- ─── 骰子悬浮入口(游戏开启时常驻) ─── --}}
|
||||
<div id="baccarat-fab" x-data="{ visible: false }" x-show="visible" x-cloak
|
||||
style="position:fixed; bottom:90px; right:18px; z-index:9900;">
|
||||
<button x-on:click="document.getElementById('baccarat-panel')._x_dataStack[0].show = true"
|
||||
<button
|
||||
x-on:click="() => {
|
||||
const p = Alpine.$data(document.getElementById('baccarat-panel'));
|
||||
p.show = true;
|
||||
if (p.phase === 'betting' && p.countdown > 0 && !p.countdownTimer) {
|
||||
p.startCountdown();
|
||||
}
|
||||
}"
|
||||
style="width:52px; height:52px; border-radius:50%; border:none; cursor:pointer;
|
||||
background:linear-gradient(135deg,#7c3aed,#4f46e5);
|
||||
box-shadow:0 4px 20px rgba(124,58,237,.5);
|
||||
font-size:22px; display:flex; align-items:center; justify-content:center;
|
||||
animation:pulse-fab 2s infinite;"
|
||||
title="百家乐">🎲</button>
|
||||
title="百家乐下注中">🎲</button>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -502,13 +509,48 @@
|
||||
if (panel) Alpine.$data(panel).showResult(e.detail);
|
||||
});
|
||||
|
||||
/** 页面加载时初始化历史记录 */
|
||||
/** 页面加载时:检查是否有进行中的局,有则自动恢复面板 */
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
try {
|
||||
const res = await fetch('/baccarat/history');
|
||||
const data = await res.json();
|
||||
// 先加载历史趋势
|
||||
const histRes = await fetch('/baccarat/history');
|
||||
const histData = await histRes.json();
|
||||
const panel = document.getElementById('baccarat-panel');
|
||||
if (panel) Alpine.$data(panel).history = (data.history || []).reverse();
|
||||
} catch {}
|
||||
if (panel) {
|
||||
Alpine.$data(panel).history = (histData.history || []).reverse();
|
||||
}
|
||||
|
||||
// 再检查是否有正在进行的局
|
||||
const curRes = await fetch('/baccarat/current');
|
||||
const curData = await curRes.json();
|
||||
|
||||
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;
|
||||
|
||||
if (round.my_bet) {
|
||||
panelData.myBet = true;
|
||||
panelData.myBetType = round.my_bet.bet_type;
|
||||
panelData.myBetAmount = round.my_bet.amount;
|
||||
}
|
||||
|
||||
// 只显示悬浮按钮,不自动弹出全屏(避免打扰刚进入的用户)
|
||||
panelData.updateFab(true);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[百家乐] 初始化失败', e);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user