king
2024-06-21 2bccb9ec7bdefe23292a22bc153463cfa1479a49
src/tabviews/zshare/actionList/excelInbutton/index.jsx
@@ -29,6 +29,7 @@
    disabled: false,
    hidden: false,
    primaryId: '',
    dict: window.GLOB.dict
  }
  UNSAFE_componentWillMount () {
@@ -106,57 +107,45 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record, type) => {
    const { setting, BID, btn, selectedData } = this.props
    const { loading, disabled } = this.state
  actionTrigger = (triggerId, record, type, lid) => {
    const { setting, BID, btn, selectedData, 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: 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 === 'requiredSgl' && data.length !== 1) {
    } else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: '请选择单行数据!',
        message: dict['select_single_row'] || '请选择单行数据!',
        duration: 5
      })
      return
    } else if (!btn.verify || !btn.verify.sheet || !btn.verify.columns || btn.verify.columns.length === 0) {
      notification.warning({
        top: 92,
        message: 'excel导入验证信息未设置!',
        duration: 5
    } else {
      let primaryId = '' // 导入时行Id
      if (btn.Ot === 'requiredSgl' && setting.primaryKey) {
        primaryId = data[0][setting.primaryKey] || ''
      }
      this.setState({
        selines: data,
        primaryId: primaryId
      }, () => {
        this.refs.excelIn.exceltrigger()
      })
      return
    }
    let primaryId = '' // 导入时行Id
    if (btn.Ot === 'requiredSgl' && setting.primaryKey) {
      primaryId = data[0][setting.primaryKey] || ''
    }
    this.setState({
      selines: data,
      primaryId: primaryId
    }, () => {
      this.refs.excelIn.exceltrigger()
    })
    if (window.GLOB.systemType === 'production') {
      MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'})
      if (window.GLOB.systemType === 'production') {
        MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'})
      }
    }
  }
@@ -170,16 +159,18 @@
   */
  execSuccess = (res = {}) => {
    const { btn } = this.props
    const { dict } = this.state
    if (res.ErrCode === 'S' || !res.ErrCode) { // 执行成功
      notification.success({
        top: 92,
        message: res.message || '执行成功!',
        message: res.message || dict['exc_success'] || '执行成功!',
        duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
      })
    } else if (res.ErrCode === 'Y') { // 执行成功
      Modal.success({
        title: res.message || '执行成功!'
        title: res.message || dict['exc_success'] || '执行成功!',
        okText: dict['got_it'] || '知道了',
      })
    } else if (res.ErrCode === '-1') { // 完成后不提示
@@ -232,6 +223,7 @@
   */
  execError = (res = {}) => {
    const { btn } = this.props
    const { dict } = this.state
    if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) {
      res.ErrCode = 'E'
@@ -239,23 +231,24 @@
    if (res.ErrCode === 'E') {
      Modal.error({
        title: res.message || '执行失败!',
        title: res.message || dict['exc_fail'] || '执行失败!',
        okText: dict['got_it'] || '知道了'
      })
    } else if (res.ErrCode === 'N') {
      notification.error({
        top: 92,
        message: res.message || '执行失败!',
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
      })
    } else if (res.ErrCode === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: res.message || '执行失败!',
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || '执行失败!')
      message.error(res.message || dict['exc_fail'] || '执行失败!')
    }
    
    this.setState({
@@ -266,6 +259,24 @@
      MKEmitter.emit('popclose')
    } else if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
      if (btn.syncComponentId) {
        if (btn.syncComponentId === 'multiComponent') {
          btn.syncComponentIds.forEach((id, i) => {
            setTimeout(() => {
              if (/\$focus/.test(id)) {
                MKEmitter.emit('reloadData', id.split('$')[0], id.split('$')[1])
              } else {
                MKEmitter.emit('reloadData', id)
              }
            }, 20 * i)
          })
        } else if (/\$focus/.test(btn.syncComponentId)) {
          MKEmitter.emit('reloadData', btn.syncComponentId.split('$')[0], btn.syncComponentId.split('$')[1])
        } else {
          MKEmitter.emit('reloadData', btn.syncComponentId)
        }
      }
    }
    if (btn.execError === 'popclose' && btn.$tabId) { // 标签关闭刷新
@@ -276,43 +287,21 @@
  /**
   * @description Excel 导入
   */
  getexceldata = (data, errors, sheetName, errDetail) => {
  getexceldata = (data, error) => {
    const { btn, BID } = this.props
    if (errors) {
      if (errors === 'notexit') {
        notification.warning({
          top: 92,
          message: '工作表《' + sheetName + '》不存在!',
          duration: 5
        })
      } else if (errors === 'empty') {
        notification.warning({
          top: 92,
          message: '工作表《' + sheetName + '》为空!',
          duration: 5
        })
      } else if (errors === 'headerError') {
        notification.warning({
          top: 92,
          message: `工作表《${sheetName}》表头错误,${errDetail}`,
          duration: 5
        })
      }
    if (error) {
      notification.warning({
        top: 92,
        message: error,
        duration: 5
      })
      this.setState({ loading: false })
      return
    }
    if (!data || data.length === 0) {
      notification.warning({
        top: 92,
        message: '未获取到工作表《' + sheetName + '》数据!',
        duration: 5
      })
      this.setState({ loading: false })
      return
    } else if (data.length * btn.verify.columns.length > 30000) {
    if (data.length * btn.verify.columns.length > 30000) {
      notification.warning({
        top: 92,
        message: '当前导入数据量过大,如遇错误提示,请分批导入!',
@@ -364,6 +353,10 @@
        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
      }
      if (btn.database === 'sso' && window.GLOB.mainSystemApi) {
        param.rduri = window.GLOB.mainSystemApi
      }
      param.menuname = btn.logLabel
      
      if (window.GLOB.probation) {
@@ -386,8 +379,10 @@
          } else if (res.ErrCode === 'C') {
            const _this = this
            confirm({
              title: '请确认',
              title: window.GLOB.dict['exec_sure'] || '请确认',
              content: res.message,
              okText: window.GLOB.dict['ok'] || '确定',
              cancelText: window.GLOB.dict['cancel'] || '取消',
              onOk() {
                return new Promise(resolve => {
                  Api.genericInterface(unCheckParam).then(result => {
@@ -429,6 +424,9 @@
      if (btn.recordUser === 'true') {
        param.username = sessionStorage.getItem('User_Name') || ''
        param.fullname = sessionStorage.getItem('Full_Name') || ''
      }
      if (btn.dataM === 'true') {
        param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : ''
      }
      Api.genericInterface(param).then((res) => {
@@ -556,39 +554,24 @@
    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 || 'upload'
    } 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>
    }
    return <>
      <Button
        type={type}
        type="link"
        id={'button' + btn.uuid}
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
        loading={loading}
        disabled={disabled}
        style={btn.style}
        icon={icon}
        className={className}
        className={btn.hover || ''}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
      <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" />