king
2023-03-13 d70c5b0eee48808b9a42d1f7685640f5bafc2ad3
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -45,31 +45,11 @@
  }
  UNSAFE_componentWillMount () {
    const { btn, selectedData, BData } = this.props
    let disabled = false
    const { btn, selectedData, BData, disabled } = this.props
    if (btn.control !== 'parent' && btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
      })
      this.setState({hidden: disabled && btn.control === 'hidden'})
    } else 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 (this.props.disabled || disabled) {
    if (btn.controlField) {
      this.setStatus(btn, selectedData || [], BData, disabled)
    } else if (disabled) {
      this.setState({disabled: true})
    }
  }
@@ -89,36 +69,12 @@
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData, BData } = this.props
    const { btn } = this.props
    let disabled = false
    if (btn.control !== 'parent' && 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 (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
        })
      }
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
    } else 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 || 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})
    }
  }
@@ -128,6 +84,43 @@
    }
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
    MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
  }
  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})
  }
  triggerBtnPopSubmit = (id) => {
@@ -321,6 +314,16 @@
          // 自定义打印
          if (btn.verify.printMode === 'custom') {
            result.list.forEach(cell => {
              Object.keys(cell).forEach(key => {
                let _key = key.toLowerCase()
                if (['printtype', 'printcount'].includes(_key)) {
                  cell[_key] = cell[key]
                }
              })
              cell.printType = cell.printtype || ''
              cell.printCount = +(cell.printcount || 1)
            })
            this.execCustomPrint(result.list, formdata)
            resolve(false)
            return
@@ -1121,6 +1124,8 @@
    _customScript = _customScript.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _dataresource = _dataresource.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _customScript = _customScript.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _dataresource = _dataresource.replace(/@typename@/ig, `'admin'`)
    _customScript = _customScript.replace(/@typename@/ig, `'admin'`)
    let LText = ''
@@ -1962,7 +1967,7 @@
  actionSettingError = () => {
    notification.warning({
      top: 92,
      message: this.state.dict['main.action.settingerror'],
      message: '按钮设置错误!',
      duration: 5
    })
  }
@@ -2003,7 +2008,20 @@
        this.setState({
          visible: true
        })
        if (btnconfig.setting.display === 'modal' && btnconfig.setting.moveable === 'true') {
          setTimeout(() => {
            this.setMove()
          }, 100)
        }
      }
    } else if (!btn.$old) {
      notification.warning({
        top: 92,
        message: '未获取到按钮配置信息!',
        duration: 5
      })
      this.setState({ loading: false })
    } else {
      Api.getCacheConfig({
        func: 'sPC_Get_LongParam',
@@ -2198,10 +2216,11 @@
        title={title}
        maskClosable={clickouter}
        getContainer={container}
        wrapClassName='action-modal'
        wrapClassName={'action-modal' + (btnconfig.setting.moveable === 'true' ? ' moveable-modal modal-' + btn.uuid : '')}
        visible={this.state.visible}
        confirmLoading={this.state.confirmLoading}
        width={width}
        maskStyle={btnconfig.setting.moveable === 'true' ?  {backgroundColor: 'rgba(0, 0, 0, 0.15)'} : null}
        onOk={this.handleOk}
        onCancel={this.handleCancel}
        destroyOnClose
@@ -2219,6 +2238,43 @@
    )
  }
  setMove = () => {
    const { btn } = this.props
    let wrap = document.getElementsByClassName('modal-' + btn.uuid)[0]
    if (!wrap) return
    let node = wrap.getElementsByClassName('ant-modal-header')[0]
    if (!node) return
    node.onmousedown = function(e) {
      let orileft = 0
      let oritop = 0
      let oleft = e.clientX
      let otop = e.clientY
      if (node.parentNode.style.left) {
        orileft = parseFloat(node.parentNode.style.left)
      }
      if (node.parentNode.style.top) {
        oritop = parseFloat(node.parentNode.style.top)
      }
      document.onmousemove = function(e) {
        let left = e.clientX - oleft
        let top = e.clientY - otop
        node.parentNode.style.left = (orileft + left) + 'px'
        node.parentNode.style.top = (oritop + top) + 'px'
      }
    }
    document.onmouseup = function() {
      document.onmousemove = null
    }
  }
  render() {
    const { btn } = this.props
    const { loading, disabled, hidden } = this.state