king
2025-05-23 24842b40de5cd60700bf69dfd38a0332f5431e36
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Input } from 'antd'
import './index.scss'
 
class CodeForm extends Component {
  static propTpyes = {
    handleSubmit: PropTypes.func,
    verify: PropTypes.object
  }
 
  state = {}
 
  handleConfirm = () => {
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          resolve(values)
        } else {
          reject(err)
        }
      })
    })
  }
 
  componentDidMount () {
    const input = document.getElementById('code')
    if (input) {
      input.focus()
    }
  }
 
  render() {
    const { verify } = this.props
    const { getFieldDecorator } = this.props.form
 
    let phone = verify.phone
    phone = phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
 
    return (
      <Form style={{margin: '0px 10px'}}>
        <Form.Item label="手机号" labelCol={{style: {width: '33%'}}} wrapperCol={{style: {display: 'inline-block', width: '55%'}}}>
          {phone}
        </Form.Item>
        <Form.Item label="验证码" help={<span style={{fontSize: '12px'}}>信息已发送,请查看手机短信。</span>} labelCol={{style: {verticalAlign: 'top',width: '33%'}}} wrapperCol={{style: {display: 'inline-block', width: '55%'}}}>
          {getFieldDecorator('code', {
            initialValue: '',
            rules: [
              {
                required: true,
                message: '请输入验证码!',
              }
            ]
          })(<Input onPressEnter={(e) => {this.props.handleSubmit()}} placeholder="验证码" />)}
        </Form.Item>
      </Form>
    )
  }
}
 
export default Form.create()(CodeForm)