| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { _decorator, Component, Node, Sprite, Label } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../../core/net/Http';
- import List from '../../core/ui/virtualList/List';
- import { FightData, FriendData } from '../FightData';
- import { AllyItem } from '../item/AllyItem';
- const { ccclass, property } = _decorator;
- @ccclass('AllyUI')
- export class AllyUI extends Component {
- @property({ type: Http, displayName: "Http组件", tooltip: "Http组件" }) http: Http = null;
- @property({ type: List, displayName: "List列表", tooltip: "List列表" }) list: List = null;
- private listData: FriendData[];
- start() {
- this.getFriend();
- }
- /**获取好友数据*/
- private async getFriend() {
- let fightData = DataSystem.getData(FightData);
- if (fightData.friendDataList.length == 0) {
- let friendData = await this.http.send("/api/pvp/GetFriend");
- if (friendData && friendData.code == HttpResponseCode.Success) {
- fightData.friendDataList = friendData.data.friendDatas;
- }
- }
- this.listData = fightData.friendDataList.concat();
- this.list.numItems = this.listData.length;
- console.log("FriendNum: " + this.listData.length);
- }
- /**当列表渲染时
- * @param item item节点
- * @param index item的索引
- */
- public onListRender(item: Node, index: number) {
- if (this.listData && this.listData.length > 0) {
- item.getComponent(AllyItem).onDataChange(this.listData[index], index);
- }
- }
- }
|