king
2023-08-10 ac1d52c46ff9019fcc93cf3d5e7ab17cf850824e
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
// import { is, fromJS } from 'immutable'
import { Switch } from 'antd'
 
import './index.scss'
 
class ColorSketch extends Component {
  static propTpyes = {
    defaultValue: PropTypes.any,
    value: PropTypes.any,
    onChange: PropTypes.func
  }
  state = {
    status: true,
  }
 
  UNSAFE_componentWillMount () {
    const { defaultValue, value } = this.props
    let initVal = 'true'
 
    if (this.props['data-__meta']) {
      initVal = this.props['data-__meta'].initialValue
    } else if (defaultValue) {
      initVal = defaultValue
    } else if (value) {
      initVal = value
    }
 
    if (initVal === 'false') {
      initVal = false
    } else {
      initVal = true
    }
    
    this.setState({status: initVal})
  }
 
  changeStatus = (val) => {
    this.setState({ status: val }, () => {
      let _val = val ? 'true' : 'false'
      this.props.onChange && this.props.onChange(_val)
    })
  }
 
  render() {
    const { status } = this.state
    return (
      <Switch checkedChildren="是" unCheckedChildren="否" checked={status} onChange={this.changeStatus} />
    )
  }
}
 
export default ColorSketch