king
2021-04-08 9a60da3f80eacbaadb98b6c9697aeffcc8affe57
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Icon, Input, Button, Checkbox, Tabs } from 'antd'
 
import './index.scss'
 
const { TabPane } = Tabs
 
class LoginTabForm extends Component {
  static propTpyes = {
    dict: PropTypes.object,
    loginWays: PropTypes.array,
  }
 
  state = {
    activeKey: 'uname_pwd',
    username: '',
    password: '',
    loginWays: [],
    smsId: '',
    verdisabled: false
  }
 
  UNSAFE_componentWillMount () {
    const { loginWays } = this.props
 
    let smsId = ''
    let _loginWays = []
    loginWays.forEach(item => {
      if (item.type === 'sms_vcode') {
        smsId = item.smsId
        _loginWays.push(item)
      } else if (item.type === 'uname_pwd') {
        _loginWays.push(item)
      }
    })
 
    this.setState({
      smsId: smsId,
      loginWays: _loginWays,
      activeKey: _loginWays[0].type,
    })
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (!is(fromJS(this.props.loginWays), fromJS(nextProps.loginWays))) {
      let smsId = ''
      let _loginWays = []
      nextProps.loginWays.forEach(item => {
        if (item.type === 'sms_vcode') {
          smsId = item.smsId
          _loginWays.push(item)
        } else if (item.type === 'uname_pwd') {
          _loginWays.push(item)
        }
      })
 
      this.setState({
        smsId: smsId,
        loginWays: _loginWays,
        activeKey: _loginWays[0].type
      })
    }
  }
 
  onChangeTab = (activeKey) => {
    this.setState({activeKey})
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { activeKey, verdisabled, loginWays } = this.state
 
    return (
      <Form className="login-edit-form">
        <Tabs type="card" activeKey={activeKey} onChange={this.onChangeTab}>
          {loginWays.map(item => (<TabPane tab={item.label} key={item.type}></TabPane>))}
        </Tabs>
        <div className="form-item-wrap">
          {activeKey === 'uname_pwd' ? <Form.Item>
            <Input
              prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
              placeholder="用户名"
              autoComplete="off"
            />
          </Form.Item> : null}
          {activeKey === 'uname_pwd' ? <Form.Item>
            <Input.Password placeholder="密码" prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />
          </Form.Item> : null}
          {activeKey === 'sms_vcode' ? <Form.Item>
            <Input
              placeholder="手机号"
              autoComplete="off"
            />
          </Form.Item> : null}
          {activeKey === 'sms_vcode' ? <Form.Item>
            <Input
              addonAfter={
                <Button type="link" className="vercode" size="small" disabled={verdisabled}>
                  获取验证码
                </Button>
              }
              placeholder="验证码"
              autoComplete="off"
            />
          </Form.Item> : null}
          {activeKey === 'uname_pwd' ? <Form.Item className="minline">
            <Checkbox>记住密码</Checkbox>
          </Form.Item> : null}
          {['uname_pwd', 'sms_vcode'].includes(activeKey) ? <Form.Item className="btn-login">
            <Button type="primary" htmlType="submit" className="login-form-button">
              登录
            </Button>
          </Form.Item> : null}
        </div>
      </Form>
    )
  }
}
 
export default LoginTabForm