| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import { _decorator, Component, Prefab, instantiate, UITransform } from 'cc';
- import { IFDataSource, InfiniteList } from '../../core/InfiniteList/InfiniteList';
- import { Http } from '../../core/net/Http';
- import { platform } from '../../Data/platform';
- import { EachWindowItem } from './EachWindowItem';
- const { ccclass, property } = _decorator;
- @ccclass('EachWindow')
- export class EachWindow extends Component implements IFDataSource {
- @property({ type: Http, tooltip: "Http组件" }) http: Http;
- @property({ type: InfiniteList, tooltip: "列表组件" }) list: InfiniteList;
- @property({ type: Prefab, tooltip: "列表cell预制体" }) cell: Prefab;
- private prefabHeight: number;
- private recommendData = [];
- async start() {
- let result = await this.http.send("/api/recommend/GetRecommendList");
- if (result.code == 0) {
- platform.umUp("eachPush");//互推埋点
- for (let i = 0; i < result.data.plug.length; i++) {
- let d = result.data.plug[i];
- this.recommendData.push({
- icon: d.icon,
- title: d.title,
- dec: d.introduction,
- url: d.downloadUrl,
- nebulaAppId: d.nebulaAppId
- });
- }
- }
- let prefab = instantiate(this.cell);
- this.prefabHeight = prefab.getComponent(UITransform).height;
- prefab.destroy();
- this.list.Init(this);
- }
- //#region IFDataSource
- public GetCellData(dataIndex: number): any {
- return this.recommendData[dataIndex];
- }
- public GetCellNumber(): number {
- return this.recommendData.length;
- }
- public GetCellSize(index: number): number {
- return this.prefabHeight ? this.prefabHeight : 100;
- }
- public GetCellView(index: number): EachWindowItem {
- let node = instantiate(this.cell);
- return node.getComponent(EachWindowItem);
- }
- public GetCellIdentifer(index: number): string {
- return "EachWindowItem";
- }
- //#endregion
- }
|