From 90293f86ae7d2e7e50f7f91f756c20a0e413f432 Mon Sep 17 00:00:00 2001 From: "COMPUTER\\EDY" <249929363@qq.com> Date: Tue, 11 Nov 2025 10:43:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/JiaZai.ts | 50 +++++++++++++++++++++++ assets/Script/module/Config/GameConfig.ts | 12 ++++++ assets/Script/module/Pay/Utils.ts | 41 +++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index b7a4ca8..23d4e38 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -2207,6 +2207,56 @@ export default class JiaZai extends cc.Component { console.log("关闭过时数据", cc.fx.GameConfig.GM_INFO.getItemType) this.checkAndSetPlayerPassLevel(); } + + //获取入职排行榜 + getSRank() { + Utils.getSRank(res => { + let data = JSON.parse(res.data); + let role = data.role; + let sortedArray = []; + sortedArray = Object.entries(role) + //@ts-ignore + .sort((a, b) => b[1] - a[1]) // 按数值从大到小排序 + .map((item, index) => ({ + rank: index + 1, // 排名 + name: item[0], // 省份名称 + count: item[1] // 数值 + })); + // 排序后的结果 + + let city = JSON.parse(JSON.stringify(cc.fx.GameConfig.CITY)); + let rankData = []; + for (let i = 0; i < sortedArray.length; i++) { + // 检查sortedArray中的省份名称是否存在于原始data.role数据中 + if (data && data[sortedArray[i].name] !== undefined) { + // 如果存在,则将data中对应的键值对放入rankData + if (data.role && data.role[sortedArray[i].name] !== undefined) { + rankData.push({ + rank: sortedArray[i].rank, + name: sortedArray[i].name, + count: sortedArray[i].count, + // 可以添加data2中对应的数据 + rankingData: data[sortedArray[i].name] + }); + delete city[sortedArray[i].name]; + } + } + } + // 循环完成后,将CITY中剩下的城市按顺序添加到rankData中 + let nextRank = rankData.length + 1; // 获取下一个排名 + for (let cityName in city) { + rankData.push({ + rank: nextRank++, + name: cityName, + count: 0, + rankingData: [] + }); + } + console.log(rankData); + + }); + } + update(dt) { if (this.newbieGift && this.monthlyCardNode) { if (this.monthlyCardNode.active == true) { diff --git a/assets/Script/module/Config/GameConfig.ts b/assets/Script/module/Config/GameConfig.ts index 84c610b..538ebd1 100644 --- a/assets/Script/module/Config/GameConfig.ts +++ b/assets/Script/module/Config/GameConfig.ts @@ -138,6 +138,7 @@ export class GameConfig { }; + static CITY: { 河北省: boolean; 山西省: boolean; 辽宁省: boolean; 吉林省: boolean; 黑龙江省: boolean; 江苏省: boolean; 浙江省: boolean; 安徽省: boolean; 福建省: boolean; 江西省: boolean; 山东省: boolean; 河南省: boolean; 湖北省: boolean; 湖南省: boolean; 广东省: boolean; 海南省: boolean; 四川省: boolean; 贵州省: boolean; 云南省: boolean; 陕西省: boolean; 甘肃省: boolean; 青海省: boolean; 港澳台: boolean; 北京: boolean; 天津: boolean; 上海: boolean; 重庆: boolean; 内蒙古: boolean; 广西: boolean; 西藏: boolean; 宁夏: boolean; 新疆: boolean; }; @@ -161,6 +162,7 @@ export class GameConfig { this.TA = null; this.CLICK_init(); this.GM_INFO_init(); + this.CITY_init(); this.LEVEL_INFO_init(false, 0, false); var self = this; @@ -605,5 +607,15 @@ export class GameConfig { static Authentication() { cc.fx.GameTool.Authentication(); } + + static CITY_init() { + this.CITY = { + "河北省": true, "山西省": true, "辽宁省": true, "吉林省": true, "黑龙江省": true, "江苏省": true, + "浙江省": true, "安徽省": true, "福建省": true, "江西省": true, "山东省": true, "河南省": true, "湖北省": true, + "湖南省": true, "广东省": true, "海南省": true, "四川省": true, "贵州省": true, "云南省": true, "陕西省": true, + "甘肃省": true, "青海省": true, "港澳台": true, "北京": true, "天津": true, "上海": true, "重庆": true, + "内蒙古": true, "广西": true, "西藏": true, "宁夏": true, "新疆": true + }; + } } diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 1b212cf..0735f71 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -1033,6 +1033,43 @@ export default class Utils { makeRequest(); } + /** 获取入职排行榜 */ + static getSRank(callBack) { + // 最大重试次数 + const maxRetries = 5; + let retryCount = 0; + // 标志位,用于记录 callBack 是否已经被调用 + let isCallBackCalled = false; + const makeRequest = () => { + if (retryCount > maxRetries) { + if (!isCallBackCalled) { + MiniGameSdk.API.showToast("网络异常,获取排行失败"); + callBack({ code: 2, data: null, message: '轮询超时,达到最大重试次数' }); + isCallBackCalled = true; + } + return; + } + // 设置超时定时器 + const timeoutId = setTimeout(() => { + retryCount++; + console.log(`请求超时,第 ${retryCount} 次重新申请接口`); + makeRequest(); + }, 3000); + console.log("请求uid:" + Utils.uid); + Utils.POST("getSRank", { uid: cc.fx.GameConfig.GM_INFO.uid }, res => { + console.log("查询入职排行榜结果"); + console.log(res); + // 清除超时定时器 + clearTimeout(timeoutId); + if (!isCallBackCalled) { + callBack(res); + isCallBackCalled = true; + } + }); + }; + makeRequest(); + } + //#region 新手礼包相关 //获取新手礼包是否能显示 static getStarter_pack(callBack) { @@ -1203,6 +1240,7 @@ export default class Utils { } static getpassCheckLv(callBack) { + //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); //旧的读取数据设置数据方法,以强联网为主 @@ -1227,6 +1265,7 @@ export default class Utils { } static setPassCheckLv(callBack, data) { + //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); //旧的读取数据设置数据方法,以强联网为主 @@ -1256,6 +1295,7 @@ export default class Utils { } static getPassCheckInfo(callBack) { + //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); //旧的读取数据设置数据方法,以强联网为主 @@ -1280,6 +1320,7 @@ export default class Utils { } static setPassCheckInfo(callBack, data) { + //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); //旧的读取数据设置数据方法,以强联网为主