Safety.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. $(function()
  2. {
  3. $verify_win = $('#verify-win');
  4. // 原帐号验证码发送
  5. $('.verify-submit, .verify-submit-win').on('click', function()
  6. {
  7. var $this = $(this);
  8. var $verify = $('#verify-img-value');
  9. var verify = '';
  10. // 是否需要先校验图片验证码
  11. if($this.data('verify') == 1)
  12. {
  13. // 开启图片验证码窗口
  14. $verify_win.modal('open');
  15. $verify.focus();
  16. return false;
  17. }
  18. // 验证码窗口操作按钮则更新按钮对象
  19. var is_win = $(this).data('win');
  20. if(is_win == 1)
  21. {
  22. $this = $('.verify-submit');
  23. // 验证码参数处理
  24. verify = $verify.val().replace(/\s+/g, '');
  25. if(verify.length < 6)
  26. {
  27. Prompt($verify.data('validation-message'));
  28. $verify.focus();
  29. return false;
  30. }
  31. }
  32. // 验证码时间间隔
  33. var time_count = parseInt($this.data('time'));
  34. // 按钮交互
  35. $this.button('loading');
  36. if(is_win == 1)
  37. {
  38. $('.verify-submit-win').button('loading');
  39. }
  40. // 发送验证码
  41. $.ajax({
  42. url:$('.verify-submit').data('url'),
  43. type:'POST',
  44. data:{"verify":verify, "type":$('form input[name="type"]').val()},
  45. dataType:'json',
  46. success:function(result)
  47. {
  48. if(result.code == 0)
  49. {
  50. var intervalid = setInterval(function()
  51. {
  52. if(time_count == 0)
  53. {
  54. $this.button('reset');
  55. if(is_win == 1)
  56. {
  57. $('.verify-submit-win').button('reset');
  58. }
  59. $this.text($this.data('text'));
  60. $verify.val('');
  61. clearInterval(intervalid);
  62. } else {
  63. var send_msg = $this.data('send-text').replace(/{time}/, time_count--);
  64. $this.text(send_msg);
  65. }
  66. }, 1000);
  67. $verify_win.modal('close');
  68. } else {
  69. $this.button('reset');
  70. if(is_win == 1)
  71. {
  72. $('.verify-submit-win').button('reset');
  73. }
  74. Prompt(result.msg);
  75. }
  76. },
  77. error:function()
  78. {
  79. $this.button('reset');
  80. if(is_win == 1)
  81. {
  82. $('.verify-submit-win').button('reset');
  83. }
  84. Prompt('网络错误');
  85. }
  86. });
  87. });
  88. // 新帐号验证码获取
  89. $('.verify-submit-new, .verify-submit-win-new').on('click', function()
  90. {
  91. var $this = $(this);
  92. var $accounts = $('#accounts');
  93. var $verify = $('#verify-img-value');
  94. var verify = '';
  95. if($accounts.hasClass('am-field-valid'))
  96. {
  97. // 是否需要先校验图片验证码
  98. if($this.data('verify') == 1)
  99. {
  100. // 开启图片验证码窗口
  101. $verify_win.modal('open');
  102. $verify.focus();
  103. return false;
  104. }
  105. // 验证码窗口操作按钮则更新按钮对象
  106. var is_win = $(this).data('win');
  107. if(is_win == 1)
  108. {
  109. $this = $('.verify-submit-new');
  110. // 验证码参数处理
  111. verify = $verify.val().replace(/\s+/g, '');
  112. if(verify.length < 6)
  113. {
  114. Prompt($verify.data('validation-message'));
  115. $verify.focus();
  116. return false;
  117. }
  118. }
  119. // 验证码时间间隔
  120. var time_count = parseInt($this.data('time'));
  121. // 按钮交互
  122. $this.button('loading');
  123. if(is_win == 1)
  124. {
  125. $('.verify-submit-win-new').button('loading');
  126. }
  127. // 发送验证码
  128. $.ajax({
  129. url:$('.verify-submit-new').data('url'),
  130. type:'POST',
  131. data:{"accounts":$accounts.val(), "verify":verify, "type":$('form input[name="type"]').val()},
  132. dataType:'json',
  133. success:function(result)
  134. {
  135. if(result.code == 0)
  136. {
  137. var intervalid = setInterval(function()
  138. {
  139. if(time_count == 0)
  140. {
  141. $this.button('reset');
  142. if(is_win == 1)
  143. {
  144. $('.verify-submit-win-new').button('reset');
  145. }
  146. $this.text($this.data('text'));
  147. $verify.val('');
  148. clearInterval(intervalid);
  149. } else {
  150. var send_msg = $this.data('send-text').replace(/{time}/, time_count--);
  151. $this.text(send_msg);
  152. }
  153. }, 1000);
  154. $verify_win.modal('close');
  155. } else {
  156. $this.button('reset');
  157. if(is_win == 1)
  158. {
  159. $('.verify-submit-win-new').button('reset');
  160. }
  161. Prompt(result.msg);
  162. }
  163. },
  164. error:function()
  165. {
  166. $this.button('reset');
  167. if(is_win == 1)
  168. {
  169. $('.verify-submit-win-new').button('reset');
  170. }
  171. Prompt('网络错误');
  172. }
  173. });
  174. } else {
  175. $verify_win.modal('close');
  176. $accounts.focus();
  177. }
  178. });
  179. });