| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import { _decorator, Component, Node, Prefab, instantiate, Label, UITransform, Animation, sys } from 'cc';
- import InfiniteCell from '../core/InfiniteList/InfiniteCell';
- import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList';
- import { Http } from '../core/net/Http';
- import { OpenWindow } from '../core/ui/window/OpenWindow';
- import { Window } from '../core/ui/window/Window';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { Utils } from '../core/utils/Utils';
- import { g } from '../Data/g';
- import { HttpErrorCode } from '../Data/HttpErrorCode';
- import { platform } from '../Data/platform';
- import { GetType } from '../UI/GetWindow/GetType';
- import { DayLoginItem } from './DayLoginItem';
- const { ccclass, property } = _decorator;
- @ccclass('DayLogin')
- export class DayLogin extends Component implements IFDataSource {
- @property({ type: Window })
- public dayLoginWindow: Window = null;
- @property({ type: Prefab })
- public dayLoginItem: Prefab | null = null;
- @property({ type: Node })
- public list: Node | null = null;
- @property({ type: Http })
- public http: Http = null;
- public numArr: Array<string> = ["起点", "1", "2", "3", "4", "5", "6", "7"];
- private day = null;
- private width: number = null;
- //播放完广告从服务器获得红包数量
- private redbagNum: number;
- private nextWindows: string[];
- public async start() {
- this.numArr = this.numArr.slice(this.day - 1, this.numArr.length);
- let prefab = instantiate(this.dayLoginItem);
- this.width = prefab.getComponent(UITransform).width;
- prefab.destroy();
- let infiniteList = this.list.getComponent(InfiniteList);
- infiniteList.Init(this);
- }
- /**
- * 签到按钮点击
- */
- async onLoginClick() {
- let result = await this.http.send("/api/ad/watchVideoAD");
- if (result.code == 0) {
- 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() }));
- //播放视频
- let adData = await g.showRewardVideo();
- if (adData) {
- this.onLoginVideoOver();
- } else {
- //视频观看失败
- WindowManager.showTips("视频观看时间不足");
- }
- } else if (result.code == 106) {
- WindowManager.showTips("今日视频次数已用完,请明日再继续");
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- } else {
- WindowManager.showTips("视频准备中,请稍后再试");
- }
- }
- /**
- * 签到广告观看完毕
- */
- async onLoginVideoOver() {
- let result = await this.http.send("/api/dailyLogin/dailyLoginReceive", { adData: g.adData });
- if (result.code == 0) {
- 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 }))
- platform.umUp("dayLogin");//签到埋点
- this.redbagNum = result.data;
- this.dayLoginWindow.node.destroy();
- platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: this.redbagNum, current_number: g.userData.bonus + this.redbagNum, reasons: "dailyLoginReceive" }));
- WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.redbagNum, type: GetType.RedBag, needBezierEffect: true }]);
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- }
- }
- /**
- * 接收参数
- */
- onParam(params: any[]) {
- this.day = params[0] % 7 + 1;
- this.nextWindows = params[1];
- }
- onClosing(closeCallback: () => void) {
- closeCallback();
- if (this.nextWindows && this.nextWindows.length) {
- WindowManager.open(this.nextWindows.shift(), WindowOpenMode.NotCloseAndAdd, this.nextWindows);
- }
- }
- GetCellNumber(): number {
- return this.numArr.length;
- }
- GetCellIdentifer(dataIndex: number): string {
- return "DayLoginItem";
- }
- GetCellSize(dataIndex: number): number {
- return this.width;
- }
- GetCellView(dataIndex: number, identifier?: string): InfiniteCell {
- let prefab = instantiate(this.dayLoginItem);
- return prefab.getComponent(DayLoginItem);
- }
- GetCellData?(dataIndex: number) {
- let isCan: boolean = dataIndex == 1;
- let isOver: boolean = dataIndex == 0;
- return { day: this.numArr[dataIndex], isCan: isCan, isOver: isOver };
- }
- }
|