优化 游戏金币余额显示

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
@@ -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;