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

73 lines
1.9 KiB
JavaScript

/*******************************************************************************
*
* 个人推送模块
*
* 2023.09.27
******************************************************************************/
const BridgeController = require( "bridge.controller" );
const PersonalPushMod = cc.Class( {
extends: BridgeController,
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 28900, this.onPushData.bind( this ) );
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
nx.bridge.vset( "PPushNews", [] );
nx.bridge.vset( "PPushGifts", [] );
nx.bridge.vset( "PPushCD", 0 );
// 配置加载
let cfgs = [
"personal_push_data",
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
nx.dt.fnInvoke( _cb, true );
this.reqBaseData();
} );
},
// ============================================================
// 基本数据
// ============================================================
// 请求基本数据
reqBaseData: function( _cb ) {
this.SendProtocal( 28900, {}, _cb );
},
// 基本数据
onPushData: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
// 基本信息
nx.bridge.vset( "PPushGifts", _data.gift_list || [] );
nx.bridge.vset( "PPushNews", _data.new_gift_id_list || [] );
// 就近时间戳
let time = 0;
if( nx.dt.arrNEmpty( _data.gift_list ) ) {
_data.gift_list.forEach( _gift => {
if( time == 0 ||
time > _gift.over_time ) {
time = _gift.over_time;
}
} );
}
nx.bridge.vset( "PPushCD", time );
},
} );
// 模块导出
module.exports = PersonalPushMod;