king
2025-04-21 f3d4db769ba9b51b799d981511a710fd443d0e08
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Radio } from 'antd'
 
class MKRadio extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onChange: PropTypes.func
  }
 
  state = {
    value: '',
    config: null,
    options: []
  }
 
  UNSAFE_componentWillMount () {
    const { config } = this.props
    let value = config.initval
 
    if (value) {
      let option = null
      option= config.oriOptions[0]
      if (typeof(value) === 'string' && option && typeof(option.value) === 'number') {
        value = +value
        if (isNaN(value)) {
          value = config.initval
        }
      }
    }
 
    this.setState({
      config: fromJS(config).toJS(),
      options: fromJS(config.options).toJS(),
      value,
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { config } = this.state
 
    if (!is(fromJS(config.oriOptions), fromJS(nextProps.config.oriOptions))) {
      this.setState({
        config: fromJS(nextProps.config).toJS(),
        options: fromJS(nextProps.config.options).toJS()
      })
    }
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  onChange = (val) => {
    this.props.onChange(val)
    this.setState({value: val})
  }
 
  render() {
    const { value, options } = this.state
 
    return (
      <Radio.Group value={value} onChange={(e) => this.onChange(e.target.value)}>
        {options.map(option => <Radio key={option.key} value={option.Value}>{option.Text}</Radio>)}
      </Radio.Group>
    )
  }
}
 
export default MKRadio