QCrossWidget6.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { utils } from "./Utils";
  2. import QCrossWidgetItem from "./QCrossWidgetItem";
  3. import AldUtils from "./AldUtils";
  4. import { SubLocation } from "./YZ_Constant";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class QCrossWidget6 extends cc.Component {
  8. _pageView: cc.PageView = null;
  9. _pageItem: cc.Node = null;
  10. _pageRecItem: cc.Node = null;
  11. private _jumpList: any = null;
  12. private _items: QCrossWidgetItem[] = [];
  13. onLoad() {
  14. this._pageView = this.node.getChildByName("PageView").getComponent(cc.PageView);
  15. this._pageItem = this._pageView.content.getChildByName("Panel");
  16. this._pageRecItem = this._pageItem.children[0];
  17. this._pageView.content.removeAllChildren();
  18. // for (let i = 0; i < 6; i++) {
  19. // let item: cc.Node = panel.getChildByName(`Item${i}`);
  20. // let qcrossWidgetItem: QCrossWidgetItem = item.getComponent("QCrossWidgetItem");
  21. // qcrossWidgetItem._location = "isQCross";
  22. // this._items.push(item.getComponent("QCrossWidgetItem"));
  23. // }
  24. AldUtils.SendEvent("显示6元素交叉推广组件");
  25. }
  26. start() {
  27. this._jumpList = utils.getRecommondGameList();
  28. if (this._jumpList && this._jumpList.length > 0) {
  29. this._initWidget();
  30. } else {
  31. cc.warn("交叉推广数据为null, 6元素交叉推广组件不显示!");
  32. this.node.destroy();
  33. }
  34. }
  35. private _initWidget() {
  36. let totalPage: number = Math.ceil(this._jumpList.length / 6);
  37. // utils.showLog(`qcrosswidget >>> totalPage = ${totalPage}`);
  38. utils.showLog(`qcrosswidget >>> totalPage = ${totalPage}`);
  39. let indx: number = 0;
  40. for (let i = 0; i < totalPage; i++) {
  41. let page = cc.instantiate(this._pageItem);
  42. page.removeAllChildren();
  43. this._pageView.addPage(page);
  44. for (let j = 0; j < 6; j++) {
  45. if (!this._jumpList[indx]) break;
  46. let tempNode = cc.instantiate(this._pageRecItem);
  47. page.addChild(tempNode);
  48. let qcrossWidgetItem: QCrossWidgetItem = tempNode.getComponent("QCrossWidgetItem");
  49. qcrossWidgetItem._location = SubLocation.isQCross;
  50. let data = this._jumpList[indx];
  51. tempNode.getComponent("QCrossWidgetItem").init(data);
  52. indx++;
  53. }
  54. }
  55. this.autoRefrshPageView();
  56. // for (let i = 0; i < this._jumpList.length; i++) {
  57. // let data: any = this._jumpList[i];
  58. // if (data && data.logo) {
  59. // let itemIdx: number = idx;
  60. // if (itemIdx >= this._items.length) {
  61. // return;
  62. // }
  63. // idx++;
  64. // this._items[itemIdx].init(data);
  65. // }
  66. // }
  67. }
  68. autoRefrshPageView() {
  69. this.unscheduleAllCallbacks();
  70. let interval = 3;
  71. if (utils.ServerConfig && utils.ServerConfig.statement_auto_refresh) {
  72. interval = utils.ServerConfig.statement_auto_refresh;
  73. }
  74. utils.showLog(`结算交叉推广组件${interval}秒自动刷新`);
  75. this.schedule(() => {
  76. let count = this._pageView.getPages().length;
  77. let index = this._pageView.getCurrentPageIndex();
  78. index = ((index < count) && (index + 1 !== count)) ? (index + 1) : 0;
  79. if (index == 0) {
  80. this._pageView.scrollToPage(index, 0);
  81. } else {
  82. this._pageView.scrollToPage(index, 2);
  83. }
  84. }, interval);
  85. }
  86. }