king
2025-05-23 24842b40de5cd60700bf69dfd38a0332f5431e36
src/tabviews/zshare/actionList/funczip/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification, message, Progress } from 'antd'
import { Button, Modal, notification, message } from 'antd'
import JSZip from 'jszip'
import { saveAs } from 'file-saver'
@@ -10,7 +10,7 @@
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
import './index.scss'
// import './index.scss'
class FuncZip extends Component {
  static propTpyes = {
@@ -21,27 +21,16 @@
  state = {
    loading: false,
    disabled: false,
    loadingNumber: '',
    loadingTotal: '',
    hidden: false,
    visible: false
    dict: window.GLOB.dict
  }
  UNSAFE_componentWillMount () {
    const { btn, selectedData } = this.props
    let disabled = false
    const { btn, selectedData, BData, disabled } = this.props
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
        if (btn.controlVals.includes(s)) {
          disabled = true
        }
      })
      this.setState({hidden: disabled && btn.control === 'hidden'})
    }
    if (this.props.disabled || disabled) {
    if (btn.controlField) {
      this.setStatus(btn, selectedData || [], BData, disabled)
    } else if (disabled) {
      this.setState({disabled: true})
    }
  }
@@ -51,25 +40,12 @@
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData } = this.props
    const { btn } = this.props
    let disabled = false
    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制
        nextProps.selectedData.forEach(item => {
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (btn.controlVals.includes(s)) {
            disabled = true
          }
        })
      }
      this.setState({hidden: disabled && btn.control === 'hidden'})
    }
    if (nextProps.disabled || disabled) {
      this.setState({disabled: true})
    if (btn.controlField) {
      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
    } else {
      this.setState({disabled: false})
      this.setState({disabled: nextProps.disabled === true})
    }
  }
@@ -84,40 +60,74 @@
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
  }
  setStatus = (btn, data, BData, disprop) => {
    let disabled = false
    let hidden = false
    if (btn.control !== 'parent') {
      if (data.length > 0) {
        data.forEach(item => {
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (btn.controlVals.includes(s)) {
            disabled = true
          }
        })
      } else if (btn.controlVals.includes('')) {
        disabled = true
      }
    } else {
      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
        hidden = true
      } else {
        let s = BData[btn.controlField] + ''
        if (btn.controlVals.includes(s)) {
          hidden = true
        }
      }
    }
    if (disabled && btn.control === 'hidden') {
      hidden = true
    }
    if (disprop) {
      disabled = true
    }
    this.setState({hidden, disabled})
  }
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record, type) => {
    const { BID, btn, selectedData, setting } = this.props
    const { loading, disabled } = this.state
  actionTrigger = (triggerId, record, type, lid) => {
    const { BID, btn, selectedData, setting, LID } = this.props
    const { loading, disabled, dict } = this.state
    if (loading || disabled) return
    if (triggerId && btn.uuid !== triggerId) return
    if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
    let data = record || selectedData || []
    if (setting.supModule && !BID) {
      notification.warning({
        top: 92,
        message: '需要上级主键值!',
        message: setting.supModTip || dict['sup_key_req'] || '需要上级主键值!',
        duration: 5
      })
      return
    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
      return
    }
    let data = record || selectedData || []
    if (btn.Ot !== 'notRequired' && data.length === 0) {
    } else if (btn.Ot !== 'notRequired' && data.length === 0) {
      notification.warning({
        top: 92,
        message: '请选择行!',
        message: dict['select_row'] || '请选择行!',
        duration: 5
      })
      return
    } else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
      notification.warning({
        top: 92,
        message: '请选择单行数据!',
        message: dict['select_single_row'] || '请选择单行数据!',
        duration: 5
      })
      return
@@ -325,13 +335,15 @@
    const { btn } = this.props
    this.setState({
      loading: false,
      loadingNumber: '',
      loadingTotal: ''
      loading: false
    })
    
    if (btn.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn)
    }
    if (btn.execSuccess === 'popclose' && btn.$tabId) { // 标签关闭刷新
      MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
@@ -340,100 +352,84 @@
   */
  execError = (res) => {
    const { btn } = this.props
    const { dict } = this.state
    this.setState({
      loading: false,
      loadingNumber: '',
      loadingTotal: ''
      loading: false
    })
    if (res.ErrCode === '01') {
      message.error('未获取到下载文件。')
      message.error(dict['exc_fail'] || '未获取到下载文件。')
      return
    } else if (res.ErrCode === '02') {
      Modal.error({
        title: '部分文件下载失败:1、请检查文件路径是否正确,2、请检查文件是否跨域。',
        title: dict['exc_fail'] || '部分文件下载失败:1、请检查文件路径是否正确,2、请检查文件是否跨域。',
        okText: dict['got_it'] || '知道了'
      })
      return
    } else if (res.ErrCode === '03') {
      Modal.error({
        title: '文件下载失败:1、请检查文件路径是否正确,2、请检查文件是否跨域。',
        title: dict['exc_fail'] || '文件下载失败:1、请检查文件路径是否正确,2、请检查文件是否跨域。',
        okText: dict['got_it'] || '知道了'
      })
      return
    } else if (res.ErrCode === 'E') {
      Modal.error({
        title: res.message || res.ErrMesg,
        title: res.message || dict['exc_fail'] || '执行失败!',
        okText: dict['got_it'] || '知道了'
      })
    } else if (res.ErrCode === 'N') {
      notification.error({
        top: 92,
        message: res.message || res.ErrMesg,
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: 10
      })
    } else if (res.ErrCode === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: res.message || res.ErrMesg,
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: 10
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || res.ErrMesg)
      message.error(res.message || dict['exc_fail'] || '执行失败!')
    }
    if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn)
    }
    if (btn.execError === 'popclose' && btn.$tabId) { // 标签关闭刷新
      MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
  render() {
    const { btn } = this.props
    const { loading, disabled, hidden, loadingNumber, loadingTotal } = this.state
    const { loading, disabled, hidden } = this.state
    if (hidden) return null
    let label = ''
    let icon = ''
    let type = 'link'
    let className = ''
    if (btn.show === 'button') {
      label = btn.label
      icon = btn.icon || ''
    } else if (btn.show === 'link') {
      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
      icon = ''
    if (btn.show === 'link') {
      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
    } else if (btn.show === 'icon') {
      icon = btn.icon || ''
    } else if (!btn.$toolbtn) {
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
      label = !loading ? <MkIcon type={btn.icon} /> : null
    } else {
      type = ''
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
      label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span>
    }
    
    if (loadingNumber && !loadingTotal && btn.$toolbtn && (!btn.show || btn.show === 'button')) {
      label = (loadingNumber && !loadingTotal ? `(${loadingNumber})` : '') + btn.label
    }
    return (
      <>
        <Button
          type={type}
          title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
          loading={loading}
          disabled={disabled}
          style={btn.style}
          icon={icon}
          className={className}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{label}</Button>
        {loadingTotal ? <Progress className="mk-button-progress" percent={(loadingTotal - loadingNumber) / loadingTotal * 100} size="small" showInfo={false} /> : null}
      </>
      <Button
        type="link"
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
        loading={loading}
        disabled={disabled}
        style={btn.style}
        className={btn.hover || ''}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
    )
  }
}