EachWindow.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 { g } from '../../Data/g';
  5. import { platform } from '../../Data/platform';
  6. import { EachWindowItem } from './EachWindowItem';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('EachWindow')
  9. export class EachWindow extends Component implements IFDataSource {
  10. @property({ type: Http, tooltip: "Http组件" }) http: Http;
  11. @property({ type: InfiniteList, tooltip: "列表组件" }) list: InfiniteList;
  12. @property({ type: Prefab, tooltip: "列表cell预制体" }) cell: Prefab;
  13. private prefabHeight: number;
  14. async start() {
  15. let prefab = instantiate(this.cell);
  16. this.prefabHeight = prefab.getComponent(UITransform).height;
  17. prefab.destroy();
  18. this.list.Init(this);
  19. }
  20. update() {
  21. if (g.downLoadData.needCheck) {
  22. g.downLoadData.needCheck = false;
  23. this.list.Reload();
  24. }
  25. }
  26. //#region IFDataSource
  27. public GetCellData(dataIndex: number): any {
  28. return g.downLoadData.recommendData[dataIndex];
  29. }
  30. public GetCellNumber(): number {
  31. return g.downLoadData.recommendData.length;
  32. }
  33. public GetCellSize(index: number): number {
  34. return this.prefabHeight ? this.prefabHeight : 100;
  35. }
  36. public GetCellView(index: number): EachWindowItem {
  37. let node = instantiate(this.cell);
  38. return node.getComponent(EachWindowItem);
  39. }
  40. public GetCellIdentifer(index: number): string {
  41. return "taskWindowItem";
  42. }
  43. //#endregion
  44. }