开始滚动前获取余额时,如果网络错误,添加错误后的处理
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m3s

This commit is contained in:
TJH 2026-06-25 16:40:41 +08:00
parent 10562f980c
commit deaaf21e3c
4 changed files with 42 additions and 19 deletions

View File

@ -427,25 +427,25 @@ export class SlotBar extends Component {
if (this.isGetBalance) return if (this.isGetBalance) return
this.isGetBalance = true; this.isGetBalance = true;
try { try {
let balacneData = await callGameBalanceApi({ GameId: getGameId() }); let balacneData = await this.refreshBalanceFromServer();
this.setBalance(balacneData.Balance) this.setBalance(balacneData)
return balacneData.Balance; return balacneData;
} catch (err) { } catch (err) {
console.log('获取余额失败') console.log('获取余额失败')
return null; return null;
} finally { } finally {
this.scheduleOnce(() => { this.scheduleOnce(() => {
this.isGetBalance = false; this.isGetBalance = false;
}, 1) }, 0.5)
} }
} }
async onConfirmErr2(): Promise<number | null> { async onConfirmErr2(): Promise<number | null> {
try { try {
let balacneData = await callGameBalanceApi({ GameId: getGameId() }); let balacneData = await this.refreshBalanceFromServer();
this.setBalance(balacneData.Balance) this.setBalance(balacneData)
return balacneData.Balance; return balacneData;
} catch (err) { } catch (err) {
console.log('获取余额失败') console.log('获取余额失败')
return null; return null;
@ -834,4 +834,28 @@ export class SlotBar extends Component {
this.setBet(this.betGrade[this.betIndex], true); this.setBet(this.betGrade[this.betIndex], true);
} }
} }
// private _refreshingBalance: boolean = false;
async refreshBalanceFromServer(): Promise<number | null> {
// if (this._refreshingBalance) return this.getBalance();
// this._refreshingBalance = true;
try {
const res = await callGameBalanceApi({});
const balance = Number(res.Balance);
if (!Number.isFinite(balance)) {
console.warn("[SlotBar] invalid balance response:", res);
return this.getBalance();
}
this.setBalance(balance);
return balance;
} catch (err) {
console.error("[SlotBar] refresh balance failed:", err);
return this.getBalance();
} finally {
// this.scheduleOnce(() => {
// this._refreshingBalance = false;
// }, 1)
}
}
} }

View File

@ -298,12 +298,11 @@ export class SlotScene extends Component {
if (!isFreeSpin) { if (!isFreeSpin) {
this.slotBar.setWin(0); this.slotBar.setWin(0);
} }
let curBalanceData = await callGameBalanceApi({ GameId: getGameId() }) let curBalanceData = await this.slotBar.refreshBalanceFromServer()
let curBalance = curBalanceData.Balance if (!curBalanceData) {
if (!curBalance) { curBalanceData = this.slotBar.getBalance()
curBalance = this.slotBar.getBalance()
} }
if (curBalance < (isFeatureBuy ? this.slotBar.getBet() * this.gameInfo.BuyMul : this.slotBar.getBet()) && !isFreeSpin && !GameDataManager.instance.frb.Ongoing) { if (curBalanceData < (isFeatureBuy ? this.slotBar.getBet() * this.gameInfo.BuyMul : this.slotBar.getBet()) && !isFreeSpin && !GameDataManager.instance.frb.Ongoing) {
//余额不足不经过服务器,在客户端拦截 //余额不足不经过服务器,在客户端拦截
this.showErrorTip(2, () => { this.slotBar.onConfirmErr2() }); this.showErrorTip(2, () => { this.slotBar.onConfirmErr2() });
this.handleErrSpin(true); this.handleErrSpin(true);

View File

@ -105,7 +105,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 540, "x": 540,
"y": 959.9999999999999, "y": 960,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@ -190,7 +190,7 @@
"_priority": 0, "_priority": 0,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 959.9999999999999, "_orthoHeight": 960,
"_near": 0, "_near": 0,
"_far": 2000, "_far": 2000,
"_color": { "_color": {
@ -2342,7 +2342,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 1080, "width": 1080,
"height": 1919.9999999999998 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -2442,7 +2442,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 1080, "width": 1080,
"height": 1919.9999999999998 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -2494,7 +2494,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 1080, "width": 1080,
"height": 1919.9999999999998 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -3070,7 +3070,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 1080, "width": 1080,
"height": 1919.9999999999998 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",

View File

@ -7,7 +7,7 @@ import { PREVIEW } from "cc/env"
const gameId = "rp_11001"; const gameId = "rp_11001";
// let apiaddr = "https://rpgames-api.rpfafafahkdev.com"; // let apiaddr = "https://rpgames-api.rpfafafahkdev.com";
let apiaddr = ""; let apiaddr = "";
let token = "eyJQIjoxMDA5NDksIkUiOjE3ODExODU1MzgsIlMiOjEwMDIsIkQiOiJycF8xMTAwMSJ9.MEuOw7xQRgnH1-0hQFXTspVZbXMEsvPBF2BbUFq3wBg"; let token = "eyJQIjoxMDA5NDksIkUiOjE3ODI0MTk0MzcsIlMiOjEwMDEsIkQiOiJycF8xMTAwMSJ9.vtoxQYfRPLeEqzcOqkCE7UIVn6G8xFejT34eR6pixR8";
let language = "en" let language = "en"
let currency = "THB" let currency = "THB"