a62597dd07a24c3714ad095eedbfc8f76f2d165c.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 = 7) {
  42. this._mode = mode;
  43. if (this._mode == 1) {
  44. if (data) {
  45. var _data$sign_list, _data$creat_date;
  46. data = data;
  47. const sign_list = (_data$sign_list = data.sign_list) != null ? _data$sign_list : [];
  48. const creat_date = (_data$creat_date = data.creat_date) != null ? _data$creat_date : chsdk.date.now();
  49. for (let i = 0; i < sign_list.length; i++) this._sign_data.add(sign_list[i]);
  50. this._sign_count = this._sign_data.size;
  51. this._creat_date = creat_date;
  52. } else {
  53. this._sign_count = 0;
  54. this._sign_data.clear();
  55. this._creat_date = chsdk.date.now();
  56. }
  57. } else {
  58. if (data) {
  59. var _data$sign_count, _data$last_date;
  60. data = data;
  61. this._sign_count = (_data$sign_count = data.sign_count) != null ? _data$sign_count : 0;
  62. this._creat_date = (_data$last_date = data.last_date) != null ? _data$last_date : 0;
  63. } else {
  64. this._sign_count = 0;
  65. this._creat_date = 0;
  66. }
  67. }
  68. this._max = max_day;
  69. }
  70. /**已签到的数据,用于存档*/
  71. getSignData() {
  72. if (this._mode == 1) {
  73. return {
  74. sign_list: Array.from(this._sign_data.keys()),
  75. creat_date: this._creat_date
  76. };
  77. } else if (this._mode == 2) {
  78. return {
  79. sign_count: this._sign_count,
  80. last_date: this._creat_date
  81. };
  82. }
  83. }
  84. /** 返回某一天的状态
  85. * 0 等待签到
  86. * 1 已经签到
  87. * 2 失效等待补签
  88. * */
  89. checkSigineState(day) {
  90. if (this._mode == 1) {
  91. if (day < 1 || day > this._max) return 0;
  92. if (this._sign_data.has(day)) return 1;
  93. const count = this.getCreatDayCount();
  94. if (count <= 0) return 0;
  95. if (day < count) return 2;
  96. } else if (this._mode == 2) {
  97. if (day <= this._sign_count) return 1;
  98. }
  99. return 0;
  100. }
  101. /**今天是否可以签到*/
  102. checkSigin() {
  103. if (this._mode == 1) {
  104. const count = this.getCreatDayCount();
  105. if (count <= 0 || count > this._max) return false;
  106. return !this._sign_data.has(count);
  107. } else if (this._mode == 2) {
  108. const count = this._sign_count;
  109. if (count >= this._max) return false;
  110. return !chsdk.date.isSameDate(this._creat_date, chsdk.date.now());
  111. }
  112. return false;
  113. }
  114. /**签到是否全部完成*/
  115. checkSiginComplete() {
  116. const count = this._sign_count;
  117. return count >= this._max;
  118. }
  119. /**
  120. * 是否能补签
  121. * 不能返回0,
  122. * 可以补签返回可以补签的那一天*/
  123. checkReSigin() {
  124. if (this._mode != 1) return 0;
  125. let count = this.getCreatDayCount() - 1;
  126. if (count <= 0) return 0;
  127. if (count > this._max) count = this._max;
  128. for (let i = 1; i <= count; i++) {
  129. if (!this._sign_data.has(i)) return i;
  130. }
  131. return 0;
  132. }
  133. /**签到
  134. * 失败返回 0
  135. * 成功返回签到当天
  136. */
  137. signIn() {
  138. if (!this.checkSigin()) {
  139. return 0;
  140. }
  141. if (this._mode == 1) {
  142. const day = this.getCreatDayCount();
  143. this._sign_data.add(day);
  144. this._sign_count = this._sign_data.size;
  145. return day;
  146. } else if (this._mode == 2) {
  147. this._sign_count++;
  148. this._creat_date = chsdk.date.now();
  149. return this._sign_count;
  150. }
  151. return 0;
  152. }
  153. /**补签
  154. * 失败返回 0
  155. * 成功返回补签那天
  156. */
  157. reSignIn() {
  158. if (this._mode != 1) return 0;
  159. const index = this.checkReSigin();
  160. if (index <= 0 || index > this._max) {
  161. return 0;
  162. }
  163. this._sign_data.add(index);
  164. this._sign_count = this._sign_data.size;
  165. return index;
  166. } //
  167. });
  168. ch_sign._instance = void 0;
  169. _cclegacy._RF.pop();
  170. _crd = false;
  171. }
  172. };
  173. });
  174. //# sourceMappingURL=a62597dd07a24c3714ad095eedbfc8f76f2d165c.js.map