forked from nsjcy/frontEnd/nsjcy

liuwh
2020-05-29 2fdc3dc444a2f8199866780205c0fa4b5ac40522
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
/**
 * 徐祥健<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>
    );
  }
 
}