king
2022-01-21 46f79b491173d284a4900d19e7aecf7509481438
src/tabviews/zshare/actionList/exceloutbutton/index.jsx
@@ -3,7 +3,7 @@
import moment from 'moment'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification, message, Icon } from 'antd'
import { Button, Modal, notification, message } from 'antd'
import * as XLSX from 'xlsx'
import Utils from '@/utils/utils.js'
@@ -12,24 +12,50 @@
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
// import './index.scss'
class ExcelOutButton extends Component {
  static propTpyes = {
    BID: PropTypes.string,            // 主表ID
    position: PropTypes.any,          // 按钮位置,工具栏为toolbar
    BData: PropTypes.any,             // 主表数据
    show: PropTypes.any,              // 显示样式
    Tab: PropTypes.any,               // 如果当前元素为标签时,tab为标签信息
    btn: PropTypes.object,            // 按钮
    setting: PropTypes.any,           // 页面通用设置
    updateStatus: PropTypes.func,     // 按钮状态更新
    disabled: PropTypes.any,          // 行按钮禁用
    lineId: PropTypes.any,            // 行索引+主键值,用于行按钮双击
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    excelName: '',  // 文件名
    search: '',     // 搜索条件
    loading: false  // 导出中
    loading: false, // 导出中
    hidden: false,
    disabled: false
  }
  UNSAFE_componentWillMount () {
    const { btn, BData, disabled } = this.props
    if (btn.control === 'parent') {
      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
        this.setState({hidden: true})
      } else {
        let s = BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
        }
      }
    }
    if (disabled) {
      this.setState({disabled: true})
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -39,6 +65,29 @@
  componentDidMount () {
    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    MKEmitter.addListener('returnModuleParam', this.triggerExcelout)
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, BData } = this.props
    if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
        this.setState({hidden: true})
      } else {
        let s = nextProps.BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
        }
      }
    }
    if (nextProps.disabled) {
      this.setState({disabled: true})
    } else {
      this.setState({disabled: false})
    }
  }
  componentWillUnmount () {
@@ -68,11 +117,17 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId) => {
  actionTrigger = (triggerId, record) => {
    const { setting, Tab, BID, btn } = this.props
    const { loading } = this.state
    const { loading, disabled } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    if (loading || disabled) return
    if (triggerId) {
      if (btn.uuid !== triggerId) return
      if (this.props.lineId && record && record[0] && this.props.lineId !== record[0].$$key) {
        return
      }
    }
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
@@ -819,7 +874,9 @@
      loading: false
    })
    if (btn.execSuccess !== 'never') {
    if (btn.execSuccess === 'closepoptab') {
      MKEmitter.emit('popclose')
    } else if (btn.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', [])
    }
    if (btn.switchTab && btn.switchTab.length > 0) {
@@ -863,20 +920,25 @@
      loading: false
    })
    if (btn.execError !== 'never') {
    if (btn.execError === 'closepoptab') {
      MKEmitter.emit('popclose')
    } else if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', [])
    }
  }
  render() {
    const { btn, show } = this.props
    const { loading } = this.state
    const { loading, hidden, disabled } = this.state
    if (hidden) return null
    if (show === 'actionList') {
      return (
        <Button
          className={'mk-btn mk-' + btn.class}
          icon={btn.icon}
          disabled={disabled}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
          loading={loading}
        >{btn.label}</Button>
@@ -889,7 +951,7 @@
        label = btn.label
        icon = btn.icon || ''
      } else if (show === 'link') {
        label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
        label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
        icon = ''
      } else if (show === 'icon') {
        icon = btn.icon || 'download'
@@ -903,6 +965,7 @@
          type="link"
          title={show === 'icon' ? btn.label : ''}
          loading={loading}
          disabled={disabled}
          style={btn.style}
          icon={icon}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}