useModal.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. const sheep_store_index = require("../store/index.js");
  3. const sheep_helper_index = require("../helper/index.js");
  4. const common_vendor = require("../../common/vendor.js");
  5. const sheep_helper_test = require("../helper/test.js");
  6. const sheep_api_member_auth = require("../api/member/auth.js");
  7. function showAuthModal(type = "accountLogin") {
  8. const modal = sheep_store_index.$store("modal");
  9. console.log(modal);
  10. if (modal.auth !== "") {
  11. closeAuthModal();
  12. setTimeout(() => {
  13. modal.$patch((state) => {
  14. state.auth = type;
  15. });
  16. }, 100);
  17. } else {
  18. modal.$patch((state) => {
  19. state.auth = type;
  20. });
  21. }
  22. }
  23. function closeAuthModal() {
  24. sheep_store_index.$store("modal").$patch((state) => {
  25. state.auth = "";
  26. });
  27. }
  28. function showShareModal() {
  29. sheep_store_index.$store("modal").$patch((state) => {
  30. state.share = true;
  31. });
  32. }
  33. function closeShareModal() {
  34. sheep_store_index.$store("modal").$patch((state) => {
  35. state.share = false;
  36. });
  37. }
  38. function showMenuTools() {
  39. sheep_store_index.$store("modal").$patch((state) => {
  40. state.menu = true;
  41. });
  42. }
  43. function closeMenuTools() {
  44. sheep_store_index.$store("modal").$patch((state) => {
  45. state.menu = false;
  46. });
  47. }
  48. function getSmsCode(event, mobile) {
  49. const modalStore = sheep_store_index.$store("modal");
  50. const lastSendTimer = modalStore.lastTimer[event];
  51. if (typeof lastSendTimer === "undefined") {
  52. sheep_helper_index.$helper.toast("短信发送事件错误");
  53. return;
  54. }
  55. const duration = common_vendor.dayjs().unix() - lastSendTimer;
  56. const canSend = duration >= 60;
  57. if (!canSend) {
  58. sheep_helper_index.$helper.toast("请稍后再试");
  59. return;
  60. }
  61. if (mobile && !sheep_helper_test.test.mobile(mobile)) {
  62. sheep_helper_index.$helper.toast("手机号码格式不正确");
  63. return;
  64. }
  65. let scene = -1;
  66. switch (event) {
  67. case "resetPassword":
  68. scene = 4;
  69. break;
  70. case "changePassword":
  71. scene = 3;
  72. break;
  73. case "changeMobile":
  74. scene = 2;
  75. break;
  76. case "smsLogin":
  77. scene = 1;
  78. break;
  79. }
  80. sheep_api_member_auth.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
  81. if (res.code === 0) {
  82. modalStore.$patch((state) => {
  83. state.lastTimer[event] = common_vendor.dayjs().unix();
  84. });
  85. }
  86. });
  87. }
  88. function getSmsTimer(event, mobile = "") {
  89. const modalStore = sheep_store_index.$store("modal");
  90. const lastSendTimer = modalStore.lastTimer[event];
  91. if (typeof lastSendTimer === "undefined") {
  92. sheep_helper_index.$helper.toast("短信发送事件错误");
  93. return;
  94. }
  95. const duration = common_vendor.ref(common_vendor.dayjs().unix() - lastSendTimer - 60);
  96. const canSend = duration.value >= 0;
  97. if (canSend) {
  98. return "获取验证码";
  99. }
  100. if (!canSend) {
  101. setTimeout(() => {
  102. duration.value++;
  103. }, 1e3);
  104. return -duration.value.toString() + " 秒";
  105. }
  106. }
  107. function saveAdvHistory(adv) {
  108. const modal = sheep_store_index.$store("modal");
  109. modal.$patch((state) => {
  110. if (!state.advHistory.includes(adv.imgUrl)) {
  111. state.advHistory.push(adv.imgUrl);
  112. }
  113. });
  114. }
  115. exports.closeAuthModal = closeAuthModal;
  116. exports.closeMenuTools = closeMenuTools;
  117. exports.closeShareModal = closeShareModal;
  118. exports.getSmsCode = getSmsCode;
  119. exports.getSmsTimer = getSmsTimer;
  120. exports.saveAdvHistory = saveAdvHistory;
  121. exports.showAuthModal = showAuthModal;
  122. exports.showMenuTools = showMenuTools;
  123. exports.showShareModal = showShareModal;