Files
fc/dev/project/library/imports/22/2218764c-31e3-422a-9f18-ebac3547ff6a.js
2026-05-24 10:21:26 +08:00

91 lines
2.1 KiB
JavaScript

"use strict";
cc._RF.push(module, '22187ZMMeNCKp8Y66w1R/9q', 'vb.cd');
// Scripts/nx/cmp/flex/vb.cd.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 倒计时
*
* 2018.05.18
******************************************************************/
cc.Class({
"extends": cc.Component,
properties: {
endTxt: "",
//倒計時結束提示
isPop: false //是否飘窗提示
},
// 编辑器特性
editor: {
// 允许当前组件在编辑器模式下运行
executeInEditMode: false,
// requireComponent 参数用来指定当前组件的依赖组件
requireComponent: cc.Label,
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
disallowMultiple: true
},
onEnable: function onEnable() {},
onDisable: function onDisable() {
this.unscheduleAllCallbacks();
},
// 改变通知
_onValueChanged: function _onValueChanged(_secs) {
this.unscheduleAllCallbacks();
this.secs = _secs;
// 文本
var self = this;
var text = function text(_secs) {
// 结束
var txt = "";
if (_secs <= 0) {
// 空提示
txt = nx.text.getKey(self.doneKey);
if (nx.dt.strNEmpty(txt)) {
nx.gui.setString(self, "", txt);
return;
} else {
txt = "00:00:00";
}
} else {
txt = nx.dt.fmtTimeFromSecs(_secs, true);
}
// 格式化
if (nx.dt.strNEmpty(self.fmtText)) {
txt = nx.text.format(self.fmtText, txt);
}
nx.gui.setString(self, "", txt);
};
// 0
if (!nx.dt.numPositive(_secs, false)) {
text(0);
return;
}
// 倒计时
text(this.secs);
this.schedule(function () {
self.secs = Math.max(self.secs - 1, 0);
text(self.secs);
// 结束
if (self.secs <= 0) {
self.unscheduleAllCallbacks();
// 通告
if (self.doneEvents) {
cc.Component.EventHandler.emitEvents(self.doneEvents);
}
}
}, 1);
}
});
cc._RF.pop();