164 lines
3.6 KiB
JavaScript
164 lines
3.6 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '5ce00eW4mRM+LWTN/2HWtMg', 'cmp.main.ads');
|
||
|
|
// Scripts/mod/mainui/cmp/cmp.main.ads.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 广告图轮播
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var BridgeComponent = require("bridge.component");
|
||
|
|
var SEC_DELAY = 2;
|
||
|
|
cc.Class({
|
||
|
|
"extends": BridgeComponent,
|
||
|
|
properties: {
|
||
|
|
autoSecs: {
|
||
|
|
"default": 3
|
||
|
|
},
|
||
|
|
adPages: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.PageView
|
||
|
|
},
|
||
|
|
tPage: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 显示
|
||
|
|
onEnable: function onEnable() {
|
||
|
|
var _this = this;
|
||
|
|
// 清空
|
||
|
|
this.adPages.removeAllPages();
|
||
|
|
|
||
|
|
// 视图绑定
|
||
|
|
if (nx.bridge.acts) {
|
||
|
|
nx.bridge.acts.vbind(this, [["foreshow", this.onFreshAds.bind(this)]]);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 自动弹出
|
||
|
|
this.popDone = false;
|
||
|
|
this.scheduleOnce(function () {
|
||
|
|
_this.tryAutoPopup(true);
|
||
|
|
}, SEC_DELAY);
|
||
|
|
},
|
||
|
|
// 关闭
|
||
|
|
onDisable: function onDisable() {
|
||
|
|
// 视图绑定
|
||
|
|
if (nx.bridge.acts) {
|
||
|
|
nx.bridge.acts.vunbind(this);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 重建轮播列表
|
||
|
|
onFreshAds: function onFreshAds(_data) {
|
||
|
|
var _this2 = this;
|
||
|
|
// 空
|
||
|
|
if (nx.dt.arrEmpty(_data)) {
|
||
|
|
this.node.opacity = 0;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 清空
|
||
|
|
this.adPages.removeAllPages();
|
||
|
|
this.node.opacity = 255;
|
||
|
|
this.ads = nx.dt.objClone(_data);
|
||
|
|
this.toLeft = true;
|
||
|
|
this.ads.forEach(function (ad) {
|
||
|
|
_this2.addPage(ad);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 自动轮播
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
this.schedule(function () {
|
||
|
|
_this2.nextAd();
|
||
|
|
}, this.autoSecs);
|
||
|
|
},
|
||
|
|
// 添加广告图
|
||
|
|
addPage: function addPage(_ad) {
|
||
|
|
// 创建新页面
|
||
|
|
var page = cc.instantiate(this.tPage);
|
||
|
|
page.name = "" + _ad.id;
|
||
|
|
page.adinfo = _ad;
|
||
|
|
var path = cc.path.join("locals", nx.getLocLanguage(), "images/ads", _ad.sc);
|
||
|
|
nx.gui.setSpriteFrame(page, "img", path);
|
||
|
|
|
||
|
|
// 加入PV
|
||
|
|
this.adPages.addPage(page);
|
||
|
|
},
|
||
|
|
// 下一张
|
||
|
|
nextAd: function nextAd() {
|
||
|
|
var total = this.adPages.getPages().length;
|
||
|
|
var cur = this.adPages.getCurrentPageIndex();
|
||
|
|
|
||
|
|
// 左移
|
||
|
|
if (this.toLeft) {
|
||
|
|
var next = cur + 1;
|
||
|
|
if (total > 1) {
|
||
|
|
if (next < total) {
|
||
|
|
this.adPages.scrollToPage(next);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (next <= total) {
|
||
|
|
this.adPages.scrollToPage(next);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.toLeft = false;
|
||
|
|
this.nextAd();
|
||
|
|
} else {
|
||
|
|
var _next = cur - 1;
|
||
|
|
if (_next >= 0) {
|
||
|
|
this.adPages.scrollToPage(_next);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.toLeft = true;
|
||
|
|
this.nextAd();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 点击广告图
|
||
|
|
onTouchAd: function onTouchAd(_ad) {
|
||
|
|
var info = _ad ? _ad.adinfo : {};
|
||
|
|
if (nx.dt.objNEmpty(info)) {
|
||
|
|
if (nx.dt.strNEmpty(info.sk)) {
|
||
|
|
nx.bridge.cmd.doStr(info.sk);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 自动弹出
|
||
|
|
tryAutoPopup: function tryAutoPopup(_reset) {
|
||
|
|
var _this3 = this;
|
||
|
|
if (_reset === void 0) {
|
||
|
|
_reset = false;
|
||
|
|
}
|
||
|
|
var pop = nx.storage.get("foreshow");
|
||
|
|
|
||
|
|
// 已经弹出过了
|
||
|
|
if (_reset) {
|
||
|
|
this.popDone = false;
|
||
|
|
}
|
||
|
|
if (this.popDone || pop && pop == 1) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 弹出
|
||
|
|
var list = nx.bridge.acts.vget("foreshow");
|
||
|
|
if (nx.dt.arrNEmpty(list)) {
|
||
|
|
this.popDone = true;
|
||
|
|
nx.bridge.createPanel("WndActsForeshow");
|
||
|
|
nx.storage.set("foreshow", 1);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 延迟再试
|
||
|
|
this.scheduleOnce(function () {
|
||
|
|
_this3.tryAutoPopup();
|
||
|
|
}, SEC_DELAY);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|