RankPanel.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { _decorator, Button, Component, instantiate, Layout, Node, NodePool, Prefab, ScrollView, UITransform } from 'cc';
  2. import { BasePanel } from './BasePanel';
  3. import List from '../Tools/List';
  4. import { ItemInfor } from './ItemInfor';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('RankPanel')
  7. export class RankPanel extends BasePanel {
  8. private content: UITransform;
  9. private nation_Btn: Button;
  10. private friend_Btn: Button;
  11. private data: any[] = [];
  12. //列表
  13. @property(List)
  14. list: List = null;
  15. public onList:Function;
  16. onListRender(item: any, idx: number) {
  17. this.onList?.(item,idx);
  18. }
  19. start() {
  20. this.content = this.node.getChildByPath('ScrollView/view/content').getComponent(UITransform);
  21. this.nation_Btn = this.node.getChildByName('Nation_Btn').getComponent(Button);
  22. this.friend_Btn = this.node.getChildByName('Friend_Btn').getComponent(Button);
  23. this.nation_Btn.node.on(Button.EventType.CLICK, this.onNationBtnClick, this);
  24. this.friend_Btn.node.on(Button.EventType.CLICK, this.onFriendBtnClick, this);
  25. }
  26. getData(){
  27. this.onList=(item:Node,index:number)=>{
  28. item.getComponent(ItemInfor).updateData(index,null,this.data[index]);
  29. }
  30. this.showType();
  31. }
  32. private async showType(){
  33. const ret = await chsdk.loadRankData("全国", chsdk.updateType.none, 100, true,false);
  34. console.log("排行榜数据:", ret);
  35. // 解构返回值
  36. if (ret.code === 0) {
  37. this.data = ret.data.list;
  38. this.list.numItems = ret.data.list.length;
  39. console.log("排行榜列表:", this.data);
  40. } else {
  41. console.error("错误信息:", ret.err);
  42. }
  43. }
  44. update(deltaTime: number) { }
  45. onNationBtnClick() {
  46. this.friend_Btn.normalSprite = this.friend_Btn.disabledSprite;
  47. this.nation_Btn.normalSprite = this.nation_Btn.pressedSprite;
  48. }
  49. onFriendBtnClick() {
  50. this.nation_Btn.normalSprite = this.nation_Btn.disabledSprite;
  51. this.friend_Btn.normalSprite = this.friend_Btn.pressedSprite;
  52. }
  53. onEnter(): void {
  54. super.onEnter();
  55. this.getData();
  56. }
  57. onExit(): void {
  58. super.onExit();
  59. }
  60. onClose(): void {
  61. super.onClose(null);
  62. }
  63. }