优化 游戏金币余额显示

This commit is contained in:
2026-04-12 22:31:35 +08:00
parent ef407a8c6e
commit c297b61493
6 changed files with 51 additions and 6 deletions
@@ -483,6 +483,16 @@
autoCloseTimer: null,
autoCloseCountdown: 0,
/**
* 同步全局聊天上下文中的金币余额,供弹窗右上角与其他面板共用。
*/
syncUserGold(jjb) {
if (jjb === undefined || jjb === null) return;
if (!window.chatContext) return;
window.chatContext.userJjb = Number(jjb);
window.chatContext.myGold = Number(jjb);
},
/**
* 获取快捷下注金额数组
*/
@@ -594,6 +604,8 @@
try {
const res = await fetch('/baccarat/current');
const data = await res.json();
// 每次打开或刷新局次信息时,都用服务端最新金币覆盖右上角余额。
this.syncUserGold(data.jjb);
if (data.round && (data.round.seconds_left || 0) > 0) {
this.phase = 'betting';
this.roundId = data.round.id;
@@ -807,6 +819,9 @@
// 再检查是否有正在进行的局
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;
@@ -419,6 +419,16 @@
// 历史记录
history: [],
/**
* 同步全局聊天上下文中的金币余额,供弹窗右上角与其他面板共用。
*/
syncUserGold(jjb) {
if (jjb === undefined || jjb === null) return;
if (!window.chatContext) return;
window.chatContext.userJjb = Number(jjb);
window.chatContext.myGold = Number(jjb);
},
/**
* 获取当前选中马匹的预览名称(用于按钮文字)
*/
@@ -502,6 +512,8 @@
try {
const res = await fetch('/horse-race/current');
const data = await res.json();
// 每次打开或刷新当前场次时,都先同步右上角金币余额。
this.syncUserGold(data.jjb);
if (data.race) {
this.horses = data.race.horses || this.horses;
this.totalPool = data.race.total_pool || 0;
@@ -674,6 +686,7 @@
try {
const res = await fetch('/horse-race/current');
const data = await res.json();
this.syncUserGold(data.jjb);
if (data.race) {
const race = data.race;
this.raceId = race.id;
@@ -763,6 +776,9 @@
const curRes = await fetch('/horse-race/current');
const curData = await curRes.json();
if (panel) {
Alpine.$data(panel).syncUserGold(curData.jjb);
}
// 游戏可访问则常驻显示 FAB(与占卜一致)
if (fab) Alpine.$data(fab).visible = true;