verifyPopupComponent.blade.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <style>
  2. .verify-popup-component {
  3. position: fixed;
  4. z-index: 10;
  5. top: 0;
  6. right: 0;
  7. left: 0;
  8. bottom: 0;
  9. margin: auto;
  10. width: 100%;
  11. height: 100%;
  12. background-color: transparent;
  13. }
  14. .verify-popup-component-content {
  15. position: fixed;
  16. z-index: 1;
  17. top: 0;
  18. right: 0;
  19. left: 0;
  20. bottom: 0;
  21. padding: 15px;
  22. margin: auto;
  23. width: 31.6vw;
  24. height: 300px;
  25. background-color: white;
  26. border-radius: 15px;
  27. box-sizing: border-box;
  28. box-shadow: 0 0 11px 4px rgb(0 0 0 / 8%);
  29. }
  30. .verify-popup-component-content>h4 {
  31. text-align: center;
  32. }
  33. .verify-form {
  34. width: 80%;
  35. margin: 20px auto 0;
  36. }
  37. .verify-form-row {
  38. display: flex;
  39. align-items: center;
  40. justify-content: center;
  41. }
  42. .verify-form-row:not(:last-child) {
  43. margin-bottom: 15px;
  44. }
  45. .verify-form-row .verify-form-col:first-child {
  46. flex-shrink: 0;
  47. width: 60px;
  48. }
  49. .verify-form-row .verify-form-col:nth-child(2) {
  50. flex-grow: 1;
  51. }
  52. .verify-form-row .verify-form-col:nth-child(3) {
  53. flex-grow: 1;
  54. }
  55. .verify-form-operation {
  56. margin-top: 30px;
  57. }
  58. .verify-form-operation button {
  59. margin-right: 20px;
  60. }
  61. .verify-form-code-prompt {
  62. text-align: left;
  63. color: red;
  64. }
  65. .verify-popup-component-mask {
  66. position: fixed;
  67. z-index: -1;
  68. top: 0;
  69. right: 0;
  70. left: 0;
  71. bottom: 0;
  72. margin: auto;
  73. width: inherit;
  74. height: inherit;
  75. background-color: rgba(0, 0, 0, 0.2);
  76. }
  77. </style>
  78. <div class="verify-popup-component" hidden>
  79. <div class="verify-popup-component-content">
  80. <h4>二次校验</h4>
  81. <form class="verify-form" action="">
  82. <div class="verify-form-row">
  83. <div class="verify-form-col">手机号</div>
  84. <div class="verify-form-col"> @if($verify_phone){{ $verify_phone }}@else <a href="{{ yzWebFullUrl('password.setting.index') }}">设置二次校验手机号</a> @endif</div>
  85. <div class="verify-form-col">
  86. @if($verify_phone)
  87. <button class="btn btn-success" type='button' onclick="getVerifyCode(this)"><span></span>
  88. 获取手机验证码
  89. </button>
  90. @endif
  91. </div>
  92. </div>
  93. <div class="verify-form-row verify-form-code-prompt"></div>
  94. <div class="verify-form-row">
  95. <div class="verify-form-col">验证码</div>
  96. <div class="verify-form-col"><input type="text" name="code" placeholder="请输入手机验证码"></div>
  97. </div>
  98. <div class="verify-form-row">
  99. 通过验证后{{ $verify_expire }}分钟内无需再次验证
  100. </div>
  101. <div class="verify-form-row verify-form-operation">
  102. @if($verify_phone)
  103. <button class="btn btn-success" type="button" onclick="verifyCode()">确定</button>
  104. @endif
  105. <button class="btn btn-default" type="button" onclick="hideGetVerifyCodePopup()">取消</button>
  106. </div>
  107. </form>
  108. </div>
  109. <div class="verify-popup-component-mask" onclick="hideGetVerifyCodePopup()"></div>
  110. </div>
  111. <script>
  112. let getCodeVerifyTimes = 60;
  113. let getCodeVerifyTimer = null;
  114. const verifyPhoneNumber = Number("{{$verify_phone}}");
  115. let verifyed = Boolean("{{ $is_verify }}");
  116. let expireTime = Number("{{ $expire_time }}");
  117. const codePromptEl = document.querySelector(".verify-form-code-prompt");
  118. function showGetVerifyCodePopup() {
  119. document.querySelector(".verify-popup-component").hidden = false;
  120. }
  121. function hideGetVerifyCodePopup() {
  122. document.querySelector(".verify-popup-component").hidden = true;
  123. }
  124. function getVerifyCode(buttonEl) {
  125. if (!verifyPhoneNumber) {
  126. alert("还未设置二次校验验证手机号,请前往资产密码页面设置二次校验验证手机号码");
  127. return;
  128. }
  129. codePromptEl.innerText = "";
  130. if (getCodeVerifyTimer === null) {
  131. codePromptEl.innerText = "获取验证码中";
  132. fetch("{!! yzWebFullUrl('finance.withdraw.sendCode') !!}").then(res => res.json()).then(res => {
  133. if (res.result === 0) {
  134. codePromptEl.innerText = res.msg;
  135. return;
  136. }
  137. codePromptEl.innerText = "获取验证码成功";
  138. setTimeout(() => {
  139. codePromptEl.innerText = "";
  140. }, 3000);
  141. getCodeVerifyTimer = setInterval(() => {
  142. buttonEl.innerText = --getCodeVerifyTimes + "秒后重发";
  143. if (getCodeVerifyTimes <= 0) {
  144. clearInterval(getCodeVerifyTimer);
  145. getCodeVerifyTimer = null;
  146. buttonEl.innerText = "获取手机验证码";
  147. }
  148. }, 1000);
  149. });
  150. }
  151. }
  152. function verifyCode() {
  153. const code = document.querySelector("input[name='code']").value;
  154. if (!code) {
  155. codePromptEl.innerText = "请输入手机接收到的验证码";
  156. return;
  157. }
  158. codePromptEl.innerText = "验证中,请稍后";
  159. const submitData = new FormData();
  160. submitData.append("code", code);
  161. fetch("{!! yzWebFullUrl('finance.withdraw.checkVerifyCode') !!}", {
  162. method: "POST",
  163. body: submitData
  164. }).then(res => res.json()).then(res => {
  165. if (res.result === 0) {
  166. codePromptEl.innerText = res.msg;
  167. return;
  168. }
  169. codePromptEl.innerText = "验证成功";
  170. verifyed = true;
  171. expireTime = res.data.expire;
  172. clearInterval(getCodeVerifyTimer);
  173. getCodeVerifyTimer = null;
  174. setTimeout(() => {
  175. hideGetVerifyCodePopup();
  176. }, 1000);
  177. });
  178. }
  179. </script>