/**
|
* 徐祥健<xuxj@hugeinfo.com.cn>
|
* 2018年12月19日 16:02
|
*
|
*/
|
|
|
import React from 'react';
|
// import { Modal } from 'antd-mobile';
|
import { Input, Row, Col, Button, message } from 'antd';
|
import HeadView from "../view/HeadView";
|
|
import Fetch from '../fetch';
|
export default class UpdatePWD extends React.Component {
|
constructor(props) {
|
super(props);
|
this.state = {
|
userInfo: {},
|
savedate: {}
|
};
|
}
|
|
componentDidMount() {
|
document.title = '个人中心';
|
Fetch.getUserInfo()
|
.then(res => {
|
if (res.code === 0) {
|
this.setState({ userInfo: res.data });
|
}
|
});
|
}
|
saveInputChange = ({ target: { value, name } }) => {
|
this.setState(({ savedate }) => ({
|
savedate: {
|
...savedate,
|
[name]: value
|
}
|
}))
|
}
|
|
goBack = () => {
|
this.props.history.goBack();
|
};
|
submit = () => {
|
const { savedate, userInfo } = this.state;
|
|
if (!savedate.userPassword) {
|
this.setState({
|
loading: false
|
});
|
return message.warning("旧密码不能为空");
|
} else {
|
if (userInfo.userPassword != btoa(savedate.userPassword)) {
|
return message.warning("旧密码不正确");
|
}
|
}
|
|
if (savedate.userNewPassword == savedate.userNewPasswordA) {
|
var regex = new RegExp('^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,20}$');
|
if (!regex.test(savedate.userNewPassword)) {
|
this.setState({
|
loading: false
|
});
|
return message.warning("新密码不符合规则");
|
} else {
|
userInfo.userPassword = savedate.userNewPassword;
|
}
|
} else {
|
return message.warning("两次密码输入不同");
|
}
|
Fetch.saveUser(userInfo)
|
.then(res => {
|
if (res.code === 0) {
|
message.success("修改成功!");
|
this.goBack();
|
} else {
|
message.error(res.msg, 2);
|
}
|
});
|
};
|
|
render() {
|
const { userInfo } = this.state;
|
return (
|
<div className="app-page">
|
<HeadView history={this.props.history} />
|
<div style={{ border: 20, margin: 20, padding: 32, flex: 1, background: '#fff', lineHeight: '3' }} >
|
<Row gutter={16}>
|
<Col className="gutter-row" span={6} >
|
用户名:
|
</Col>
|
<Col className="gutter-row" span={18}>
|
<Input style={{ width: "600px" }} value={userInfo.qywxUsername} readOnly />
|
</Col>
|
<Col className="gutter-row" span={6} >
|
旧密码:
|
</Col>
|
<Col className="gutter-row" span={18}>
|
<Input placeholder="请输入旧密码" style={{ width: "600px" }} name='userPassword' onChange={this.saveInputChange} />
|
</Col>
|
<Col className="gutter-row" span={6} >
|
新密码:
|
</Col>
|
<Col className="gutter-row" span={18}>
|
<Input placeholder="请输入新密码" style={{ width: "600px" }} name='userNewPassword' onChange={this.saveInputChange} />
|
<p style={{ lineHeight: 'initial', fontSize: '12px', color: '#1790FF' }}>密码规则:在数字,大写字母,小写字母,特殊字符四选三组成的密码强度,且长度在8到20个字符之间</p>
|
</Col>
|
<Col className="gutter-row" span={6} >
|
再次输入新密码:
|
</Col>
|
<Col className="gutter-row" span={18}>
|
<Input placeholder="请再次输入新密码" style={{ width: "600px" }} name='userNewPasswordA' onChange={this.saveInputChange} />
|
</Col>
|
</Row>
|
<Row gutter={16}>
|
<div>
|
<Button type="primary"
|
className="app-btn"
|
onClick={this.submit}
|
>
|
提交
|
</Button>
|
<Button className="app-btn"
|
onClick={this.goBack}>
|
返回
|
</Button>
|
</div>
|
</Row>
|
</div>
|
</div>
|
);
|
}
|
|
}
|