useModal.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. console.log(lastSendTimer);
  131. if (typeof lastSendTimer === "undefined") {
  132. sheep_helper_index.$helper.toast("短信发送事件错误");
  133. return;
  134. }
  135. const duration = common_vendor.dayjs().unix() - lastSendTimer;
  136. const canSend = duration >= 60;
  137. if (!canSend) {
  138. sheep_helper_index.$helper.toast("请稍后再试");
  139. return;
  140. }
  141. if (mobile && !sheep_helper_test.test.mobile(mobile)) {
  142. sheep_helper_index.$helper.toast("手机号码格式不正确");
  143. return;
  144. }
  145. let scene = -1;
  146. switch (event) {
  147. case "resetPassword":
  148. scene = 4;
  149. break;
  150. case "changePassword":
  151. scene = 3;
  152. break;
  153. case "changeMobileOld":
  154. scene = 2;
  155. break;
  156. case "changeMobileNew":
  157. scene = 5;
  158. break;
  159. case "smsLogin":
  160. scene = 1;
  161. break;
  162. }
  163. sheep_api_member_auth.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
  164. if (res.code === 0) {
  165. modalStore.$patch((state) => {
  166. state.lastTimer[event] = common_vendor.dayjs().unix();
  167. });
  168. }
  169. });
  170. }
  171. function getSmsTimer(event, mobile = "") {
  172. const modalStore = sheep_store_index.$store("modal");
  173. const lastSendTimer = modalStore.lastTimer[event];
  174. if (typeof lastSendTimer === "undefined") {
  175. sheep_helper_index.$helper.toast("短信发送事件错误");
  176. return;
  177. }
  178. const duration = common_vendor.ref(common_vendor.dayjs().unix() - lastSendTimer - 60);
  179. const canSend = duration.value >= 0;
  180. if (canSend) {
  181. return "获取验证码";
  182. }
  183. if (!canSend) {
  184. setTimeout(() => {
  185. duration.value++;
  186. }, 1e3);
  187. return -duration.value.toString() + " 秒";
  188. }
  189. }
  190. function saveAdvHistory(adv) {
  191. const modal = sheep_store_index.$store("modal");
  192. modal.$patch((state) => {
  193. if (!state.advHistory.includes(adv.imgUrl)) {
  194. state.advHistory.push(adv.imgUrl);
  195. }
  196. });
  197. }
  198. exports.autoSign = autoSign;
  199. exports.cancelAutoSign = cancelAutoSign;
  200. exports.closeAuthModal = closeAuthModal;
  201. exports.closeMenuTools = closeMenuTools;
  202. exports.closeShareModal = closeShareModal;
  203. exports.colseSignUpModal = colseSignUpModal;
  204. exports.colseWalletModal = colseWalletModal;
  205. exports.getSmsCode = getSmsCode;
  206. exports.getSmsTimer = getSmsTimer;
  207. exports.resetSignStatusIfNeeded = resetSignStatusIfNeeded;
  208. exports.saveAdvHistory = saveAdvHistory;
  209. exports.showAuthModal = showAuthModal;
  210. exports.showMenuTools = showMenuTools;
  211. exports.showShareModal = showShareModal;
  212. exports.showWalletModal = showWalletModal;