ForgetPasswordForm.js
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, {PropTypes} from 'react';
import {Field, reduxForm, SubmissionError, getFormValues} from 'redux-form';
import InputField from './widget/reduxForm/InputField';
import {Button, Tabs,message} from 'antd';
import {connect} from 'react-redux';
const TabPane = Tabs.TabPane;
import cx from 'classnames';
import l from './loginFormLess.les';
import {doLogin, sendLoginSmsCode,changePassword,sendResetPwdSmsCode} from '../redux/actions/authed';
import {required, mobile, minValue, maxLength,number,password} from './widget/reduxForm/validate';
let i = '';
class ForgetPasswordForm extends React.Component {
constructor(props) {
super(props);
this.handleLogin = this.handleLogin.bind(this);
this.myLogin = this.myLogin.bind(this);
this.sendSmsCode = this.sendSmsCode.bind(this);
this.loop = this.loop.bind(this);
this.state = {
clickStatus: false,
countDown: 60
}
}
componentDidMount() {}
componentWillReceiveProps(nextProps) {}
componentWillUnmount() {
window.clearInterval(i);
}
handleLogin() { //立即登录
const {dispatch, submit} = this.props;
dispatch(submit());
this.setState({clickStatus: false})
}
myLogin(e) {
const {dispatch, submit} = this.props;
if (e.keyCode == 13) {
// console.log('进入回车事件');
dispatch(submit());
}
}
sendSmsCode() {
const {dispatch, formValues, touch, valid} = this.props;
const params = {
mobile: formValues.mobile,
type: 'resetpwd',
scope: 'global_access:tenant_admin'
}
const o = required(formValues.mobile);
const p = mobile(formValues.mobile);
if(!o&&!p){
dispatch(sendResetPwdSmsCode(params));
this.setState({clickStatus: true})
i = setInterval(this.loop, 1000);
}
}
loop() {
const {countDown} = this.state;
if (countDown == 0) {
this.setState({clickStatus: false, countDown: 60})
} else {
let temp = countDown - 1;
this.setState({countDown: temp})
}
}
goSubmit(){
const {dispatch,submit}= this.props;
window.clearInterval(i);
this.setState({
clickStatus: false,
countDown: 60
})
dispatch(submit());
}
render() {
const {clickStatus,countDown} = this.state;
const {handleSubmit} = this.props;
return (
<div >
<Tabs className={cx('login_tab')} defaultActiveKey="1">
<TabPane tab="重置密码" key="1">
<div className={cx(l.login_tab_content, 'login_input')}>
<InputField type='text' name='mobile' placeholder='请输入手机号' onKeyUp={this.myLogin} />
<div style={{position:'relative'}}>
<InputField type='text' name='sms_code' placeholder='请输入验证码' onKeyUp={this.myLogin}></InputField>
{!clickStatus
? <div className={cx(l.reset_verfication_code_active)} onClick={this.sendSmsCode}>获取验证码</div>
: <div className={cx(l.reset_verfication_code_inactive)}>重新发送({countDown})</div>
}
</div>
<InputField type='password' name='password' placeholder='请输入密码' onKeyUp={this.myLogin}></InputField>
<InputField type='password' name='confirmPassword' placeholder='请再次输入密码' onKeyUp={this.myLogin}></InputField>
</div>
</TabPane>
</Tabs>
<InputField type='hidden' name='tabKey'/>
<div style={{
color: '#f04134',
marginTop: '8px'
}}>{this.props.error}</div>
<Button type="primary" onClick={this.goSubmit.bind(this)}>确定</Button>
<ul className={cx(l.login_foot)}>
<li></li>
<li>
<a href="#">返回登录</a>
</li>
</ul>
</div>
)
}
}
const submitForm = (values, dispatch, props) => {
return dispatch(changePassword(values));
}
const validate = (values, props) => {
const errors = {};
if (required(values.mobile)) {
errors.mobile = required(values.mobile);
console.log(required(values.mobile))
} else if (mobile(values.mobile)) {
errors.mobile = mobile(values.mobile);
} else if (required(values.sms_code)) {
errors.sms_code = required(values.sms_code);
} else if (number(values.sms_code)) {
errors.sms_code = number(values.sms_code);
} else if (required(values.password)) {
errors.password = number(values.sms_code);
} else if (password(values.password)) {
errors.password = password(values.password);
} else if (required(values.confirmPassword)) {
errors.confirmPassword = number(values.confirmPassword);
} else if (password(values.confirmPassword)) {
errors.confirmPassword = password(values.confirmPassword);
} else if (values.password != values.confirmPassword) {
errors.confirmPassword = '两次输入的密码不一致';
}
return errors;
}
ForgetPasswordForm = reduxForm({
form: 'forget-password',
onSubmit: submitForm,
validate,
initialValues: {
'mobile':'',
'scope': 'global_access:tenant_admin',
'password': '',
}
})(ForgetPasswordForm);
const mapState = (state) => {
return {
formValues: getFormValues('forget-password')(state)
}
};
export default connect(mapState)(ForgetPasswordForm);