king
2021-06-10 5cfe6db94c1449810a44660b299dba8e7e98e5c5
src/components/header/loginform.jsx
@@ -11,7 +11,7 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
  }
  handleConfirm = () => {
@@ -27,17 +27,23 @@
    })
  }
  handleSubmit = e => {
    // 登录参数检验
  handleSubmit = (e, key) => {
    e.preventDefault()
    this.props.handleSubmit()
    if (e.target.value) {
      if (!this.props.form.getFieldValue(key)) {
        const input = document.getElementById(key)
        input && input.focus()
        return
      }
      this.props.handleSubmit()
    } else {
      this.handleConfirm()
    }
  }
  componentDidMount () {
    const input = document.getElementById('username')
    if (input) {
      input.focus()
    }
    input && input.focus()
  }
  render() {
@@ -54,7 +60,7 @@
              prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
              placeholder={this.state.dict['login.username']}
              autoComplete="off"
              onPressEnter={this.handleSubmit}
              onPressEnter={(e) => {this.handleSubmit(e, 'password')}}
            />
          )}
        </Form.Item>
@@ -67,7 +73,7 @@
                message: this.state.dict['login.password.empty'],
              }
            ]
          })(<Input.Password onPressEnter={this.handleSubmit} placeholder={this.state.dict['login.password']} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
          })(<Input.Password onPressEnter={(e) => {this.handleSubmit(e, 'username')}} placeholder={this.state.dict['login.password']} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
        </Form.Item>
      </Form>
    )