king
2023-03-11 34e7681fd12b1c4e4994d3bea1a553870e10bc50
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})
@@ -593,29 +594,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 +685,42 @@
        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' }}
          })
        }
        // 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: '导出成功!'})
@@ -776,6 +836,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 +847,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 +872,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'
@@ -857,8 +927,8 @@
      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 +984,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) {
@@ -949,6 +1029,21 @@
      `
    }
    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')) {
      param.custom_script && console.info(`${LText ? '' : '/*不执行默认sql*/\n'}${param.custom_script}`)