import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Input } from 'antd'
|
import { UserOutlined, LockOutlined } from '@ant-design/icons'
|
import './index.scss'
|
|
class HeaderLoginForm extends Component {
|
static propTpyes = {
|
handleSubmit: PropTypes.func
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.cloudusername = values.cloudusername.replace(/\t+|\v+|\s+/g, '')
|
values.cloudpassword = values.cloudpassword.replace(/\t+|\v+|\s+/g, '')
|
resolve(values)
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
handleSubmit = (e, key) => {
|
e.preventDefault()
|
if (e.target.value) {
|
if (!this.props.form.getFieldValue(key)) {
|
const input = document.getElementById(key)
|
if (input) {
|
input.focus()
|
}
|
return
|
}
|
this.props.handleSubmit()
|
} else {
|
this.handleConfirm()
|
}
|
}
|
|
componentDidMount () {
|
const input = document.getElementById('cloudusername')
|
if (input) {
|
input.focus()
|
}
|
}
|
|
render() {
|
const { getFieldDecorator } = this.props.form
|
|
return (
|
<Form style={{margin: '0px 10px'}}>
|
<Form.Item>
|
{getFieldDecorator('cloudusername', {
|
rules: [{ required: true, message: '请输入用户名' }],
|
initialValue: '',
|
})(
|
<Input
|
prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
|
placeholder="用户名"
|
autoComplete="off"
|
onPressEnter={(e) => {this.handleSubmit(e, 'cloudpassword')}}
|
/>
|
)}
|
</Form.Item>
|
<Form.Item>
|
{getFieldDecorator('cloudpassword', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: '请输入密码',
|
}
|
]
|
})(<Input.Password onPressEnter={(e) => {this.handleSubmit(e, 'cloudusername')}} placeholder="密码" prefix={<LockOutlined style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
|
</Form.Item>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(HeaderLoginForm)
|