a62597dd07a24c3714ad095eedbfc8f76f2d165c.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, ch_sign, _crd;
  4. _export("default", void 0);
  5. return {
  6. setters: [function (_cc) {
  7. _cclegacy = _cc.cclegacy;
  8. }],
  9. execute: function () {
  10. _crd = true;
  11. _cclegacy._RF.push({}, "6d031yryKRLYaiOHaXKh4Av", "sign", undefined);
  12. _export("default", ch_sign = class ch_sign {
  13. constructor() {
  14. this._sign_data = new Set();
  15. this._max = 7;
  16. this._creat_date = 0;
  17. this._sign_count = 0;
  18. this._mode = 1;
  19. }
  20. static getInstance() {
  21. if (!this._instance) this._instance = new ch_sign();
  22. return this._instance;
  23. }
  24. /**设定的签到天数*/
  25. get max_day() {
  26. return this._max;
  27. }
  28. getCreatDayCount() {
  29. if (this._creat_date == 0) {
  30. chsdk.log.warn("签到模块没有初始化");
  31. return 0;
  32. }
  33. return chsdk.date.getDiffDayNum(this._creat_date, chsdk.date.now()) + 1;
  34. }
  35. /**
  36. * 签到初始化
  37. * @param mode =1可以补签 =2不可补签
  38. * @param data 签到存档数据,可以为空为第一天
  39. * @param max_day 签到最大天数
  40. */
  41. init(mode, data, max_day) {
  42. if (max_day === void 0) {
  43. max_day = 7;
  44. }
  45. this._mode = mode;
  46. if (this._mode == 1) {
  47. if (data) {
  48. var _data$sign_list, _data$creat_date;
  49. data = data;
  50. var sign_list = (_data$sign_list = data.sign_list) != null ? _data$sign_list : [];
  51. var creat_date = (_data$creat_date = data.creat_date) != null ? _data$creat_date : chsdk.date.now();
  52. for (var i = 0; i < sign_list.length; i++) this._sign_data.add(sign_list[i]);
  53. this._sign_count = this._sign_data.size;
  54. this._creat_date = creat_date;
  55. } else {
  56. this._sign_count = 0;
  57. this._sign_data.clear();
  58. this._creat_date = chsdk.date.now();
  59. }
  60. } else {
  61. if (data) {
  62. var _data$sign_count, _data$last_date;
  63. data = data;
  64. this._sign_count = (_data$sign_count = data.sign_count) != null ? _data$sign_count : 0;
  65. this._creat_date = (_data$last_date = data.last_date) != null ? _data$last_date : 0;
  66. } else {
  67. this._sign_count = 0;
  68. this._creat_date = 0;
  69. }
  70. }
  71. this._max = max_day;
  72. }
  73. /**已签到的数据,用于存档*/
  74. getSignData() {
  75. if (this._mode == 1) {
  76. return {
  77. sign_list: Array.from(this._sign_data.keys()),
  78. creat_date: this._creat_date
  79. };
  80. } else if (this._mode == 2) {
  81. return {
  82. sign_count: this._sign_count,
  83. last_date: this._creat_date
  84. };
  85. }
  86. }
  87. /** 返回某一天的状态
  88. * 0 等待签到
  89. * 1 已经签到
  90. * 2 失效等待补签
  91. * */
  92. checkSigineState(day) {
  93. if (this._mode == 1) {
  94. if (day < 1 || day > this._max) return 0;
  95. if (this._sign_data.has(day)) return 1;
  96. var count = this.getCreatDayCount();
  97. if (count <= 0) return 0;
  98. if (day < count) return 2;
  99. } else if (this._mode == 2) {
  100. if (day <= this._sign_count) return 1;
  101. }
  102. return 0;
  103. }
  104. /**今天是否可以签到*/
  105. checkSigin() {
  106. if (this._mode == 1) {
  107. var count = this.getCreatDayCount();
  108. if (count <= 0 || count > this._max) return false;
  109. return !this._sign_data.has(count);
  110. } else if (this._mode == 2) {
  111. var _count = this._sign_count;
  112. if (_count >= this._max) return false;
  113. return !chsdk.date.isSameDate(this._creat_date, chsdk.date.now());
  114. }
  115. return false;
  116. }
  117. /**签到是否全部完成*/
  118. checkSiginComplete() {
  119. var count = this._sign_count;
  120. return count >= this._max;
  121. }
  122. /**
  123. * 是否能补签
  124. * 不能返回0,
  125. * 可以补签返回可以补签的那一天*/
  126. checkReSigin() {
  127. if (this._mode != 1) return 0;
  128. var count = this.getCreatDayCount() - 1;
  129. if (count <= 0) return 0;
  130. if (count > this._max) count = this._max;
  131. for (var i = 1; i <= count; i++) {
  132. if (!this._sign_data.has(i)) return i;
  133. }
  134. return 0;
  135. }
  136. /**签到
  137. * 失败返回 0
  138. * 成功返回签到当天
  139. */
  140. signIn() {
  141. if (!this.checkSigin()) {
  142. return 0;
  143. }
  144. if (this._mode == 1) {
  145. var day = this.getCreatDayCount();
  146. this._sign_data.add(day);
  147. this._sign_count = this._sign_data.size;
  148. return day;
  149. } else if (this._mode == 2) {
  150. this._sign_count++;
  151. this._creat_date = chsdk.date.now();
  152. return this._sign_count;
  153. }
  154. return 0;
  155. }
  156. /**补签
  157. * 失败返回 0
  158. * 成功返回补签那天
  159. */
  160. reSignIn() {
  161. if (this._mode != 1) return 0;
  162. var index = this.checkReSigin();
  163. if (index <= 0 || index > this._max) {
  164. return 0;
  165. }
  166. this._sign_data.add(index);
  167. this._sign_count = this._sign_data.size;
  168. return index;
  169. } //
  170. });
  171. ch_sign._instance = void 0;
  172. _cclegacy._RF.pop();
  173. _crd = false;
  174. }
  175. };
  176. });
  177. //# sourceMappingURL=a62597dd07a24c3714ad095eedbfc8f76f2d165c.js.map