EachWindow.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Component, Prefab, instantiate, UITransform } from 'cc';
  2. import { IFDataSource, InfiniteList } from '../../core/InfiniteList/InfiniteList';
  3. import { Http } from '../../core/net/Http';
  4. import { platform } from '../../Data/platform';
  5. import { EachWindowItem } from './EachWindowItem';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('EachWindow')
  8. export class EachWindow extends Component implements IFDataSource {
  9. @property({ type: Http, tooltip: "Http组件" }) http: Http;
  10. @property({ type: InfiniteList, tooltip: "列表组件" }) list: InfiniteList;
  11. @property({ type: Prefab, tooltip: "列表cell预制体" }) cell: Prefab;
  12. private prefabHeight: number;
  13. private recommendData = [];
  14. async start() {
  15. let result = await this.http.send("/api/recommend/GetRecommendList");
  16. if (result.code == 0) {
  17. platform.umUp("eachPush");//互推埋点
  18. for (let i = 0; i < result.data.plug.length; i++) {
  19. let d = result.data.plug[i];
  20. this.recommendData.push({
  21. icon: d.icon,
  22. title: d.title,
  23. dec: d.introduction,
  24. url: d.downloadUrl,
  25. nebulaAppId: d.nebulaAppId
  26. });
  27. }
  28. }
  29. let prefab = instantiate(this.cell);
  30. this.prefabHeight = prefab.getComponent(UITransform).height;
  31. prefab.destroy();
  32. this.list.Init(this);
  33. }
  34. //#region IFDataSource
  35. public GetCellData(dataIndex: number): any {
  36. return this.recommendData[dataIndex];
  37. }
  38. public GetCellNumber(): number {
  39. return this.recommendData.length;
  40. }
  41. public GetCellSize(index: number): number {
  42. return this.prefabHeight ? this.prefabHeight : 100;
  43. }
  44. public GetCellView(index: number): EachWindowItem {
  45. let node = instantiate(this.cell);
  46. return node.getComponent(EachWindowItem);
  47. }
  48. public GetCellIdentifer(index: number): string {
  49. return "EachWindowItem";
  50. }
  51. //#endregion
  52. }