| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { _decorator, Button, Component, instantiate, Layout, Node, NodePool, Prefab, ScrollView, UITransform } from 'cc';
- import { BasePanel } from './BasePanel';
- import List from '../Tools/List';
- import { ItemInfor } from './ItemInfor';
- const { ccclass, property } = _decorator;
- @ccclass('RankPanel')
- export class RankPanel extends BasePanel {
- private content: UITransform;
- private nation_Btn: Button;
- private friend_Btn: Button;
- private data: any[] = [];
- //列表
- @property(List)
- list: List = null;
- public onList:Function;
- onListRender(item: any, idx: number) {
- this.onList?.(item,idx);
- }
- start() {
- this.content = this.node.getChildByPath('ScrollView/view/content').getComponent(UITransform);
- this.nation_Btn = this.node.getChildByName('Nation_Btn').getComponent(Button);
- this.friend_Btn = this.node.getChildByName('Friend_Btn').getComponent(Button);
- this.nation_Btn.node.on(Button.EventType.CLICK, this.onNationBtnClick, this);
- this.friend_Btn.node.on(Button.EventType.CLICK, this.onFriendBtnClick, this);
- }
- getData(){
- this.onList=(item:Node,index:number)=>{
- item.getComponent(ItemInfor).updateData(index,null,this.data[index]);
- }
- this.showType();
- }
- private async showType(){
- const ret = await chsdk.loadRankData("全国", chsdk.updateType.none, 100, true,false);
- console.log("排行榜数据:", ret);
- // 解构返回值
- if (ret.code === 0) {
- this.data = ret.data.list;
- this.list.numItems = ret.data.list.length;
- console.log("排行榜列表:", this.data);
- } else {
- console.error("错误信息:", ret.err);
- }
- }
- update(deltaTime: number) { }
- onNationBtnClick() {
- this.friend_Btn.normalSprite = this.friend_Btn.disabledSprite;
- this.nation_Btn.normalSprite = this.nation_Btn.pressedSprite;
- }
- onFriendBtnClick() {
- this.nation_Btn.normalSprite = this.nation_Btn.disabledSprite;
- this.friend_Btn.normalSprite = this.friend_Btn.pressedSprite;
- }
- onEnter(): void {
- super.onEnter();
- this.getData();
- }
- onExit(): void {
- super.onExit();
- }
- onClose(): void {
- super.onClose(null);
- }
- }
|