Showing
3 changed files
with
120 additions
and
6 deletions
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <span class="page-title">手机找回密码</span> | 4 | <span class="page-title">手机找回密码</span> |
5 | <button class="close iconfont"></button> | 5 | <button class="close iconfont"></button> |
6 | </div> | 6 | </div> |
7 | - <form class="back-mobile-form"> | 7 | + <div class="back-mobile-form"> |
8 | <div class="form-group mobile"> | 8 | <div class="form-group mobile"> |
9 | <label for="mobile" class="iconfont"></label> | 9 | <label for="mobile" class="iconfont"></label> |
10 | <select name="" id="countryCodeSelector" class="country-select"> | 10 | <select name="" id="countryCodeSelector" class="country-select"> |
@@ -24,5 +24,5 @@ | @@ -24,5 +24,5 @@ | ||
24 | </div> | 24 | </div> |
25 | <div data-geetest="{{useGeetest}}" id="js-img-check" {{#unless useGeetest}} class="full-img-verify" {{/unless}}></div> | 25 | <div data-geetest="{{useGeetest}}" id="js-img-check" {{#unless useGeetest}} class="full-img-verify" {{/unless}}></div> |
26 | <button id="backMobileResetBtn" class="back-mobile-reset-btn">重置登录密码</button> | 26 | <button id="backMobileResetBtn" class="back-mobile-reset-btn">重置登录密码</button> |
27 | - </form> | 27 | + </div> |
28 | </div> | 28 | </div> |
1 | import $ from 'yoho-jquery'; | 1 | import $ from 'yoho-jquery'; |
2 | +import tip from 'plugin/tip'; | ||
2 | import Page from 'yoho-page'; | 3 | import Page from 'yoho-page'; |
4 | +import api from '../api'; | ||
5 | +import Validate from 'plugin/validata'; | ||
6 | +const $captcha = $('#js-img-check'); | ||
7 | +const validate = new Validate($captcha, { | ||
8 | + useREM: { | ||
9 | + rootFontSize: 40, | ||
10 | + picWidth: 150 | ||
11 | + } | ||
12 | +}); | ||
13 | +const showErrTip = tip.show; | ||
3 | 14 | ||
4 | class MobileNew extends Page { | 15 | class MobileNew extends Page { |
5 | constructor() { | 16 | constructor() { |
6 | super(); | 17 | super(); |
7 | 18 | ||
8 | this.selector = { | 19 | this.selector = { |
20 | + countryCodeSelector: $('#countryCodeSelector'), | ||
9 | mobileInput: $('input[name=mobile]'), | 21 | mobileInput: $('input[name=mobile]'), |
22 | + clearMobile: $('#clearMobile'), | ||
10 | verifyCodeInput: $('input[name=verifyCode]'), | 23 | verifyCodeInput: $('input[name=verifyCode]'), |
11 | passwordInput: $('input[name=password]'), | 24 | passwordInput: $('input[name=password]'), |
12 | getVerifyCodeBtn: $('#getVerifyCodeBtn'), | 25 | getVerifyCodeBtn: $('#getVerifyCodeBtn'), |
@@ -17,12 +30,14 @@ class MobileNew extends Page { | @@ -17,12 +30,14 @@ class MobileNew extends Page { | ||
17 | } | 30 | } |
18 | 31 | ||
19 | init() { | 32 | init() { |
33 | + validate.init(); | ||
20 | this.selector.getVerifyCodeBtn.data('oneClick', false); | 34 | this.selector.getVerifyCodeBtn.data('oneClick', false); |
21 | this.bindEvents(); | 35 | this.bindEvents(); |
22 | } | 36 | } |
23 | 37 | ||
24 | bindEvents() { | 38 | bindEvents() { |
25 | this.selector.mobileInput.on('input', this.changeBtnStatus.bind(this)); | 39 | this.selector.mobileInput.on('input', this.changeBtnStatus.bind(this)); |
40 | + this.selector.clearMobile.on('click', this.clearMobile.bind(this)); | ||
26 | this.selector.verifyCodeInput.on('input', this.changeBtnStatus.bind(this)); | 41 | this.selector.verifyCodeInput.on('input', this.changeBtnStatus.bind(this)); |
27 | this.selector.passwordInput.on('input', this.changeBtnStatus.bind(this)); | 42 | this.selector.passwordInput.on('input', this.changeBtnStatus.bind(this)); |
28 | this.selector.getVerifyCodeBtn.on('click', this.getVerifyCode.bind(this)); | 43 | this.selector.getVerifyCodeBtn.on('click', this.getVerifyCode.bind(this)); |
@@ -30,17 +45,110 @@ class MobileNew extends Page { | @@ -30,17 +45,110 @@ class MobileNew extends Page { | ||
30 | } | 45 | } |
31 | 46 | ||
32 | /** | 47 | /** |
33 | - * 监听输入,改变按钮状态 | 48 | + * 清除输入的手机号 |
49 | + */ | ||
50 | + clearMobile() { | ||
51 | + this.selector.mobileInput.val(''); | ||
52 | + this.selector.clearMobile.addClass('hide'); | ||
53 | + this.selector.getVerifyCodeBtn.removeClass('active'); | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * 输入监听,改变按钮状态 | ||
34 | */ | 58 | */ |
35 | changeBtnStatus() { | 59 | changeBtnStatus() { |
36 | - console.log(this); | 60 | + // 获取验证码按钮 |
61 | + if (this.selector.mobileInput.val()) { | ||
62 | + this.selector.getVerifyCodeBtn.addClass('active'); | ||
63 | + this.selector.clearMobile.removeClass('hide'); | ||
64 | + } else { | ||
65 | + this.selector.getVerifyCodeBtn.removeClass('active'); | ||
66 | + this.selector.clearMobile.addClass('hide'); | ||
67 | + } | ||
68 | + | ||
69 | + // 登录按钮 | ||
70 | + if (this.selector.mobileInput.val() && | ||
71 | + this.selector.getVerifyCodeBtn.data('oneClick') && | ||
72 | + this.selector.verifyCodeInput.val() && | ||
73 | + this.selector.passwordInput.val()) { | ||
74 | + this.selector.backMobileResetBtn.addClass('active'); | ||
75 | + } else { | ||
76 | + this.selector.backMobileResetBtn.removeClass('active'); | ||
77 | + } | ||
37 | } | 78 | } |
38 | 79 | ||
39 | /** | 80 | /** |
81 | + * 获取验证码倒计时 | ||
82 | + */ | ||
83 | + countDown(during) { | ||
84 | + let count = during || 59; | ||
85 | + let itime; | ||
86 | + | ||
87 | + this.selector.getVerifyCodeBtn.removeClass('active'); | ||
88 | + | ||
89 | + itime = setInterval(() => { | ||
90 | + if (count === 0) { | ||
91 | + this.selector.getVerifyCodeBtn.text('重新获取').addClass('active'); | ||
92 | + clearInterval(itime); | ||
93 | + } else { | ||
94 | + this.selector.getVerifyCodeBtn.text('重新获取 (' + count-- + '秒)'); | ||
95 | + window.setCookie('count', count); | ||
96 | + | ||
97 | + if (during && parseInt(during, 10) !== 0) { | ||
98 | + this.selector.getVerifyCodeBtn.removeClass('active'); | ||
99 | + } | ||
100 | + } | ||
101 | + }, 1000); | ||
102 | + } | ||
103 | + | ||
104 | + | ||
105 | + /** | ||
40 | * 获取验证码 | 106 | * 获取验证码 |
41 | */ | 107 | */ |
42 | getVerifyCode() { | 108 | getVerifyCode() { |
43 | - console.log('1'); | 109 | + let pn = $.trim(this.selector.mobileInput.val()); |
110 | + let area = $.trim(this.selector.countryCodeSelector.val()); | ||
111 | + | ||
112 | + if (!this.selector.getVerifyCodeBtn.hasClass('active')) { | ||
113 | + return; | ||
114 | + } | ||
115 | + | ||
116 | + this.selector.getVerifyCodeBtn.data('oneClick', true); | ||
117 | + | ||
118 | + if (area && pn && api.phoneRegx[area].test(pn)) { | ||
119 | + validate.getResults().then(result => { | ||
120 | + let params = { | ||
121 | + areaCode: area.replace('+', ''), | ||
122 | + phoneNum: pn | ||
123 | + }; | ||
124 | + | ||
125 | + $.extend(params, result); | ||
126 | + | ||
127 | + this.ajax({ | ||
128 | + url: '/passport/back/sendcode', | ||
129 | + type: 'POST', | ||
130 | + data: params | ||
131 | + }).then(codeResult => { | ||
132 | + validate.type === 2 && validate.refresh(); | ||
133 | + if (codeResult.code === 200) { | ||
134 | + this.countDown(); | ||
135 | + return; | ||
136 | + } else if (codeResult.code === 409) { | ||
137 | + showErrTip(codeResult.message); | ||
138 | + } else { | ||
139 | + showErrTip(codeResult.message); | ||
140 | + } | ||
141 | + (codeResult.changeCaptcha && validate.type !== 2) && validate.refresh(); | ||
142 | + }).catch(() => { | ||
143 | + showErrTip('出错了,请重试'); | ||
144 | + validate.refresh(); | ||
145 | + }); | ||
146 | + }); | ||
147 | + } else if (!area) { | ||
148 | + showErrTip('出错了,请重新刷新页面'); | ||
149 | + } else { | ||
150 | + showErrTip('手机号格式不正确,请重新输入'); | ||
151 | + } | ||
44 | } | 152 | } |
45 | 153 | ||
46 | /** | 154 | /** |
1 | +@import "layout/img-check"; | ||
2 | + | ||
1 | @define-extend padding-75 { | 3 | @define-extend padding-75 { |
2 | padding-left: 75px; | 4 | padding-left: 75px; |
3 | padding-right: 75px; | 5 | padding-right: 75px; |
@@ -11,7 +13,11 @@ $active-gray: #444; | @@ -11,7 +13,11 @@ $active-gray: #444; | ||
11 | @extend padding-75; | 13 | @extend padding-75; |
12 | 14 | ||
13 | .active { | 15 | .active { |
14 | - background-color: $active-gray; | 16 | + background-color: $active-gray !important; |
17 | + } | ||
18 | + | ||
19 | + .hide { | ||
20 | + display: none; | ||
15 | } | 21 | } |
16 | 22 | ||
17 | .iconfont { | 23 | .iconfont { |
-
Please register or login to post a comment