login.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var loginPage = new Vue({
  2. el: "#loginPage",
  3. data: {
  4. maxtime:60,
  5. loginLoading: false,
  6. qrCodeLogin: false,
  7. loginAccount: '',
  8. loginPassword: '',
  9. rule:{
  10. account: "(^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$)|(^\\d{6,12}$)",
  11. password: "^[^\\u4e00-\\u9fa5]{6,30}$"
  12. },
  13. userData: {
  14. account: '',
  15. email: '',
  16. phone: '',
  17. name: '',
  18. userName: '',
  19. userId: '',
  20. spId: '',
  21. clubId: '',
  22. shopId: '',
  23. identity: '',
  24. permission: '',
  25. token: ''
  26. }
  27. },
  28. computed: {
  29. },
  30. methods: {
  31. toQrCodeLogin: function(){//切换微信登录二维码
  32. var _self = this;
  33. var timeClock = null;
  34. this.qrCodeLogin = true;
  35. UserApi.ToWechatLogin({},function(response){
  36. var wxLogin = new WxLogin({
  37. self_redirect: true,
  38. id: "qrCodeWrap",
  39. appid: response.data.AppId,
  40. scope: 'snsapi_login',
  41. redirect_uri: response.data.redirect_uri,
  42. state: response.data.state,
  43. style: "black",
  44. href: "https://www-b.caimei365.com/web/login/css/login.css"
  45. });
  46. timeClock = setInterval(function(){
  47. _self.maxtime--;
  48. if (_self.maxtime == 0) {
  49. clearInterval(timeClock);
  50. };
  51. },1000);
  52. _self.getWrchatStatusData({uuid:response.data.state})
  53. });
  54. },
  55. getWrchatStatusData:function(params){//轮询查询用户是否扫描过二维码登录
  56. var _self = this;
  57. var timer = null;
  58. UserApi.ToWechatPolling(params,function(response){
  59. if(response.code == -90){
  60. if(_self.maxtime == 0){
  61. clearInterval(timer);
  62. _self.maxtime = 60;
  63. $('#qrCodeWrap').append('<div class="model"><div class="refresh-div"><img class="refresh" src="/web/login/img/shua.png" alt=""><p>二维码已失效,点击刷新</p></div></div>');
  64. $('#qrCodeWrap .model').click(function () {
  65. $(this).remove();
  66. _self.toQrCodeLogin();
  67. })
  68. }else{
  69. timer = setTimeout(function(){
  70. _self.getWrchatStatusData(params);
  71. },3000)
  72. }
  73. }else {
  74. clearTimeout(timer); //清理定时任务
  75. if(response.code == 0){
  76. _self.userData = {
  77. account: response.data.account,
  78. email: response.data.email,
  79. phone: response.data.bindMobile,
  80. name: response.data.name,
  81. userName: response.data.userName,
  82. userId: response.data.userID,
  83. spId: response.data.serviceProviderID,
  84. clubId: response.data.clubID,
  85. shopId: response.data.shopID,
  86. identity: response.data.userIdentity,
  87. permission: response.data.userPermission,
  88. token: response.data.token
  89. };
  90. _self.setStorages( _self.userData);
  91. }else if(response.code == -4){
  92. window.location.href = 'binding.html';
  93. }
  94. }
  95. });
  96. },
  97. toNormalLogin: function(){
  98. this.qrCodeLogin = false;
  99. },
  100. showPassword: function(event) {
  101. var el = event.currentTarget;
  102. var pwdEle = $(el).siblings('input');
  103. if(pwdEle.attr('type') === 'password') {
  104. $(el).addClass('on');
  105. pwdEle.attr('type','text');
  106. } else {
  107. $(el).removeClass('on');
  108. pwdEle.attr('type','password');
  109. }
  110. },
  111. blurHandle: function(event) { // 失去焦点校验
  112. var el = event.currentTarget;
  113. verifyHandle(el);
  114. },
  115. loginSubmit: function () { // 账号登录
  116. var _self = this;
  117. var pass = verifyForm();
  118. if (this.loginLoading) { return false; }
  119. this.$nextTick(function(){
  120. if (!pass) { return false; }
  121. _self.loginLoading = true;
  122. var params = {mobileOrEmail: _self.loginAccount,password: _self.loginPassword,source: 'www'};
  123. UserApi.PostLoginAccount(params,function(response){
  124. _self.loginLoading = false;
  125. if(response.code === 0){
  126. _self.userData = {
  127. account: response.data.account,
  128. email: response.data.email,
  129. phone: response.data.bindMobile,
  130. name: response.data.name,
  131. userName: response.data.userName,
  132. userId: response.data.userID,
  133. spId: response.data.serviceProviderID,
  134. clubId: response.data.clubID,
  135. shopId: response.data.shopID,
  136. identity: response.data.userIdentity,
  137. permission: response.data.userPermission,
  138. token: response.data.token
  139. };
  140. _self.setStorages( _self.userData);
  141. // 登录成功页面跳转
  142. var beforePath = localStorage.getItem("loginBeforePath");
  143. if (beforePath) {
  144. window.location.href = beforePath;
  145. }else{
  146. window.location.href = '/index.html';
  147. }
  148. } else {// 登录失败
  149. alertInfo(response.msg);
  150. }
  151. });
  152. });
  153. },
  154. setStorages:function(data){//存储本地数据
  155. localStorage.setItem('userInfo',JSON.stringify(data));
  156. }
  157. },
  158. created: function () {
  159. },
  160. mounted: function () {
  161. var _self = this;
  162. $('body').on("focus",'[needverify]:visible',function(){
  163. $(this).siblings('.errTips').removeClass("show").siblings('.checked').removeClass("show");
  164. });
  165. //enter键登录
  166. $(document).keyup(function (e) {
  167. var e = e || event;
  168. e.stopPropagation();
  169. if (e.keyCode === 13) {
  170. _self.loginSubmit();
  171. }
  172. });
  173. }
  174. });