king
2024-07-15 f4b9504cad034ddcdef21c2081d14a4984fcd2d3
src/menu/components/share/styleInput/index.jsx
@@ -24,14 +24,8 @@
  UNSAFE_componentWillMount () {
    const { value, options } = this.props
    let val = ''
    let unit = ''
    if (value !== undefined) {
      val = value
    }
    unit = options[0]
    let val = value || ''
    let unit = options[0]
    if (val) {
      if (val.indexOf('px') > -1) {
@@ -56,6 +50,34 @@
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.value === '' && this.state.value !== '') {
      this.setState({value: ''})
    } else if (nextProps.value && nextProps.value !== `${this.state.value}${this.state.unit}`) {
      let val = nextProps.value
      let unit = this.state.unit
      if (val) {
        if (val.indexOf('px') > -1) {
          unit = 'px'
        } else if (val.indexOf('%') > -1) {
          unit = '%'
        } else if (val.indexOf('vw') > -1) {
          unit = 'vw'
        } else if (val.indexOf('vh') > -1) {
          unit = 'vh'
        }
      }
      let _val = parseFloat(val)
      if (isNaN(_val)) {
        _val = ''
      }
      this.setState({value: _val, unit})
    }
  }
  /**
@@ -85,16 +107,17 @@
    this.setState({
      value: _val,
    }, () => {
      this.props.onChange(_val !== '' ? `${_val}${unit}` : '')
    })
    this.props.onChange(_val ? `${_val}${unit}` : '')
  }
  changeUnit = (val) => {
    const { value } = this.state
    this.setState({unit: val})
    this.props.onChange(value ? `${value}${val}` : '')
    this.setState({unit: val}, () => {
      this.props.onChange(value !== '' ? `${value}${val}` : '')
    })
  }
  render () {