king
2023-06-30 0519dcda8b6fb2914987f8d4d58e1d14bcf98dc3
src/tabviews/zshare/actionList/exceloutbutton/index.jsx
@@ -18,6 +18,7 @@
  static propTpyes = {
    BID: PropTypes.string,            // 主表ID
    BData: PropTypes.any,             // 主表数据
    selectedData: PropTypes.any,      // 子表中选择数据
    btn: PropTypes.object,            // 按钮
    setting: PropTypes.any,           // 页面通用设置
    updateStatus: PropTypes.func,     // 按钮状态更新
@@ -41,7 +42,7 @@
        this.setState({hidden: true})
      } else {
        let s = BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
        if (btn.controlVals.includes(s)) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
@@ -70,7 +71,7 @@
        this.setState({hidden: true})
      } else {
        let s = nextProps.BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
        if (btn.controlVals.includes(s)) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
@@ -219,7 +220,8 @@
          } else {
            this.execError(result)
          }
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.execError({})
        })
      } else if (btn.intertype === 'inner') { // 使用内部函数
@@ -232,7 +234,8 @@
          } else {
            this.execError(result)
          }
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.execError({})
        })
      } else if (btn.intertype === 'outer' && !btn.innerFunc) { // 使用外部函数
@@ -284,7 +287,8 @@
          } else {
            this.execError(result)
          }
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.execError({})
        })
      } else if (btn.intertype === 'outer' && btn.innerFunc) {
@@ -348,7 +352,8 @@
          } else {
            this.execError(res)
          }
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.execError({})
        })
      } else {
@@ -436,13 +441,15 @@
          } else {
            this.execError(result)
          }
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.execError({})
        })
      } else {
        this.execError(res)
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.execError({})
    })
  }
@@ -524,7 +531,8 @@
      } else {
        this.execError(result)
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.execError({})
    })
  }
@@ -593,29 +601,68 @@
        this.table2excel(column, table, this.state.excelName.replace(/\.xlsx/ig, '.xls'))
        if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) {
        if (btn.verify.enable === 'true' && btn.verify.script) {
          this.execCustomScript()
        } else {
          this.execSuccess({ErrCode: 'S', ErrMesg: '导出成功!'})
        }
      } else {
        let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        let cols = []
        for (let index = 0; index < columns.length; index++) {
          let i = Math.floor(index / 26)
          let s = letters[i - 1] || ''
          cols.push(s + letters[index % 26])
        }
        let table = []
        let _header = []
        let _topRow = {}
        let colwidth = []
        let requires = []
        let merges = []
        columns.forEach((col, i) => {
          _header.push(col.Column)
          _topRow[col.Column] = col.Text
          colwidth.push({width: col.Width || 20})
          colwidth.push({wch: col.Width || 20})
          if (col.required === 'true') {
            requires.push(i)
          }
        })
        let table = []
        table.push(_topRow)
        if (btn.verify.merge === 'true') {
          let fLine = {}
          let sLine = {}
          let sign = ''
          columns.forEach((col, i) => {
            if (/.+-.+/.test(col.Text)) {
              let _sign = col.Text.split('-')[0]
              let _name = col.Text.split('-')[1]
              fLine[col.Column] = _sign
              sLine[col.Column] = _name
              if (sign === _sign) {
                merges[merges.length - 1] = merges[merges.length - 1].split(':')[0] + `:${cols[i]}1`
              } else {
                merges.push(`${cols[i]}1:${cols[i]}2`)
                sign = _sign
              }
            } else {
              fLine[col.Column] = col.Text
              sLine[col.Column] = col.Text
              sign = ''
              merges.push(`${cols[i]}1:${cols[i]}2`)
            }
          })
          table.push(fLine)
          table.push(sLine)
        } else {
          table.push(_topRow)
        }
  
        data && data.forEach((item, index) => {
          let _row = {}
@@ -645,22 +692,57 @@
        ws['!cols'] = colwidth
        if (btn.verify.rowHeight) {
          ws['!rows'] = Array(table.length).fill({hpx: btn.verify.rowHeight})
        }
        if (requires.length) {
          let cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
          requires.forEach(col => {
            if (cols[col]) {
              ws[cols[col] + '1'].s = {font: { color: { rgb: 'F5222D' } }}
            }
          })
        }
        if (merges.length) {
          ws['!merges'] = []
          merges.forEach(item => {
            ws['!merges'].push(XLSX.utils.decode_range(item))
          })
          cols.forEach(col => {
            if (ws[col + '1'].s) {
              ws[col + '1'].s = {font: { color: { rgb: 'F5222D' } }, alignment: { horizontal: 'center', vertical: 'center' }}
            } else {
              ws[col + '1'].s = {alignment: { horizontal: 'center', vertical: 'center' }}
            }
            ws[col + '2'].s = {alignment: { horizontal: 'center', vertical: 'center' }}
          })
        }
        if (btn.verify.wrapText === 'true' && data) {
          let lines = data.length + 1
          let start = 2
          if (btn.verify.merge === 'true') {
            lines = data.length + 2
          }
          for (let n = 0; n < cols.length; n++) {
            for (let m = start; m <= lines; m++) {
              if (ws[cols[n] + m] && !ws[cols[n] + m].s) {
                ws[cols[n] + m].s = {alignment: { wrapText: true }}
              }
            }
          }
        }
        // ws["A1"].s = {fill: { bgColor: { rgb: "FFFFAA"  }}, font: { color: { rgb: "1890FF" } }}
        const wb = XLSX.utils.book_new()
        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
        XLSX.utils.book_append_sheet(wb, ws, btn.verify.sheet || 'Sheet1')
  
        XLSX.writeFile(wb, this.state.excelName)
  
        if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) {
        if (btn.verify.enable === 'true' && btn.verify.script) {
          this.execCustomScript()
        } else {
          this.execSuccess({ErrCode: 'S', ErrMesg: '导出成功!'})
@@ -767,7 +849,8 @@
      } else {
        this.execError(res)
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus('over')
    })
  }
@@ -776,6 +859,7 @@
   * @description 获取用户自定义存储过程传参
   */
  getExcelCustomParam = (orderBy, search, pagination = false, pageIndex = 1, pageSize = 100) => {
    const { btn, selectedData } = this.props
    let _search = Utils.formatCustomMainSearch(search)
    let param = {
@@ -786,6 +870,13 @@
    // 数据管理权限
    if (sessionStorage.getItem('dataM') === 'true') {
      param.dataM = 'Y'
    }
    if (btn.Ot === 'requiredOnce' && selectedData && selectedData.length > 0) {
      let primaryId = selectedData.map(d => d.$$uuid || '').filter(Boolean).join(',')
      if (primaryId) {
        param.ID = primaryId
      }
    }
    if (this.props.BID) {
@@ -804,17 +895,19 @@
   * @description 获取默认存储过程请求参数
   */
  getExcelDefaultParam = (arr_field, orderBy, search, pagination = false, pageIndex = 1, pageSize = 100) => {
    const { setting, btn } = this.props
    const { setting, btn, selectedData, BID } = this.props
    let defaultSql = setting.execute || setting.default || 'true'
    let customScript = setting.customScript || ''
    let _dataresource = setting.dataresource || ''
    let queryType = setting.queryType
    let primaryKey = setting.primaryKey || 'ID'
    if (btn.verify.dataType === 'custom') {
      defaultSql = btn.verify.defaultSql || 'true'
      _dataresource = btn.verify.dataresource || ''
      queryType = btn.verify.queryType
      // primaryKey = btn.verify.primaryKey || 'ID'
      if (/\s/.test(_dataresource)) {
        _dataresource = '(' + _dataresource + ') tb'
@@ -852,13 +945,18 @@
      menuname: btn.logLabel
    }
    if (btn.verify.dataType !== 'custom' && setting.sub_field) {
      arr_field = arr_field + ',' + setting.sub_field
      param.arr_field = arr_field
    }
    // 数据管理权限
    if (sessionStorage.getItem('dataM') === 'true') {
      param.dataM = 'Y'
    }
    if (this.props.BID) {
      param.BID = this.props.BID
    if (BID) {
      param.BID = BID
    }
    let userName = sessionStorage.getItem('User_Name') || ''
@@ -914,6 +1012,16 @@
      _search = ''
    }
    let primaryId = ''
    if (btn.Ot === 'requiredOnce' && selectedData && selectedData.length > 0) {
      primaryId = selectedData.map(d => d.$$uuid || '').filter(Boolean).join(',')
      if (_search && primaryId) {
        _search += ` and ${primaryKey} in (select ID from dbo.SplitComma('${primaryId}'))`
      } else if (primaryId) {
        _search = `where ${primaryKey} in (select ID from dbo.SplitComma('${primaryId}'))`
      }
    }
    let LText = ''
    if (defaultSql !== 'false' && !pagination) {
@@ -948,6 +1056,21 @@
        ${LText}
      `
    }
    LText = LText.replace(/@ID@/ig, `'${primaryId || ''}'`)
    param.custom_script = param.custom_script.replace(/@ID@/ig, `'${primaryId || ''}'`)
    LText = LText.replace(/@BID@/ig, `'${BID}'`)
    param.custom_script = param.custom_script.replace(/@BID@/ig, `'${BID}'`)
    LText = LText.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    param.custom_script = param.custom_script.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    LText = LText.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    param.custom_script = param.custom_script.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    LText = LText.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    param.custom_script = param.custom_script.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    LText = LText.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    param.custom_script = param.custom_script.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    LText = LText.replace(/@typename@/ig, `'admin'`)
    param.custom_script = param.custom_script.replace(/@typename@/ig, `'admin'`)
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
@@ -1003,7 +1126,17 @@
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', [])
    }
    
    btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId)
    if (btn.syncComponentId) {
      if (btn.syncComponentId === 'multiComponent') {
        btn.syncComponentIds.forEach((id, i) => {
          setTimeout(() => {
            MKEmitter.emit('reloadData', id)
          }, 20 * i)
        })
      } else {
        MKEmitter.emit('reloadData', btn.syncComponentId)
      }
    }
    
    if (btn.switchTab && btn.switchTab.length > 0) {
      let id = btn.switchTab[btn.switchTab.length - 1]