useModal.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_store_index = require("../store/index.js");
  4. const sheep_helper_index = require("../helper/index.js");
  5. const sheep_helper_test = require("../helper/test.js");
  6. const sheep_api_member_auth = require("../api/member/auth.js");
  7. const sheep_index = require("../index.js");
  8. const sheep_api_member_signin = require("../api/member/signin.js");
  9. let time = 30;
  10. let timer = null;
  11. async function onSign() {
  12. console.log("onSign");
  13. const {
  14. code,
  15. data
  16. } = await sheep_api_member_signin.SignInApi.createSignInRecord();
  17. if (code === 0) {
  18. showSignUpModal(data);
  19. }
  20. if (timer) {
  21. clearInterval(timer);
  22. }
  23. common_vendor.index.setStorageSync("isRun", false);
  24. common_vendor.index.setStorageSync("isSign", true);
  25. }
  26. function resetSignStatusIfNeeded() {
  27. const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
  28. const lastCheckDate = common_vendor.index.getStorageSync("lastCheckDate");
  29. if (today !== lastCheckDate) {
  30. common_vendor.index.setStorageSync("isSign", false);
  31. common_vendor.index.setStorageSync("lastCheckDate", today);
  32. }
  33. }
  34. function autoSign() {
  35. resetSignStatusIfNeeded();
  36. const isLogin = common_vendor.computed(() => sheep_index.sheep.$store("user").isLogin);
  37. if (isLogin.value) {
  38. common_vendor.index.setStorageSync("isRun", true);
  39. if (common_vendor.index.getStorageSync("isRun") && !common_vendor.index.getStorageSync("isSign")) {
  40. timer = setInterval(() => {
  41. time--;
  42. console.log("time", time);
  43. if (common_vendor.index.getStorageSync("isSign") || !isLogin.value) {
  44. console.log("已经签到了或者已经登出了 不可以在签到");
  45. cancelAutoSign();
  46. }
  47. if (time <= 0 && !common_vendor.index.getStorageSync("isSign")) {
  48. clearInterval(timer);
  49. onSign();
  50. }
  51. }, 1e3);
  52. }
  53. }
  54. }
  55. function cancelAutoSign() {
  56. if (timer) {
  57. clearInterval(timer);
  58. }
  59. time = 30;
  60. common_vendor.index.setStorageSync("isRun", false);
  61. }
  62. function showSignUpModal(obj) {
  63. sheep_store_index.$store("modal").$patch((state) => {
  64. state.signUp = true;
  65. state.signUpInfo = obj;
  66. });
  67. }
  68. function colseSignUpModal() {
  69. sheep_store_index.$store("modal").$patch((state) => {
  70. state.signUp = false;
  71. });
  72. }
  73. function showWalletModal(obj) {
  74. sheep_store_index.$store("modal").$patch((state) => {
  75. state.getWallet = true;
  76. state.getWalletInfo = obj;
  77. });
  78. }
  79. function colseWalletModal() {
  80. sheep_store_index.$store("modal").$patch((state) => {
  81. state.getWallet = false;
  82. });
  83. }
  84. function showAuthModal(type = "accountLogin", isActive = "accountLogin") {
  85. const modal = sheep_store_index.$store("modal");
  86. if (modal.auth !== "") {
  87. closeAuthModal();
  88. setTimeout(() => {
  89. modal.$patch((state) => {
  90. state.auth = type;
  91. state.isActive = isActive;
  92. });
  93. }, 100);
  94. } else {
  95. modal.$patch((state) => {
  96. state.auth = type;
  97. state.isActive = isActive;
  98. });
  99. }
  100. }
  101. function closeAuthModal() {
  102. sheep_store_index.$store("modal").$patch((state) => {
  103. state.auth = "";
  104. });
  105. }
  106. function showShareModal(spuId = 0) {
  107. sheep_store_index.$store("modal").$patch((state) => {
  108. state.share = true;
  109. state.shareInfo.spuId = spuId;
  110. });
  111. }
  112. function closeShareModal() {
  113. sheep_store_index.$store("modal").$patch((state) => {
  114. state.share = false;
  115. });
  116. }
  117. function showMenuTools() {
  118. sheep_store_index.$store("modal").$patch((state) => {
  119. state.menu = true;
  120. });
  121. }
  122. function closeMenuTools() {
  123. sheep_store_index.$store("modal").$patch((state) => {
  124. state.menu = false;
  125. });
  126. }
  127. function getSmsCode(event, mobile) {
  128. const modalStore = sheep_store_index.$store("modal");
  129. const lastSendTimer = modalStore.lastTimer[event];
  130. if (typeof lastSendTimer === "undefined") {
  131. sheep_helper_index.$helper.toast("短信发送事件错误");
  132. return;
  133. }
  134. const duration = common_vendor.dayjs().unix() - lastSendTimer;
  135. const canSend = duration >= 60;
  136. if (!canSend) {
  137. sheep_helper_index.$helper.toast("请稍后再试");
  138. return;
  139. }
  140. if (mobile && !sheep_helper_test.test.mobile(mobile)) {
  141. sheep_helper_index.$helper.toast("手机号码格式不正确");
  142. return;
  143. }
  144. let scene = -1;
  145. switch (event) {
  146. case "resetPassword":
  147. scene = 4;
  148. break;
  149. case "changePassword":
  150. scene = 3;
  151. break;
  152. case "changeMobile":
  153. scene = 2;
  154. break;
  155. case "smsLogin":
  156. scene = 1;
  157. break;
  158. }
  159. sheep_api_member_auth.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
  160. if (res.code === 0) {
  161. modalStore.$patch((state) => {
  162. state.lastTimer[event] = common_vendor.dayjs().unix();
  163. });
  164. }
  165. });
  166. }
  167. function getSmsTimer(event, mobile = "") {
  168. const modalStore = sheep_store_index.$store("modal");
  169. const lastSendTimer = modalStore.lastTimer[event];
  170. if (typeof lastSendTimer === "undefined") {
  171. sheep_helper_index.$helper.toast("短信发送事件错误");
  172. return;
  173. }
  174. const duration = common_vendor.ref(common_vendor.dayjs().unix() - lastSendTimer - 60);
  175. const canSend = duration.value >= 0;
  176. if (canSend) {
  177. return "获取验证码";
  178. }
  179. if (!canSend) {
  180. setTimeout(() => {
  181. duration.value++;
  182. }, 1e3);
  183. return -duration.value.toString() + " 秒";
  184. }
  185. }
  186. function saveAdvHistory(adv) {
  187. const modal = sheep_store_index.$store("modal");
  188. modal.$patch((state) => {
  189. if (!state.advHistory.includes(adv.imgUrl)) {
  190. state.advHistory.push(adv.imgUrl);
  191. }
  192. });
  193. }
  194. exports.autoSign = autoSign;
  195. exports.cancelAutoSign = cancelAutoSign;
  196. exports.closeAuthModal = closeAuthModal;
  197. exports.closeMenuTools = closeMenuTools;
  198. exports.closeShareModal = closeShareModal;
  199. exports.colseSignUpModal = colseSignUpModal;
  200. exports.colseWalletModal = colseWalletModal;
  201. exports.getSmsCode = getSmsCode;
  202. exports.getSmsTimer = getSmsTimer;
  203. exports.resetSignStatusIfNeeded = resetSignStatusIfNeeded;
  204. exports.saveAdvHistory = saveAdvHistory;
  205. exports.showAuthModal = showAuthModal;
  206. exports.showMenuTools = showMenuTools;
  207. exports.showShareModal = showShareModal;
  208. exports.showWalletModal = showWalletModal;