login.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. var Login={
  2. reg_url:'/wxshare/Share/userLogin',
  3. code_url:'/wxshare/Share/getCode',
  4. type:'reg',
  5. checkPhone:/^0?1[3|4|5|7|8|9][0-9]\d{8}$/,
  6. init:function(){
  7. this.addEvent();
  8. },
  9. addEvent:function(){
  10. this.js_reg_phone_input=$(".js_reg_phone_input"),
  11. this.js_reg_code_input=$(".js_reg_code_input"),
  12. this.js_reg_getcode=$(".js_reg_getcode"),
  13. this.js_reg_submit=$(".js_reg_submit"),
  14. this.js_reg_pop=$("#login");
  15. //this.reg();
  16. var _this=this;
  17. $(".js-reg").on("click",function(e){
  18. console.log(11),
  19. e.preventDefault(), _this.reg()
  20. })
  21. $("#login").click(function(e) {
  22. var target = $(e.target);
  23. //点击其他地方隐藏礼物列表
  24. if(!target.is('.login_form') && !target.is(".login_form *")) {
  25. _this.closePop()
  26. }
  27. });
  28. /* _this.js_close.on("click",function(){
  29. _this.closePop()
  30. }) */
  31. },
  32. closePop:function(){
  33. this.js_reg_pop.fadeOut(300)
  34. },
  35. loginWarring:function(msg){
  36. var e = null,n;
  37. n = $(".js_"+this.type+"_warring"),
  38. n.text(msg).show(),
  39. e && (window.clearTimeout(e), e = null), e = window.setTimeout(function() {
  40. e = null, n.fadeOut(300)
  41. }, 5e3)
  42. },
  43. regVerify:function(){
  44. var _this=this;
  45. var phone=_this.js_reg_phone_input,
  46. code=_this.js_reg_code_input,
  47. getcode=_this.js_reg_getcode,
  48. reg=_this.js_reg_submit;
  49. phone.on("keyup input propertychange", function() {
  50. var e = $.trim($(this).val());
  51. e.length > 10 ? ( C() ? GY(): GN() ): GN() , W()
  52. })
  53. code.on("keyup input propertychange", function() {
  54. W()
  55. })
  56. /* captcha.on("keyup input propertychange", function() {
  57. var e = $.trim($(this).val());
  58. e.length == 4 ? CapY(): CapN()
  59. }) */
  60. /* captchaimg.on("click",function(){
  61. getCaptcha()
  62. }) */
  63. function C(){
  64. if(!_this.checkPhone.test(phone.val())){
  65. _this.loginWarring("您输入的手机号有误")
  66. return !1;
  67. }
  68. return !0;
  69. }
  70. /* 点击 获取验证码 */
  71. function G(){
  72. //getCaptcha()
  73. getCodeU()
  74. }
  75. function GY() {
  76. getcode.hasClass("login_counting") || getcode.removeClass("get_none").addClass("get_key").unbind().click(G)
  77. }
  78. function GN() {
  79. getcode.unbind().removeClass("get_key").addClass("get_none")
  80. }
  81. /* 计时器 */
  82. function O(){
  83. function r(e) {
  84. getcode.text(e)
  85. }
  86. GN()/* , CapN() */;
  87. console.log(11);
  88. var e = 60,
  89. n = window.setInterval(function() {
  90. if (e > 0) {
  91. var i = e--+"s 重新获取";
  92. getcode.addClass("login_counting"), r(i)
  93. } else window.clearInterval(n), n = null, r("获取验证码"), getcode.removeClass("login_counting"), C() && GY()
  94. }, 1e3)
  95. }
  96. /* 验证码 */
  97. /* function Cap(){
  98. _this.type='captcha',getCodeU()
  99. }
  100. function CapY(){
  101. captchasub.removeClass("get_none").addClass("get_key").unbind().click(Cap)
  102. }
  103. function CapN(){
  104. captchasub.unbind().removeClass("get_key").addClass("get_none")
  105. } */
  106. /* 注册页面 */
  107. function W(){
  108. d = $.trim(phone.val()), c = $.trim(code.val()), d.length > 10 && c.length == 6 ? Y() : N()
  109. }
  110. function Y() {
  111. reg.removeClass("get_none").addClass("get_key").unbind().click(R)
  112. }
  113. function N() {
  114. reg.unbind().removeClass("get_key").addClass("get_none")
  115. }
  116. /* 发送短信验证码 */
  117. function getCodeU(){
  118. $.ajax({
  119. url: _this.code_url,
  120. data: {mobile:phone.val()/* ,captcha:captcha.val() */},
  121. type: "GET",
  122. dataType: "json",
  123. cache: !1,
  124. success:function(data){
  125. if(data && data.errno ==0){
  126. layer.msg(data.errmsg);
  127. _this.type='reg',/* popbox.fadeOut(300), */O()
  128. }else{
  129. _this.loginWarring(data.errmsg),CapN()/* ,getCaptcha() */;
  130. return !1;
  131. }
  132. },
  133. error:function(e){
  134. console.log(e);
  135. }
  136. })
  137. }
  138. /* 图片验证码 */
  139. function getCaptcha(){
  140. $.ajax({
  141. url: _this.captcha_url,
  142. data: {},
  143. type: "GET",
  144. dataType: "jsonp",
  145. jsonp: "callback",
  146. cache: !1,
  147. success:function(data){
  148. if(data && data.errno ==0){
  149. _this.js_reg_captcha_img.attr("src",data.data.captcha+"&v=" + parseInt(Math.random() * 1e8, 10));
  150. }else{
  151. _this.loginWarring(data.errmsg);
  152. return !1;
  153. }
  154. }
  155. })
  156. }
  157. function R(){
  158. _this.doreg();
  159. }
  160. },
  161. reg:function(){
  162. this.js_reg_pop.fadeIn(300),
  163. this.type='reg',
  164. this.regVerify()
  165. },
  166. doreg:function(){
  167. var _this=this,
  168. phone=this.js_reg_phone_input.val(),
  169. code =this.js_reg_code_input.val();
  170. $.ajax({
  171. url: _this.reg_url,
  172. data: {mobile:phone,code:code},
  173. type: "GET",
  174. dataType: "json",
  175. cache: !1,
  176. success:function(data){
  177. if(data && data.errno ==0){
  178. window.location.reload();
  179. }else{
  180. _this.loginWarring(data.errmsg);
  181. return !1;
  182. }
  183. }
  184. })
  185. }
  186. }
  187. $(function(){
  188. Login.init();
  189. });