king
2021-07-23 c7414c3cc93649479119d51b230c4b8e36884ca7
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Checkbox } from 'antd'
 
import './index.scss'
 
class MKCheckbox extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onChange: PropTypes.func
  }
 
  state = {
    defaultValue: this.props.config.initval ? this.props.config.initval.split(',').filter(Boolean) : []
  }
 
  onChange = (values) => {
    this.props.onChange(values.join(','))
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { config } = this.props
    const { defaultValue } = this.state
 
    return (
      <Checkbox.Group defaultValue={defaultValue} disabled={config.readonly} onChange={this.onChange}>
        {config.options.map(option => <Checkbox key={option.key} title={option.label} value={option.value}>{option.label}</Checkbox>)}
      </Checkbox.Group>
    )
  }
}
 
export default MKCheckbox