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
40
41
42
43
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Switch } from 'antd'
 
import './index.scss'
 
class MKSwitch extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onChange: PropTypes.func
  }
 
  state = {
    defaultChecked: this.props.config.initval === this.props.config.openVal
  }
 
  onChange = (val) => {
    const { config } = this.props
    
    if (val) {
      this.props.onChange(config.openVal)
    } else {
      this.props.onChange(config.closeVal)
    }
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { config } = this.props
    const { defaultChecked } = this.state
 
    return (
      <Switch checkedChildren={config.openText || ''} unCheckedChildren={config.closeText || ''} defaultChecked={defaultChecked} onChange={this.onChange}/>
    )
  }
}
 
export default MKSwitch