useModal.js 3.4 KB

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