DayLogin.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { _decorator, Component, Node, Prefab, instantiate, Label, UITransform, Animation, sys } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList';
  4. import { Http } from '../core/net/Http';
  5. import { OpenWindow } from '../core/ui/window/OpenWindow';
  6. import { Window } from '../core/ui/window/Window';
  7. import { WindowManager } from '../core/ui/window/WindowManager';
  8. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  9. import { Utils } from '../core/utils/Utils';
  10. import { g } from '../Data/g';
  11. import { HttpErrorCode } from '../Data/HttpErrorCode';
  12. import { platform } from '../Data/platform';
  13. import { GetType } from '../UI/GetWindow/GetType';
  14. import { DayLoginItem } from './DayLoginItem';
  15. const { ccclass, property } = _decorator;
  16. @ccclass('DayLogin')
  17. export class DayLogin extends Component implements IFDataSource {
  18. @property({ type: Window })
  19. public dayLoginWindow: Window = null;
  20. @property({ type: Prefab })
  21. public dayLoginItem: Prefab | null = null;
  22. @property({ type: Node })
  23. public list: Node | null = null;
  24. @property({ type: Http })
  25. public http: Http = null;
  26. public numArr: Array<string> = ["起点", "1", "2", "3", "4", "5", "6", "7"];
  27. private day = null;
  28. private width: number = null;
  29. //播放完广告从服务器获得红包数量
  30. private redbagNum: number;
  31. private nextWindows: string[];
  32. public async start() {
  33. this.numArr = this.numArr.slice(this.day - 1, this.numArr.length);
  34. let prefab = instantiate(this.dayLoginItem);
  35. this.width = prefab.getComponent(UITransform).width;
  36. prefab.destroy();
  37. let infiniteList = this.list.getComponent(InfiniteList);
  38. infiniteList.Init(this);
  39. }
  40. /**
  41. * 签到按钮点击
  42. */
  43. async onLoginClick() {
  44. let result = await this.http.send("/api/ad/watchVideoAD");
  45. if (result.code == 0) {
  46. platform.reportThinking("ad_init", JSON.stringify({ ad_id: "login_reward", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
  47. //播放视频
  48. let adData = await g.showRewardVideo();
  49. if (adData) {
  50. this.onLoginVideoOver();
  51. } else {
  52. //视频观看失败
  53. WindowManager.showTips("视频观看时间不足");
  54. }
  55. } else if (result.code == 106) {
  56. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  57. } else if (result.code == HttpErrorCode.VideoADCD) {
  58. WindowManager.showTips("请求频繁,请稍后再试");
  59. } else {
  60. WindowManager.showTips("视频准备中,请稍后再试");
  61. }
  62. }
  63. /**
  64. * 签到广告观看完毕
  65. */
  66. async onLoginVideoOver() {
  67. let result = await this.http.send("/api/dailyLogin/dailyLoginReceive", { adData: g.adData });
  68. if (result.code == 0) {
  69. platform.reportThinking("ad_end", JSON.stringify({ ad_id: "login_reward", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: result.data }))
  70. platform.umUp("dayLogin");//签到埋点
  71. this.redbagNum = result.data;
  72. this.dayLoginWindow.node.destroy();
  73. platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: this.redbagNum, current_number: g.userData.bonus + this.redbagNum, reasons: "dailyLoginReceive" }));
  74. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.redbagNum, type: GetType.RedBag, needBezierEffect: true }]);
  75. } else if (result.code == HttpErrorCode.VideoADCD) {
  76. WindowManager.showTips("请求频繁,请稍后再试");
  77. }
  78. }
  79. /**
  80. * 接收参数
  81. */
  82. onParam(params: any[]) {
  83. this.day = params[0] % 7 + 1;
  84. this.nextWindows = params[1];
  85. }
  86. onClosing(closeCallback: () => void) {
  87. closeCallback();
  88. if (this.nextWindows && this.nextWindows.length) {
  89. WindowManager.open(this.nextWindows.shift(), WindowOpenMode.NotCloseAndAdd, this.nextWindows);
  90. }
  91. }
  92. GetCellNumber(): number {
  93. return this.numArr.length;
  94. }
  95. GetCellIdentifer(dataIndex: number): string {
  96. return "DayLoginItem";
  97. }
  98. GetCellSize(dataIndex: number): number {
  99. return this.width;
  100. }
  101. GetCellView(dataIndex: number, identifier?: string): InfiniteCell {
  102. let prefab = instantiate(this.dayLoginItem);
  103. return prefab.getComponent(DayLoginItem);
  104. }
  105. GetCellData?(dataIndex: number) {
  106. let isCan: boolean = dataIndex == 1;
  107. let isOver: boolean = dataIndex == 0;
  108. return { day: this.numArr[dataIndex], isCan: isCan, isOver: isOver };
  109. }
  110. }