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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import Taro, { Component, Config } from '@tarojs/taro';
import { ComponentClass } from 'react';
import { View, Input, Image, Button } from '@tarojs/components';
import Vcode from '../../components/Vcode/Vcode';
import pwdHideIcon from '../../images/login/setting_invisible_icon@2x.png';
import pwdShowIcon from '../../images/login/setting_see_icon@2x.png';
import ToastBox from '../../components/ToastBox/ToastBox';
import './ResetPwd.scss';
import { changePwdByCellphone } from '../../api/customer';
import { replaceIllegalPwd } from '../../utils/pwd';
type PageOwnProps = {};
type PageState = {
cellphone: string;
vcode: string;
pwd: string;
checkPwd: string;
showPwd: boolean;
showCheckPwd: boolean;
};
interface ResetPwd {
props: PageOwnProps;
state: PageState;
}
class ResetPwd extends Component {
config: Config = {
navigationBarTitleText: '找回APP登陆密码',
};
constructor(props: PageOwnProps) {
super(props);
this.state = {
cellphone: '',
vcode: '',
pwd: '',
checkPwd: '',
showPwd: false,
showCheckPwd: false,
};
}
setPwdValue(key: string, value: string) {
let val = replaceIllegalPwd(value);
this.setState({
[key]: val,
});
return val;
}
togglePwdBox() {
this.setState(({ showPwd }: PageState) => ({
showPwd: !showPwd,
}));
}
togglePwdCheckBox() {
this.setState(({ showCheckPwd }: PageState) => ({
showCheckPwd: !showCheckPwd,
}));
}
validatePwdForm(): boolean {
const { pwd, checkPwd, cellphone, vcode } = this.state;
if (!cellphone || cellphone.length !== 11) {
Taro.showToast({
title: '请输入手机号码',
icon: 'none',
});
return false;
}
if (!vcode || vcode.length !== 6) {
Taro.showToast({
title: '请输入6位验证码',
icon: 'none',
});
return false;
}
if (!pwd || pwd.length < 6) {
Taro.showToast({
title: '请输入大于6位密码',
icon: 'none',
});
return false;
}
if (!checkPwd || checkPwd.length < 6) {
Taro.showToast({
title: '请输入大于6位密码',
icon: 'none',
});
return false;
}
if (pwd !== checkPwd) {
Taro.showToast({
title: '两次密码不一致',
icon: 'none',
});
return false;
}
return true;
}
resetPwd() {
if (this.validatePwdForm()) {
const { cellphone, pwd, vcode } = this.state;
changePwdByCellphone({
loginAccount: cellphone,
password: pwd,
verification: vcode,
})
.then(() => {
this.refs.ToastBox.showToast('修改成功');
console.log('回到登陆');
setTimeout(() => {
Taro.redirectTo({
url: '/pages/Login/Login',
});
}, 2000);
})
.catch(console.error);
}
}
render() {
const {
cellphone,
vcode,
showPwd,
pwd,
showCheckPwd,
checkPwd,
} = this.state;
return (
<View className='ResetPwd'>
<ToastBox ref='ToastBox' />
<View className='ResetPwd-form'>
<View className='ResetPwd-title'>请输入您的登陆手机号</View>
<View className='registerBox-item'>
<Input
className='loginBox-input'
placeholderClass='loginBox-placeholder'
placeholder='请输入注册的手机号码'
type='number'
value={cellphone}
onInput={({ detail: { value } }) => {
this.setState({
cellphone: value,
});
return value;
}}
maxLength={11}
/>
</View>
<View className='registerBox-item'>
<Input
className='loginBox-input'
placeholderClass='loginBox-placeholder'
placeholder='请输入验证码'
maxLength={6}
value={vcode}
onInput={({ detail: { value } }) => {
this.setState({
vcode: value,
});
return value;
}}
/>
<Vcode
vcode-classname='registerBox-getVcode'
ref='Vcode'
cellphone={cellphone}
/>
</View>
<View className='ResetPwd-title'>设置新密码</View>
<View className='registerBox-item'>
<Input
className='loginBox-input'
placeholderClass='loginBox-placeholder'
password={!showPwd}
placeholder='输入6-20位新密码'
maxLength={20}
value={pwd}
onInput={({ detail: { value } }) =>
this.setPwdValue('pwd', value)
}
/>
<Image
className='registerBox-pwdIcon'
src={showPwd ? pwdShowIcon : pwdHideIcon}
onClick={this.togglePwdBox}
/>
</View>
<View className='registerBox-item'>
<Input
className='loginBox-input'
placeholderClass='loginBox-placeholder'
password={!showCheckPwd}
placeholder='确认6-20位新密码'
maxLength={20}
value={checkPwd}
onInput={({ detail: { value } }) =>
this.setPwdValue('checkPwd', value)
}
/>
<Image
className='registerBox-pwdIcon'
src={showCheckPwd ? pwdShowIcon : pwdHideIcon}
onClick={this.togglePwdCheckBox}
/>
</View>
</View>
<Button className='ResetPwd-btn' onClick={this.resetPwd}>
确定
</Button>
</View>
);
}
}
export default ResetPwd as ComponentClass<PageOwnProps, PageState>;