7cfa5643c6c9738684864bc7698eb3fdbb12ba7f.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "cc/env"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Label, _decorator, oops, EventMessage, TimeUtil, EDITOR, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _crd, ccclass, property, menu, LabelTime;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfoops(extras) {
  8. _reporterNs.report("oops", "../../../core/Oops", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfEventMessage(extras) {
  11. _reporterNs.report("EventMessage", "../../../core/common/event/EventMessage", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfTimeUtil(extras) {
  14. _reporterNs.report("TimeUtil", "../../../core/utils/TimeUtils", _context.meta, extras);
  15. }
  16. return {
  17. setters: [function (_unresolved_) {
  18. _reporterNs = _unresolved_;
  19. }, function (_cc) {
  20. _cclegacy = _cc.cclegacy;
  21. __checkObsolete__ = _cc.__checkObsolete__;
  22. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  23. Label = _cc.Label;
  24. _decorator = _cc._decorator;
  25. }, function (_unresolved_2) {
  26. oops = _unresolved_2.oops;
  27. }, function (_unresolved_3) {
  28. EventMessage = _unresolved_3.EventMessage;
  29. }, function (_unresolved_4) {
  30. TimeUtil = _unresolved_4.TimeUtil;
  31. }, function (_ccEnv) {
  32. EDITOR = _ccEnv.EDITOR;
  33. }],
  34. execute: function () {
  35. _crd = true;
  36. _cclegacy._RF.push({}, "57786GMN6RPbaAT9b9RmX18", "LabelTime", undefined);
  37. __checkObsolete__(['Label', '_decorator']);
  38. ({
  39. ccclass,
  40. property,
  41. menu
  42. } = _decorator);
  43. /** 倒计时标签 */
  44. _export("default", LabelTime = (_dec = ccclass("LabelTime"), _dec2 = menu('OopsFramework/Label/LabelTime (倒计时标签)'), _dec3 = property({
  45. tooltip: "到计时间总时间(单位秒)"
  46. }), _dec4 = property({
  47. tooltip: "天数数据格式化"
  48. }), _dec5 = property({
  49. tooltip: "时间格式化"
  50. }), _dec6 = property({
  51. tooltip: "是否有00"
  52. }), _dec(_class = _dec2(_class = (_class2 = class LabelTime extends Label {
  53. constructor() {
  54. super(...arguments);
  55. _initializerDefineProperty(this, "countDown", _descriptor, this);
  56. _initializerDefineProperty(this, "dayFormat", _descriptor2, this);
  57. _initializerDefineProperty(this, "timeFormat", _descriptor3, this);
  58. _initializerDefineProperty(this, "zeroize", _descriptor4, this);
  59. this.backStartTime = 0;
  60. // 进入后台开始时间
  61. this.dateDisable = void 0;
  62. // 时间能否由天数显示
  63. this.result = void 0;
  64. // 时间结果字符串
  65. /** 每秒触发事件 */
  66. this.onSecond = null;
  67. /** 倒计时完成事件 */
  68. this.onComplete = null;
  69. }
  70. replace(value) {
  71. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  72. args[_key - 1] = arguments[_key];
  73. }
  74. return value.replace(/\{(\d+)\}/g, function (m, i) {
  75. return args[i];
  76. });
  77. }
  78. /** 格式化字符串 */
  79. format() {
  80. var c = this.countDown;
  81. var date = Math.floor(c / 86400);
  82. c = c - date * 86400;
  83. var hours = Math.floor(c / 3600);
  84. c = c - hours * 3600;
  85. var minutes = Math.floor(c / 60);
  86. c = c - minutes * 60;
  87. var seconds = c;
  88. this.dateDisable = this.dateDisable || false;
  89. if (date == 0 && hours == 0 && minutes == 0 && seconds == 0) {
  90. if (this.zeroize) {
  91. this.result = this.replace(this.timeFormat, "00", "00", "00");
  92. } else {
  93. this.result = this.replace(this.timeFormat, "0", "0", "0");
  94. }
  95. } else if (date > 0 && !this.dateDisable) {
  96. var dataFormat = this.dayFormat;
  97. var index = dataFormat.indexOf("{1}");
  98. if (hours == 0 && index > -1) {
  99. dataFormat = dataFormat.substring(0, index - 1);
  100. }
  101. var df = dataFormat;
  102. if (date > 1 && dataFormat.indexOf("days") < 0) {
  103. df = df.replace("day", "days");
  104. }
  105. if (date < 2) {
  106. df = df.replace("days", "day");
  107. }
  108. this.result = this.replace(df, date, hours); // 如果天大于1,则显示 "1 Day..."
  109. } else {
  110. hours += date * 24;
  111. if (this.zeroize) {
  112. this.result = this.replace(this.timeFormat, this.coverString(hours), this.coverString(minutes), this.coverString(seconds)); // 否则显示 "01:12:24"
  113. } else {
  114. this.result = this.replace(this.timeFormat, hours, minutes, seconds);
  115. }
  116. }
  117. this.string = this.result;
  118. }
  119. /** 个位数的时间数据将字符串补位 */
  120. coverString(value) {
  121. if (value < 10) return "0" + value;
  122. return value.toString();
  123. }
  124. /** 设置时间能否由天数显示 */
  125. setDateDisable(flag) {
  126. this.dateDisable = flag;
  127. }
  128. /**
  129. * 设置倒计时时间
  130. * @param second 倒计时时间(单位秒)
  131. */
  132. setTime(second) {
  133. this.countDown = second; // 倒计时,初始化显示字符串
  134. this.timing_end();
  135. this.timing_start();
  136. this.format();
  137. }
  138. /**
  139. * 设置结束时间戳倒计时
  140. * @param timeStamp 时间戳
  141. */
  142. setTimeStamp(timeStamp) {
  143. this.countDown = (_crd && TimeUtil === void 0 ? (_reportPossibleCrUseOfTimeUtil({
  144. error: Error()
  145. }), TimeUtil) : TimeUtil).secsBetween((_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  146. error: Error()
  147. }), oops) : oops).timer.getServerTime(), timeStamp);
  148. this.timing_end();
  149. this.timing_start();
  150. this.format();
  151. }
  152. start() {
  153. if (!EDITOR) {
  154. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  155. error: Error()
  156. }), oops) : oops).message.on((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  157. error: Error()
  158. }), EventMessage) : EventMessage).GAME_SHOW, this.onGameShow, this);
  159. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  160. error: Error()
  161. }), oops) : oops).message.on((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  162. error: Error()
  163. }), EventMessage) : EventMessage).GAME_HIDE, this.onGameHide, this);
  164. }
  165. this.timing_start();
  166. this.format();
  167. }
  168. onDestroy() {
  169. if (!EDITOR) {
  170. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  171. error: Error()
  172. }), oops) : oops).message.off((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  173. error: Error()
  174. }), EventMessage) : EventMessage).GAME_SHOW, this.onGameShow, this);
  175. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  176. error: Error()
  177. }), oops) : oops).message.off((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  178. error: Error()
  179. }), EventMessage) : EventMessage).GAME_HIDE, this.onGameHide, this);
  180. }
  181. }
  182. onGameShow() {
  183. var interval = Math.floor(((_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  184. error: Error()
  185. }), oops) : oops).timer.getTime() - (this.backStartTime || (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  186. error: Error()
  187. }), oops) : oops).timer.getTime())) / 1000);
  188. this.countDown -= interval;
  189. if (this.countDown < 0) {
  190. this.countDown = 0;
  191. this.onScheduleComplete();
  192. }
  193. }
  194. onGameHide() {
  195. this.backStartTime = (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  196. error: Error()
  197. }), oops) : oops).timer.getTime();
  198. }
  199. onScheduleSecond() {
  200. this.countDown--;
  201. this.format();
  202. if (this.onSecond) this.onSecond(this.node);
  203. if (this.countDown == 0) {
  204. this.onScheduleComplete();
  205. }
  206. }
  207. onScheduleComplete() {
  208. this.timing_end();
  209. this.format();
  210. if (this.onComplete) this.onComplete(this.node);
  211. }
  212. /** 开始计时 */
  213. timing_start() {
  214. this.schedule(this.onScheduleSecond, 1);
  215. }
  216. timing_end() {
  217. this.unscheduleAllCallbacks();
  218. }
  219. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "countDown", [_dec3], {
  220. configurable: true,
  221. enumerable: true,
  222. writable: true,
  223. initializer: function initializer() {
  224. return 1000;
  225. }
  226. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "dayFormat", [_dec4], {
  227. configurable: true,
  228. enumerable: true,
  229. writable: true,
  230. initializer: function initializer() {
  231. return "{0} day";
  232. }
  233. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "timeFormat", [_dec5], {
  234. configurable: true,
  235. enumerable: true,
  236. writable: true,
  237. initializer: function initializer() {
  238. return "{0}:{1}:{2}";
  239. }
  240. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "zeroize", [_dec6], {
  241. configurable: true,
  242. enumerable: true,
  243. writable: true,
  244. initializer: function initializer() {
  245. return true;
  246. }
  247. })), _class2)) || _class) || _class));
  248. _cclegacy._RF.pop();
  249. _crd = false;
  250. }
  251. };
  252. });
  253. //# sourceMappingURL=7cfa5643c6c9738684864bc7698eb3fdbb12ba7f.js.map