96 lines
2.5 KiB
JavaScript
96 lines
2.5 KiB
JavaScript
/******************************************************************
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
|
*
|
|
* 功能/窗体跳转按钮
|
|
*
|
|
* 2018.05.18
|
|
******************************************************************/
|
|
|
|
const TDefine = require( "trace.define" );
|
|
const TTT = TDefine.TraceType;
|
|
|
|
cc.Class( {
|
|
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
|
|
wndName: { default: "", displayName: "窗体名" },
|
|
sourceId: { default: 0, displayName: "来源(功能)编号" },
|
|
param1: { default: "", displayName: "参数(p1)" },
|
|
param2: { default: "", displayName: "参数(p2)" },
|
|
touchAudio: { default: null, type: cc.AudioClip, displayName: "触摸音" },
|
|
interval: { default: 0.2, displayName: "点击间隔(秒)" },
|
|
|
|
// 埋点
|
|
idType: { default: TTT.btnClicked, type: TTT, displayName: "埋点类型" },
|
|
btnName: { default: "", displayName: "按钮名" },
|
|
},
|
|
|
|
// 编辑器特性
|
|
editor: {
|
|
|
|
// requireComponent 参数用来指定当前组件的依赖组件
|
|
requireComponent: cc.Button,
|
|
|
|
// menu 用来将当前组件添加到组件菜单中,方便用户查找
|
|
menu: "老版桥接/功能(窗体)跳转",
|
|
|
|
},
|
|
|
|
// 显示
|
|
onEnable: function () {
|
|
this.node.on( "click", this.onClicked, this );
|
|
},
|
|
|
|
// 隐藏
|
|
onDisable: function () {
|
|
this.node.off( "click", this.onClicked, this );
|
|
},
|
|
|
|
// 点击
|
|
onClicked: function () {
|
|
|
|
// 音效
|
|
if( this.touchAudio ) {
|
|
nx.audio.playSFX( this.touchAudio, false );
|
|
}
|
|
|
|
// 点击间隔
|
|
var now = cc.sys.now();
|
|
if( typeof this.lastClickTime == "number" ) {
|
|
var ms = this.interval * 1000;
|
|
if( ( now - this.lastClickTime ) < ms ) {
|
|
return;
|
|
}
|
|
}
|
|
this.lastClickTime = now;
|
|
|
|
let args = {
|
|
p1: this.param1,
|
|
p2: this.param2
|
|
};
|
|
|
|
// 直接打开
|
|
if( nx.dt.strNEmpty( this.wndName ) ) {
|
|
nx.bridge.createPanel( this.wndName, args );
|
|
return;
|
|
}
|
|
|
|
// 跳转
|
|
let sid = parseInt( this.sourceId );
|
|
if( nx.dt.numGood( sid ) ) {
|
|
nx.bridge.jumper.jump2Window( sid, args );
|
|
} else {
|
|
nx.bridge.jumper.jump2WindowByKey( sid, args );
|
|
}
|
|
|
|
// 埋点
|
|
if( nx.mTrace && this.idType > 0 && nx.dt.strNEmpty( this.btnName ) ) {
|
|
nx.mTrace.trace( this.idType, this.btnName );
|
|
}
|
|
|
|
}
|
|
|
|
} );
|