const LoginApi = require('../net/LoginApi'); cc.Class({ extends: cc.Component, properties: { scrollView: cc.ScrollView, layout: cc.Layout, rankItem: cc.Prefab, meNode: cc.Node }, // LIFE-CYCLE CALLBACKS: onLoad () { if (CC_QQPLAY) { this.scrollView.node.active = true; this.pageIndex = 0; this.listItem = []; for(let i = 0; i < 5; i++) { let item = cc.instantiate(this.rankItem); this.layout.node.addChild(item); item.active = false; this.listItem.push(item); } if (GameGlobal.winSize.height <= 1000) { this.scrollView.vertical = true; } } }, start () { }, onEnable() { if (CC_WECHATGAME) { window.wx.postMessage({ messageType: 0 }); } else if (CC_QQPLAY) { } }, init() { if (CC_QQPLAY) { var attr = "score";//使用哪一种上报数据做排行,可传入score,a1,a2等 var order = 1; //排序的方法:[ 1: 从大到小(单局),2: 从小到大(单局),3: 由大到小(累积)] var rankType = 0; //要查询的排行榜类型,0: 好友排行榜 let self = this; BK.QQ.getRankListWithoutRoom(attr, order, rankType, function (errCode, cmd, data) { // 返回错误码信息 if (errCode !== 0) { BK.Script.log(1, 1, '获取排行榜数据失败!错误码:' + errCode); return; } // 解析数据 if (data) { self.ranks = data.data.ranking_list; self._sortMeData(); self._setupList(); } }); } }, _setupList() { let start = this.pageIndex * 5; let end = start + 5; let sortArray = this.ranks.slice(start,end); this.listItem.forEach(n => { n.active = false; }); for(let i = 0; i < sortArray.length; i++) { let item = this.listItem[i]; item.active = true; let model = sortArray[i]; model.rank = this.pageIndex * 5 + (i + 1); item.getComponent('GameRankItem').initQQData(model); } }, _sortMeData() { for(let i = 0; i < this.ranks.length; i++) { let model = this.ranks[i]; model.rank = i + 1; if (model.selfFlag) { this.myData = model; this._setupMeData(); break; } } }, _setupMeData() { LoginApi.getUpdateNickOrHead(this.myData.nick,this.myData.url, (res) => { }, (error) => { }); this.meNode.active = true; this.meNode.getComponent('GameRankItem').initQQData(this.myData, true); }, previousPage() { if (CC_WECHATGAME) { window.wx.postMessage({ messageType: 1 }); } else if (CC_QQPLAY) { if (this.pageIndex <= 0 || this.ranks == undefined || this.ranks.length == 0) { return; } this.pageIndex -= 1; this._setupList(); this.scrollView.scrollToTop(); } }, nextPage() { if (CC_WECHATGAME) { window.wx.postMessage({ messageType: 2 }); } else if (CC_QQPLAY) { if (this.pageIndex >= (Math.ceil(this.ranks.length / 5) - 1) || this.ranks == undefined || this.ranks.length == 0) { return; } this.pageIndex += 1; this._setupList(); this.scrollView.scrollToTop(); } } // update (dt) {}, });