cd6fdb1e95f27bd8b1340cc00a6f38ef0acac7fe.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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(...args) {
  54. super(...args);
  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, ...args) {
  71. return value.replace(/\{(\d+)\}/g, function (m, i) {
  72. return args[i];
  73. });
  74. }
  75. /** 格式化字符串 */
  76. format() {
  77. let c = this.countDown;
  78. let date = Math.floor(c / 86400);
  79. c = c - date * 86400;
  80. let hours = Math.floor(c / 3600);
  81. c = c - hours * 3600;
  82. let minutes = Math.floor(c / 60);
  83. c = c - minutes * 60;
  84. let seconds = c;
  85. this.dateDisable = this.dateDisable || false;
  86. if (date == 0 && hours == 0 && minutes == 0 && seconds == 0) {
  87. if (this.zeroize) {
  88. this.result = this.replace(this.timeFormat, "00", "00", "00");
  89. } else {
  90. this.result = this.replace(this.timeFormat, "0", "0", "0");
  91. }
  92. } else if (date > 0 && !this.dateDisable) {
  93. let dataFormat = this.dayFormat;
  94. let index = dataFormat.indexOf("{1}");
  95. if (hours == 0 && index > -1) {
  96. dataFormat = dataFormat.substring(0, index - 1);
  97. }
  98. let df = dataFormat;
  99. if (date > 1 && dataFormat.indexOf("days") < 0) {
  100. df = df.replace("day", "days");
  101. }
  102. if (date < 2) {
  103. df = df.replace("days", "day");
  104. }
  105. this.result = this.replace(df, date, hours); // 如果天大于1,则显示 "1 Day..."
  106. } else {
  107. hours += date * 24;
  108. if (this.zeroize) {
  109. this.result = this.replace(this.timeFormat, this.coverString(hours), this.coverString(minutes), this.coverString(seconds)); // 否则显示 "01:12:24"
  110. } else {
  111. this.result = this.replace(this.timeFormat, hours, minutes, seconds);
  112. }
  113. }
  114. this.string = this.result;
  115. }
  116. /** 个位数的时间数据将字符串补位 */
  117. coverString(value) {
  118. if (value < 10) return "0" + value;
  119. return value.toString();
  120. }
  121. /** 设置时间能否由天数显示 */
  122. setDateDisable(flag) {
  123. this.dateDisable = flag;
  124. }
  125. /**
  126. * 设置倒计时时间
  127. * @param second 倒计时时间(单位秒)
  128. */
  129. setTime(second) {
  130. this.countDown = second; // 倒计时,初始化显示字符串
  131. this.timing_end();
  132. this.timing_start();
  133. this.format();
  134. }
  135. /**
  136. * 设置结束时间戳倒计时
  137. * @param timeStamp 时间戳
  138. */
  139. setTimeStamp(timeStamp) {
  140. this.countDown = (_crd && TimeUtil === void 0 ? (_reportPossibleCrUseOfTimeUtil({
  141. error: Error()
  142. }), TimeUtil) : TimeUtil).secsBetween((_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  143. error: Error()
  144. }), oops) : oops).timer.getServerTime(), timeStamp);
  145. this.timing_end();
  146. this.timing_start();
  147. this.format();
  148. }
  149. start() {
  150. if (!EDITOR) {
  151. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  152. error: Error()
  153. }), oops) : oops).message.on((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  154. error: Error()
  155. }), EventMessage) : EventMessage).GAME_SHOW, this.onGameShow, this);
  156. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  157. error: Error()
  158. }), oops) : oops).message.on((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  159. error: Error()
  160. }), EventMessage) : EventMessage).GAME_HIDE, this.onGameHide, this);
  161. }
  162. this.timing_start();
  163. this.format();
  164. }
  165. onDestroy() {
  166. if (!EDITOR) {
  167. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  168. error: Error()
  169. }), oops) : oops).message.off((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  170. error: Error()
  171. }), EventMessage) : EventMessage).GAME_SHOW, this.onGameShow, this);
  172. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  173. error: Error()
  174. }), oops) : oops).message.off((_crd && EventMessage === void 0 ? (_reportPossibleCrUseOfEventMessage({
  175. error: Error()
  176. }), EventMessage) : EventMessage).GAME_HIDE, this.onGameHide, this);
  177. }
  178. }
  179. onGameShow() {
  180. const interval = Math.floor(((_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  181. error: Error()
  182. }), oops) : oops).timer.getTime() - (this.backStartTime || (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  183. error: Error()
  184. }), oops) : oops).timer.getTime())) / 1000);
  185. this.countDown -= interval;
  186. if (this.countDown < 0) {
  187. this.countDown = 0;
  188. this.onScheduleComplete();
  189. }
  190. }
  191. onGameHide() {
  192. this.backStartTime = (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  193. error: Error()
  194. }), oops) : oops).timer.getTime();
  195. }
  196. onScheduleSecond() {
  197. this.countDown--;
  198. this.format();
  199. if (this.onSecond) this.onSecond(this.node);
  200. if (this.countDown == 0) {
  201. this.onScheduleComplete();
  202. }
  203. }
  204. onScheduleComplete() {
  205. this.timing_end();
  206. this.format();
  207. if (this.onComplete) this.onComplete(this.node);
  208. }
  209. /** 开始计时 */
  210. timing_start() {
  211. this.schedule(this.onScheduleSecond, 1);
  212. }
  213. timing_end() {
  214. this.unscheduleAllCallbacks();
  215. }
  216. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "countDown", [_dec3], {
  217. configurable: true,
  218. enumerable: true,
  219. writable: true,
  220. initializer: function () {
  221. return 1000;
  222. }
  223. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "dayFormat", [_dec4], {
  224. configurable: true,
  225. enumerable: true,
  226. writable: true,
  227. initializer: function () {
  228. return "{0} day";
  229. }
  230. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "timeFormat", [_dec5], {
  231. configurable: true,
  232. enumerable: true,
  233. writable: true,
  234. initializer: function () {
  235. return "{0}:{1}:{2}";
  236. }
  237. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "zeroize", [_dec6], {
  238. configurable: true,
  239. enumerable: true,
  240. writable: true,
  241. initializer: function () {
  242. return true;
  243. }
  244. })), _class2)) || _class) || _class));
  245. _cclegacy._RF.pop();
  246. _crd = false;
  247. }
  248. };
  249. });
  250. //# sourceMappingURL=cd6fdb1e95f27bd8b1340cc00a6f38ef0acac7fe.js.map