king
2021-09-14 6c44bc79e5edc338b44fdc469220ddf0e3fc4028
src/tabviews/zshare/actionList/tabbutton/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Button, notification } from 'antd'
import { Button, notification, Icon } from 'antd'
import { modifyTabview } from '@/store/action'
import zhCN from '@/locales/zh-CN/main.js'
@@ -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) {
@@ -30,10 +46,24 @@
  }
  componentDidMount () {
    const { position } = this.props
    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
  }
    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})
    }
  }
@@ -47,10 +77,16 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record) => {
  actionTrigger = (triggerId, record, type) => {
    const { setting, btn, tabviews, MenuID, selectedData } = this.props
    if (triggerId && btn.uuid !== triggerId) return
    if (type === 'linkbtn' && selectedData && selectedData.length === 1) {
      if (record[0].$Index !== selectedData[0].$Index) {
        return
      }
    }
    
    let data = record || selectedData || []
@@ -62,22 +98,12 @@
        duration: 5
      })
      return
    } else if (!setting.primaryKey) {
      // 需要选择行时,校验是否设置主键
      notification.warning({
        top: 92,
        message: '未设置主键!',
        duration: 5
      })
      return
    }
    let primaryId = ''
    let _data = null
    if (btn.Ot === 'requiredSgl') {
    if (btn.Ot === 'requiredSgl' && setting.primaryKey) {
      primaryId = data[0][setting.primaryKey] || ''
      _data = data[0]
    }
    let newtab = {}
@@ -96,10 +122,18 @@
          primaryId: primaryId
        }
      }
    } else if (btn.tabTemplate === 'ThdMenu') {
    // } else if (btn.tabTemplate === 'ThdMenu') {
    } else {
      let menu = null
      if (btn.linkmenu && btn.linkmenu.length > 0) {
      if (btn.MenuID) {
        menu = {
          MenuID: btn.MenuID,
          MenuName: btn.MenuName,
          MenuNo: btn.MenuNo,
          type: btn.tabType
        }
      } else if (btn.linkmenu && btn.linkmenu.length > 0) {
        let menu_id = btn.linkmenu.slice(-1)[0]
        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
      }
@@ -117,8 +151,7 @@
        ...menu,
        selected: true,
        param: {
          BID: primaryId,
          data: _data
          $BID: primaryId
        }
      }
    }
@@ -134,42 +167,68 @@
      return tab.MenuID !== newtab.MenuID
    })
    if (tabviews.length !== tabs.length) {
      this.props.modifyTabview(fromJS(tabs).toJS())
    if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
      this.props.modifyTabview([newtab])
    } else {
      if (tabviews.length !== tabs.length) {
        this.props.modifyTabview(fromJS(tabs).toJS())
      }
      this.setState({}, () => {
        if (MenuID) {
          tabs.splice(index + 1, 0, newtab)
        } else {
          tabs.push(newtab)
        }
        this.props.modifyTabview(tabs)
      })
    }
    this.setState({}, () => {
      if (MenuID) {
        tabs.splice(index + 1, 0, newtab)
      } else {
        tabs.push(newtab)
      }
      this.props.modifyTabview(tabs)
    })
    MKEmitter.emit('openNewTab')
    if (window.GLOB.systemType === 'production') {
      MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '标签页'})
    }
  }
  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>
      )
    } else { // icon、text、 all 卡片
      let label = ''
      let icon = ''
      if (show === 'button') {
        label = btn.label
        icon = btn.icon || ''
      } else if (show === 'link') {
        label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
        icon = ''
      } else if (show === 'icon') {
        icon = btn.icon || ''
      // } else if (show === 'text') {
      } else {
        label = btn.label
      }
      return (
        <Button
          type="link"
          title={show === 'icon' ? btn.label : ''}
          style={btn.btnstyle}
          icon={show === 'text' ? '' : (btn.icon || '')}
          style={btn.style}
          disabled={disabled}
          icon={icon}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
        >{label}</Button>
      )
    }
  }