king
2021-07-28 137fb8ea6af2789b3238b22bac31d80bced41dfe
src/tabviews/zshare/actionList/tabbutton/index.jsx
@@ -22,7 +22,23 @@
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    disabled: false,
    primaryId: ''
  }
  UNSAFE_componentWillMount () {
    const { btn, selectedData } = this.props
    let disabled = false
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
      })
      this.setState({disabled})
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -34,6 +50,24 @@
    if (position === 'toolbar') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    }
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData } = this.props
    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
      let disabled = false
      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制
        nextProps.selectedData.forEach(item => {
          let s = item[btn.controlField] + ''
          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
        })
      }
      this.setState({disabled})
    }
  }
@@ -62,19 +96,11 @@
        duration: 5
      })
      return
    } else if (!setting.primaryKey) {
      // 需要选择行时,校验是否设置主键
      notification.warning({
        top: 92,
        message: '未设置主键!',
        duration: 5
      })
      return
    }
    let primaryId = ''
    if (btn.Ot === 'requiredSgl') {
    if (btn.Ot === 'requiredSgl' && setting.primaryKey) {
      primaryId = data[0][setting.primaryKey] || ''
    }
@@ -156,12 +182,14 @@
  render() {
    const { btn, show } = this.props
    const { disabled } = this.state
    if (show === 'actionList') {
      return (
        <Button
          className={'mk-btn mk-' + btn.class}
          icon={btn.icon}
          disabled={disabled}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{btn.label}</Button>
      )
@@ -170,7 +198,8 @@
        <Button
          type="link"
          title={show === 'icon' ? btn.label : ''}
          style={btn.btnstyle}
          style={btn.style}
          disabled={disabled}
          icon={show === 'text' ? '' : (btn.icon || '')}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>