login.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. var Login={
  2. reg_url:'/wxshare/index.php/Share/userLogin',
  3. code_url:'/wxshare/index.php/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. _this.type='reg',/* popbox.fadeOut(300), */O()
  127. }else{
  128. _this.loginWarring(data.errmsg),CapN()/* ,getCaptcha() */;
  129. return !1;
  130. }
  131. },
  132. error:function(e){
  133. console.log(e);
  134. }
  135. })
  136. }
  137. /* 图片验证码 */
  138. function getCaptcha(){
  139. $.ajax({
  140. url: _this.captcha_url,
  141. data: {},
  142. type: "GET",
  143. dataType: "jsonp",
  144. jsonp: "callback",
  145. cache: !1,
  146. success:function(data){
  147. if(data && data.errno ==0){
  148. _this.js_reg_captcha_img.attr("src",data.data.captcha+"&v=" + parseInt(Math.random() * 1e8, 10));
  149. }else{
  150. _this.loginWarring(data.errmsg);
  151. return !1;
  152. }
  153. }
  154. })
  155. }
  156. function R(){
  157. _this.doreg();
  158. }
  159. },
  160. reg:function(){
  161. this.js_reg_pop.fadeIn(300),
  162. this.type='reg',
  163. this.regVerify()
  164. },
  165. doreg:function(){
  166. var _this=this,
  167. phone=this.js_reg_phone_input.val(),
  168. code =this.js_reg_code_input.val();
  169. $.ajax({
  170. url: _this.reg_url,
  171. data: {mobile:phone,code:code},
  172. type: "GET",
  173. dataType: "json",
  174. cache: !1,
  175. success:function(data){
  176. if(data && data.errno ==0){
  177. window.location.reload();
  178. }else{
  179. _this.loginWarring(data.errmsg);
  180. return !1;
  181. }
  182. }
  183. })
  184. }
  185. }
  186. $(function(){
  187. Login.init();
  188. });