AllyUI.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, Node, Sprite, Label } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { Http, HttpResponseCode } from '../../core/net/Http';
  4. import List from '../../core/ui/virtualList/List';
  5. import { FightData, FriendData } from '../FightData';
  6. import { AllyItem } from '../item/AllyItem';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('AllyUI')
  9. export class AllyUI extends Component {
  10. @property({ type: Http, displayName: "Http组件", tooltip: "Http组件" }) http: Http = null;
  11. @property({ type: List, displayName: "List列表", tooltip: "List列表" }) list: List = null;
  12. private listData: FriendData[];
  13. start() {
  14. this.getFriend();
  15. }
  16. /**获取好友数据*/
  17. private async getFriend() {
  18. let fightData = DataSystem.getData(FightData);
  19. if (fightData.friendDataList.length == 0) {
  20. let friendData = await this.http.send("/api/pvp/GetFriend");
  21. if (friendData && friendData.code == HttpResponseCode.Success) {
  22. fightData.friendDataList = friendData.data.friendDatas;
  23. }
  24. }
  25. this.listData = fightData.friendDataList.concat();
  26. this.list.numItems = this.listData.length;
  27. console.log("FriendNum: " + this.listData.length);
  28. }
  29. /**当列表渲染时
  30. * @param item item节点
  31. * @param index item的索引
  32. */
  33. public onListRender(item: Node, index: number) {
  34. if (this.listData && this.listData.length > 0) {
  35. item.getComponent(AllyItem).onDataChange(this.listData[index], index);
  36. }
  37. }
  38. }