login.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. var loginPage = new Vue({
  2. el: "#loginPage",
  3. mixins: [cmSysVitaMixins,loginMixins],
  4. data: {
  5. maxtime:60,
  6. loginLoading: false,
  7. qrCodeLogin: false,
  8. rule:{
  9. 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}$)",
  10. password: "^[^\\u4e00-\\u9fa5]{6,30}$",
  11. phone: '^\\d{6,12}$',
  12. code: '^\\d{6}$',
  13. mobile:'^1[1-9][0-9]{9}$'
  14. },
  15. userData: {
  16. account: '',
  17. email: '',
  18. phone: '',
  19. name: '',
  20. userName: '',
  21. userId: '',
  22. spId: '',
  23. clubId: '',
  24. shopId: '',
  25. identity: '',
  26. permission: '',
  27. token: ''
  28. },
  29. applyUse:{
  30. clubId: '',
  31. shopId: '',
  32. token:'',
  33. },
  34. isWeChat: false,
  35. text:'',
  36. stautsfalse:false,
  37. infofalse:false,
  38. isSlideFinishState:true,
  39. loginTabs:0,
  40. mobilCount:0,
  41. mobileCodeText:'获取验证码',
  42. mobilTime:null,
  43. isMobileDisabled:false,
  44. slideVerify:null
  45. },
  46. computed: {
  47. },
  48. methods: {
  49. handleTabsClick(index){
  50. const _self = this;
  51. this.loginTabs = index;
  52. clearAllErrorTxt($('input'));
  53. if(index === 1){
  54. this.isSlideFinishState = true
  55. this.initSlideVerify()
  56. }
  57. },
  58. handleHideBg(){
  59. this.stautsfalse=false;
  60. },
  61. userUpdataeStatus(response){// 更新登录
  62. const _self = this;
  63. _self.loginLoading = false;
  64. if(response.code === 0){
  65. _self.userData = {
  66. account: response.data.account,
  67. email: response.data.email,
  68. phone: response.data.bindMobile,
  69. name: response.data.name,
  70. userName: response.data.userName,
  71. userId: response.data.userId,
  72. spId: response.data.serviceProviderId,
  73. clubId: response.data.clubId,
  74. shopId: response.data.shopId,
  75. userIdentity: response.data.userIdentity,
  76. permission: response.data.userPermission,
  77. token: response.data.token,
  78. vipFlag: response.data.vipFlag,
  79. firstClubType: response.data.firstClubType,
  80. listingFee:response.data.listingFee,
  81. shopIsOrder:response.data.shopIsOrder
  82. };
  83. _self.setStorages( _self.userData);
  84. // 登录成功页面跳转
  85. var loginBeforePath = getBaseCookie("loginBeforePath");
  86. if (loginBeforePath && loginBeforePath!=='undefined' && loginBeforePath.indexOf('.html')>0) {
  87. delBaseCookie("loginBeforePath");
  88. window.location.href = loginBeforePath;
  89. } else if (_self.userData.userIdentity*1 === 3) {
  90. location.href = '/supplier/dashboard.html';
  91. } else if (_self.userData.userIdentity*1 === 2 || _self.userData.userIdentity*1 === 4) {
  92. location.href = '/user/dashboard.html';
  93. } else {
  94. location.href="/index.html";
  95. }
  96. } else if(response.code === '-3'){//审核未通过
  97. _self.text =response.msg;
  98. _self.stautsfalse = true;
  99. _self.infofalse = true;
  100. _self.applyUse = {
  101. userId: response.data.userId,
  102. shopId: response.data.shopId,
  103. token: response.data.token
  104. };
  105. }else if(response.code === '-2'){
  106. _self.stautsfalse = true;
  107. _self.text =response.msg;
  108. }else {// 登录失败
  109. CAIMEI.Alert(response.msg,'确定',false);
  110. }
  111. },
  112. toQrCodeLogin(){//切换微信登录二维码
  113. const _self = this;
  114. let timeClock = null;
  115. this.qrCodeLogin = true;
  116. UserApi.ToWechatLogin({},function(response){
  117. const wxLogin = new WxLogin({
  118. self_redirect: true,
  119. id: "qrCodeWrap",
  120. appid: response.data.appId,
  121. scope: 'snsapi_login',
  122. redirect_uri: response.data.redirectUri,
  123. state: response.data.state,
  124. style: "black",
  125. href: "https://www.caimei365.com/css/base/base.pc.css"
  126. });
  127. timeClock = setInterval(function(){
  128. _self.maxtime--;
  129. if (_self.maxtime === 0) {
  130. clearInterval(timeClock);
  131. }
  132. },1000);
  133. _self.getWrchatStatusData({state:response.data.state})
  134. });
  135. },
  136. getWrchatStatusData(params){//轮询查询用户是否扫描过二维码登录
  137. const _self = this;
  138. let timer = null;
  139. UserApi.ToWechatPolling(params,function(response){
  140. if(response.code === -90){
  141. if(_self.maxtime === 0){
  142. clearInterval(timer);
  143. _self.maxtime = 60;
  144. $('#qrCodeWrap').append('<div class="model"><div class="refresh-div"><img class="refresh" src="/img/base/shua.png" alt=""><p>二维码已失效,点击刷新</p></div></div>');
  145. $('#qrCodeWrap .model').click(function () {
  146. $(this).remove();
  147. _self.toQrCodeLogin();
  148. })
  149. }else{
  150. timer = setTimeout(function(){
  151. _self.getWrchatStatusData(params);
  152. },3000)
  153. }
  154. }else {
  155. clearTimeout(timer); //清理定时任务
  156. if(response.code === 0){
  157. _self.userData = {
  158. account: response.data.account,
  159. email: response.data.email,
  160. phone: response.data.bindMobile,
  161. name: response.data.name,
  162. userName: response.data.userName,
  163. userId: response.data.userId,
  164. spId: response.data.serviceProviderId,
  165. clubId: response.data.clubId,
  166. shopId: response.data.shopId,
  167. userIdentity: response.data.userIdentity,
  168. permission: response.data.userPermission,
  169. token: response.data.token,
  170. unionId:response.data.unionId,
  171. firstClubType:response.data.firstClubType,
  172. vipFlag: response.data.vipFlag,
  173. listingFee:response.data.listingFee,
  174. shopIsOrder:response.data.shopIsOrder
  175. };
  176. _self.setStorages( _self.userData);
  177. // 登录成功页面跳转
  178. var loginBeforePath = getBaseCookie("loginBeforePath");
  179. if (loginBeforePath && loginBeforePath!=='undefined' && loginBeforePath.indexOf('.html')>0) {
  180. delBaseCookie("loginBeforePath");
  181. window.location.href = loginBeforePath;
  182. } else if (_self.userData.userIdentity*1 === 3) {
  183. location.href = '/supplier/dashboard.html';
  184. } else if (_self.userData.userIdentity*1 === 2 || _self.userData.userIdentity*1 === 4) {
  185. location.href = '/user/dashboard.html';
  186. } else {
  187. location.href="/index.html";
  188. }
  189. }else if(response.code === -4){
  190. _self.userData = {
  191. account: response.data.account,
  192. email: response.data.email,
  193. phone: response.data.bindMobile,
  194. name: response.data.name ? response.data.name : response.data.userName,
  195. userName: response.data.userName,
  196. userId: response.data.userId,
  197. spId: response.data.serviceProviderId,
  198. clubId: response.data.clubId,
  199. shopId: response.data.shopId,
  200. userIdentity: response.data.userIdentity,
  201. permission: response.data.userPermission,
  202. token: response.data.token,
  203. unionId:response.data.unionId,
  204. listingFee:response.data.listingFee,
  205. shopIsOrder:response.data.shopIsOrder
  206. };
  207. _self.setStorages( _self.userData);
  208. setTimeout(function(){
  209. window.location.href = '/bind.html';
  210. },1000);
  211. }else if(response.code === '-3'){//审核未通过
  212. _self.text ='您的供应商账号审核未通过,原因:图片模糊,营业执照错误,审核人员在后台填写的内容';
  213. _self.stautsfalse = true;
  214. _self.infofalse = true;
  215. _self.applyUse = {
  216. userId: response.data.userId,
  217. shopId: response.data.shopId,
  218. token: response.data.token
  219. };
  220. console.log(_self.applyUse);
  221. }else if(response.code === '-2'){
  222. _self.stautsfalse = true;
  223. _self.text ='您的供应商账号正在加速审核中,审核通过后即可登录';
  224. }else{
  225. CAIMEI.Alert(response.msg,'确定',false);
  226. }
  227. }
  228. });
  229. },
  230. handleWeChatLogin(){
  231. // 微信公众号授权登录
  232. if (this.isWeChat) {
  233. // 微信浏览器自动授权登录
  234. var urlForWeChat = 'https://www.caimei365.com/we_chat/redirect_uri.html';
  235. $.get(coreServer+'/user/login/auth/link?mode=2&redirectUri='+urlForWeChat, function(r){
  236. if(r.code===0 && r.data){
  237. setBaseCookie("weChatAutoLogin", 2);
  238. window.location.href = r.data;
  239. }
  240. });
  241. }
  242. },
  243. toNormalLogin(){
  244. this.qrCodeLogin = false;
  245. },
  246. showPassword(event) {
  247. const el = event.currentTarget;
  248. const pwdEle = $(el).siblings('input');
  249. if(pwdEle.attr('type') === 'password') {
  250. $(el).addClass('on');
  251. pwdEle.attr('type','text');
  252. } else {
  253. $(el).removeClass('on');
  254. pwdEle.attr('type','password');
  255. }
  256. },
  257. blurHandle(event) { // 失去焦点校验
  258. const el = event.currentTarget;
  259. verifyHandle(el);
  260. },
  261. SetSoragesInfo(data){
  262. localStorage.setItem('APPLY_INFO',JSON.stringify(data));
  263. },
  264. setStorages(data){//存储本地数据
  265. localStorage.setItem('userInfo',JSON.stringify(data));
  266. },
  267. information(){
  268. window.location.href='/supplier/information.html';
  269. this.SetSoragesInfo( this.applyUse);
  270. },
  271. initSlideVerify(){
  272. const _self = this
  273. this.$nextTick(function (){
  274. const SlideVerifyPlug = window.slideVerifyPlug;
  275. $('#verify-wrap').html('')
  276. const slideVerify = new SlideVerifyPlug('#verify-wrap', {
  277. wrapWidth: '350',//设置 容器的宽度 ,不设置的话,会设置成100%,需要自己在外层包层div,设置宽度,这是为了适应方便点;
  278. initText: '请向右滑动滑块', //设置 初始的 显示文字
  279. sucessText: '验证通过',//设置 验证通过 显示的文字
  280. getSuccessState: function (res) {
  281. //当验证完成的时候 会 返回 res 值 true,只留了这个应该够用了
  282. if (slideVerify.slideFinishState) {
  283. $('.value').html(slideVerify.slideFinishState)
  284. $('#resetBtn').removeClass('prohibit')
  285. _self.isSlideFinishState = false;
  286. }
  287. }
  288. });
  289. })
  290. }
  291. },
  292. created: function () {
  293. const userAgent = navigator.userAgent.toLowerCase();
  294. this.isWeChat = userAgent.match(/MicroMessenger/i);
  295. this.initSlideVerify();
  296. },
  297. mounted: function () {
  298. const _self = this;
  299. $('body').on("focus",'[needverify]:visible',function(){
  300. $(this).siblings('.errTips').removeClass("show").siblings('.checked').removeClass("show");
  301. });
  302. //enter键登录
  303. if(!_self.isSlideFinishState){
  304. $(document).keyup(function (e) {
  305. var e = e || event;
  306. e.stopPropagation();
  307. if (e.keyCode === 13) {
  308. _self.loginSubmit();
  309. }
  310. });
  311. }
  312. }
  313. });