Files
2026-05-23 22:10:14 +08:00

138 lines
3.2 KiB
JavaScript

/******************************************************************
*
* 活动预告
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
cc.Class( {
extends: BridgeWindow,
properties: {
autoSecs: { default: 10 },
adPages: { default: null, type: cc.PageView },
tPage: { default: null, type: cc.Node },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
// 统计菜单项
this.menus = nx.bridge.acts.vget( "foreshow" );
if( nx.dt.arrEmpty( this.menus ) ) {
this.delayClose();
return;
}
// 清空
this.adPages.removeAllPages();
this.toLeft = true;
this.menus.forEach( ad => {
this.addPage( ad );
} );
// 自动轮播
this.unscheduleAllCallbacks();
this.schedule( () => {
this.nextAd();
}, this.autoSecs );
},
// 添加广告图
addPage: function( _ad ) {
// 创建新页面
let page = cc.instantiate( this.tPage );
page.name = "" + _ad.id;
page.adinfo = _ad;
let path = cc.path.join( "locals", nx.getLocLanguage(), "images/ads", _ad.img );
nx.gui.setSpriteFrame( page, "img", path );
// 加入PV
this.adPages.addPage( page );
},
// 下一张
nextAd: function( _dir ) {
let total = this.adPages.getPages().length;
let cur = this.adPages.getCurrentPageIndex();
// 左移
if( this.toLeft ) {
let 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 {
let next = cur - 1;
if( next >= 0 ) {
this.adPages.scrollToPage( next );
return;
}
this.toLeft = true;
this.nextAd();
}
},
// 左切
onTouchLeft: function() {
let cur = this.adPages.getCurrentPageIndex() - 1;
if( cur >= 0 ) {
this.adPages.scrollToPage( cur );
}
},
// 右切
onTouchRight: function() {
let total = this.adPages.getPages().length;
let cur = this.adPages.getCurrentPageIndex() + 1;
if( cur < total ) {
this.adPages.scrollToPage( cur );
}
},
// 点击海报
onTouchBox: function() {
let cur = this.adPages.getCurrentPageIndex();
let info = this.menus[cur];
if( nx.dt.objEmpty( info ) ) {
return;
}
// 活动跳转
if( nx.dt.numPositive( info.camp_id, false ) ) {
nx.bridge.jumper.jump2ActPage( info.camp_id );
this.close();
return;
}
// 普通跳转
if( nx.dt.strNEmpty( info.link ) ) {
nx.bridge.cmd.doStr( info.link );
this.close();
return;
}
},
} );