king
2023-08-11 4adb8b8868aeed1f5f3b89ae269a7724c6b451ad
src/views/billprint/index.jsx
@@ -5,9 +5,7 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import options, { styles } from '@/store/options.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import { styles } from '@/store/options.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import NotFount from '@/components/404'
import asyncComponent from '@/utils/asyncComponent'
@@ -29,11 +27,11 @@
const BraftEditor = asyncComponent(() => import('@/tabviews/custom/components/editor/braft-editor'))
const Balcony = asyncComponent(() => import('@/tabviews/custom/components/card/balcony'))
const AntvG6 = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-G6'))
const AntvX6 = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-X6'))
const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
class BillPrint extends Component {
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    loadingview: true,
    printing: false,
    pages: null,
@@ -43,6 +41,7 @@
    config: null,
    urlParam: null,
    visible: false,
    rePos: false,
    auto: true
  }
@@ -230,7 +229,7 @@
          this.setState({
            viewlost: true,
            loadingview: false,
            lostmsg: this.state.dict['main.view.unenabled']
            lostmsg: '抱歉,您访问的页面未启用,请联系管理员。'
          })
          return
        }
@@ -283,11 +282,6 @@
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
        if (sessionStorage.getItem('isEditState') === 'true') {
          userName = sessionStorage.getItem('CloudUserName') || ''
          fullName = sessionStorage.getItem('CloudFullName') || ''
        }
        let regs = [
          { reg: /@userName@/ig, value: `'${userName}'` },
          { reg: /@fullName@/ig, value: `'${fullName}'` }
@@ -313,8 +307,18 @@
        window.GLOB.CacheData.set(tempId, {$BID: BID})
        config.components = config.components.map(component => {
          if (component.action) component.action = []
          if (component.search) component.search = []
          if (component.action) {
            component.action = component.action.filter(cell => {
              cell = this.resetButton(component, cell)
              cell.$toolbtn = true
              return !cell.hidden
            })
          }
          if (component.search) {
            component.search = []
            component.$searches = []
          }
          component.data = [] // 初始化数据为空
          if (component.subtype === 'tablecard') { // 兼容
@@ -333,18 +337,83 @@
          if (component.type === 'table') {
            let getColumns = (cols) => {
              return cols.map(item => {
              return cols.filter(item => {
                if (item.type === 'colspan') {
                  item.subcols = getColumns(item.subcols)
                  if (item.subcols.length === 0) {
                    return false
                  }
                } else if (item.type === 'custom') {
                  item.elements = item.elements.filter(cell => {
                    if (cell.eleType === 'button') {
                      cell = this.resetButton(component, cell)
                      return !cell.hidden
                    }
                    cell = this.resetElement(cell)
                    return true
                  })
                  if (item.elements.length === 0) {
                    return false
                  }
                } else {
                  item.IsSort = 'false'
                }
          
                return item
                return true
              })
            }
            component.cols = getColumns(component.cols)
            component.statFields = []
          } else if (['card', 'carousel', 'timeline'].includes(component.type)) {
            component.subcards && component.subcards.forEach(card => {
              if (card.style.boxShadow) {
                delete card.style.hShadow
                delete card.style.vShadow
                delete card.style.shadowBlur
                delete card.style.shadowColor
              }
              card.elements = card.elements.filter(cell => {
                if (cell.eleType === 'button') {
                  cell = this.resetButton(component, cell)
                  return !cell.hidden
                }
                cell = this.resetElement(cell)
                return true
              })
              if (!card.backElements || card.backElements.length === 0) return
              card.backElements = card.backElements.filter(cell => {
                if (cell.eleType === 'button') {
                  cell = this.resetButton(component, cell)
                  return !cell.hidden
                }
                cell = this.resetElement(cell)
                return true
              })
            })
          } else if (component.type === 'balcony') {
            component.elements = component.elements.filter(cell => {
              if (cell.eleType === 'button') {
                cell = this.resetButton(component, cell)
                return !cell.hidden
              }
              cell = this.resetElement(cell)
              return true
            })
          }
          if (component.wrap && component.wrap.datatype === 'static') {
@@ -380,13 +449,11 @@
          }
      
          if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
            component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*')
            component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/')
            _customScript = _customScript.replace(/\$@/ig, '/*')
            _customScript = _customScript.replace(/@\$/ig, '*/')
            component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
            _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
          } else {
            component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '')
            _customScript = _customScript.replace(/@\$|\$@/ig, '')
            component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
            _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
          }
          regs.forEach(cell => {
@@ -454,14 +521,58 @@
    })
  }
  resetButton = (item, cell) => {
    cell.logLabel = item.$menuname + '-' + cell.label
    cell.Ot = cell.Ot || 'requiredSgl'
    cell.syncComponentId = ''
    cell.$menuId = item.uuid
    cell.hidden = cell.hidden === 'true'
    if (!['pop', 'prompt', 'exec', 'innerpage', 'form'].includes(cell.OpenType)) {
      cell.hidden = true
    }
    if (cell.controlField) {
      if (/,/ig.test(cell.controlVal)) {
        cell.controlVals = cell.controlVal.split(',')
      } else {
        cell.controlVals = [(cell.controlVal || '')]
      }
    }
    return cell
  }
  resetElement = (cell) => {
    cell.style = cell.style || {}
    if (['text', 'number', 'formula'].includes(cell.eleType)) {
      cell.innerHeight = cell.innerHeight || 'auto'
      cell.alignItems = cell.height > 1 ? cell.alignItems : ''
      if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
        cell.round = Math.pow(10, cell.decimal)
        if (cell.format === 'percent') {
          cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
        }
      }
    }
    return cell
  }
  reload = () => {
    const { tempId } = this.state
    this.setState({
      loadingview: true,
      pages: null,
      data: '',
      config: null
    }, () => {
      this.getMenuParam()
      Api.deleteMenuStorage(tempId)
      setTimeout(() => {
        this.getMenuParam()
      }, 50)
    })
  }
@@ -482,7 +593,7 @@
    }
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
    if (window.GLOB.debugger === true || (window.debugger === true && window.GLOB.sysType !== 'cloud')) {
      _customScript &&  console.info(`${_dataresource ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      _dataresource &&  console.info(_dataresource)
    }
@@ -516,11 +627,6 @@
    let city = sessionStorage.getItem('city') || ''
    let district = sessionStorage.getItem('district') || ''
    let address = sessionStorage.getItem('address') || ''
    if (sessionStorage.getItem('isEditState') === 'true') {
      userName = sessionStorage.getItem('CloudUserName') || ''
      fullName = sessionStorage.getItem('CloudFullName') || ''
    }
    let LText = params.map((item, index) => {
      let _sql = item.sql
@@ -543,7 +649,9 @@
      func: 'sPC_Get_structured_data',
      LText: LText.join(' union all '),
      LText_field: LText_field.join(' union all '),
      BID: BID || ''
      BID: BID || '',
      username: userName,
      fullName: fullName
    }
    param.LText = Utils.formatOptions(param.LText)
@@ -584,17 +692,30 @@
      let _results = results.filter(Boolean)
      let comps = components.map(item => {
        item.wrap = item.wrap || {}
        item.data = null
        if (!item.format) return item
        if ((item.subtype === 'datacard' && item.wrap.layout !== 'flex') || item.type === 'table') {
          item.$page = true
        }
        _results.forEach(res => {
          if (res.componentId === item.uuid && res.data) {
            item.data = res.data
            item.dataArray = fromJS(res.data).toJS()
          } else if (res.componentId === 'union' && res[item.dataName]) {
            item.data = res[item.dataName]
            item.dataArray = fromJS(res[item.dataName]).toJS()
            let data = res[item.dataName]
            if (!Array.isArray(data)) {
              data = [data]
            }
            item.dataArray = fromJS(data).toJS()
          }
        })
        if (item.$page && !item.dataArray) {
          item.$page = false
        }
        return item
      })
@@ -608,94 +729,104 @@
        this.setState({loadingview: false, pages})
      }
      let setData = (item) => {
        if (item.setting && item.setting.sync === 'true' && item.data) {
          item.dataName = Utils.getuuid()
          window.GLOB.SyncData.set(item.dataName, item.data)
        }
      }
      while (!over) {
        let page = []
        let count = 0
        let _pageover = false
        let pagesover = false
        comps.forEach((_item, index) => {
          let item = fromJS(_item).toJS()
        comps.forEach(comp => {
          let item = fromJS(comp).toJS()
          if (index + 1 >= length && !_pageover) {
            pagesover = true
          if (item.wrap.printType === 'headerOrfooter') { // 页眉页脚
            item.data = item.dataArray || null
            setData(item)
            page.push(item)
            comp.added = true
          }
          if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 页眉页脚
            page.push(item)
          } else if (_pageover) {
            return
          } else if (item.subtype === 'datacard' || item.type === 'table') {
            if (_item.dataArray && _item.dataArray.length > 0) {
              if (item.subtype === 'datacard' && item.wrap.layout === 'flex') {
                if (!item.added && item.wrap.printHeight) {
                  count += item.wrap.printHeight
                  if (count >= limit) {
                    _pageover = true
                  }
                  if (count <= limit) {
                    _item.added = true
                    page.push(item)
                  }
                } else if (!item.added) {
                  _item.added = true
                  page.push(item)
                }
              } else {
                item.data = []
                while (count + 1 <= limit && _item.dataArray.length > 0) {
                  item.data.push(_item.dataArray.shift())
                  count++
                }
                if (count >= limit) {
                  _pageover = true
                } else if (_item.dataArray.length > 0) {
                  _pageover = true
          if (_pageover) return
                }
          if (item.$page && comp.dataArray.length > 0) {
            item.data = []
                page.push(item)
              }
              _item.added = true
            } else if (!item.added) {
              _item.added = true
              page.push(item)
            }
          } else if (!item.added && item.wrap && item.wrap.printHeight) {
            if (item.wrap.empty === 'hidden' && (!item.data || item.data.length === 0)) {
              _item.added = true
              return
            while (count + 1 <= limit && comp.dataArray.length > 0) {
              item.data.push(comp.dataArray.shift())
              count++
            }
            count += item.wrap.printHeight
            if (count >= limit) {
            if (count >= limit || comp.dataArray.length > 0) {
              _pageover = true
            }
            if (count <= limit) {
              _item.added = true
              page.push(item)
            if (comp.dataArray.length === 0) {
              comp.added = true
            }
          } else if (!item.added) {
            _item.added = true
            setData(item)
            page.push(item)
          }
          if (index + 1 >= length && !_pageover) {
            pagesover = true
          } else if (!comp.added) {
            if (item.wrap.printHeight) {
              count += item.wrap.printHeight
              if (count >= limit) {
                _pageover = true
                return
              }
            }
            item.data = item.dataArray || null
            setData(item)
            page.push(item)
            comp.added = true
          }
        })
        pages.push(page)
        pageIndex++
        if (pageIndex >= 2000 || pagesover) {
        if (pageIndex >= 2000 || comps.findIndex(comp => !comp.added) === -1) {
          over = true
        }
      }
      this.setState({loadingview: false, pages})
      let total = pages.length
      let date = moment().format('YYYY-MM-DD')
      let datetime = moment().format('YYYY-MM-DD HH:mm:ss')
      let rePos = false
      pages.forEach((page, index) => {
        page.forEach(item => {
          if (item.wrap.printType === 'headerOrfooter') { // 页眉页脚
            if (item.type === 'balcony') {
              if (item.style.position === 'absolute') {
                rePos = true
              }
              item.elements.forEach(cell => {
                if (cell.eleType === 'text' && cell.datatype === 'static') {
                  cell.value = cell.value.replace(/@total@/ig, total).replace(/@pageIndex@/ig, index + 1).replace(/@date@/ig, date).replace(/@datetime@/ig, datetime)
                }
              })
            } else if (item.subtype === 'propcard') {
              item.subcards.forEach(card => {
                card.elements.forEach(cell => {
                  if (cell.eleType === 'text' && cell.datatype === 'static') {
                    cell.value = cell.value.replace(/@total@/ig, total).replace(/@pageIndex@/ig, index + 1).replace(/@date@/ig, date).replace(/@datetime@/ig, datetime)
                  }
                })
              })
            }
          }
        })
      })
      this.setState({loadingview: false, pages, rePos})
    })
  }
@@ -800,90 +931,104 @@
      if (item.style && item.style.clear === 'left') {
        style = {clear: 'left'}
      } else if (item.style && item.style.clear === 'right') {
        style = {float: 'right'}
      }
      if (item.type === 'bar' || item.type === 'line') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvBarAndLine config={item} initdata={item.data} mainSearch={[]} />
            <AntvBarAndLine config={item}/>
          </Col>
        )
      } else if (item.type === 'pie') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvPie config={item} initdata={item.data} mainSearch={[]} />
            <AntvPie config={item} />
          </Col>
        )
      } else if (item.type === 'scatter') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvScatter config={item} initdata={item.data} mainSearch={[]}/>
            <AntvScatter config={item}/>
          </Col>
        )
      } else if (item.type === 'dashboard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvDashboard config={item} initdata={item.data} mainSearch={[]}/>
            <AntvDashboard config={item}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'datacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DataCard config={item} initdata={item.data} mainSearch={[]} />
            <DataCard config={item} />
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'propcard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <PropCard config={item} initdata={item.data} mainSearch={[]} />
            <PropCard config={item} />
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'dualdatacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DoubleDataCard config={item} mainSearch={[]}/>
            <DoubleDataCard config={item}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'tablecard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <TableCard config={item} initdata={item.data} mainSearch={[]}/>
            <TableCard config={item}/>
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'normaltable') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <NormalTable config={item} initdata={item.data} mainSearch={[]}/>
            <NormalTable config={item}/>
          </Col>
        )
      } else if (item.type === 'code') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <SandBox config={item} initdata={item.data} mainSearch={[]}/>
            <SandBox config={item}/>
          </Col>
        )
      } else if (item.type === 'balcony') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <Balcony config={item} initdata={item.data}/>
          </Col>
        )
        if (item.wrap.printType === 'headerOrfooter' && item.style.position === 'absolute') {
          return (
            <Balcony key={item.uuid} config={item}/>
          )
        } else {
          return (
            <Col span={item.width} style={style} key={item.uuid}>
              <Balcony config={item}/>
            </Col>
          )
        }
      } else if (item.type === 'timeline') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <TimeLine config={item} initdata={item.data} mainSearch={[]}/>
            <TimeLine config={item}/>
          </Col>
        )
      } else if (item.type === 'editor') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <BraftEditor config={item} initdata={item.data} mainSearch={[]}/>
            <BraftEditor config={item}/>
          </Col>
        )
      } else if (item.type === 'antvG6') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvG6 config={item} initdata={item.data} mainSearch={[]}/>
            <AntvG6 config={item}/>
          </Col>
        )
      } else if (item.type === 'antvX6') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvX6 config={item}/>
          </Col>
        )
      } else {
@@ -893,13 +1038,13 @@
  }
  render() {
    const { loadingview, viewlost, config, pages, auto } = this.state
    const { loadingview, viewlost, config, pages, auto, rePos } = this.state
    return (
      <div className="bill-print-wrap" >
        {loadingview && <Spin size="large" />}
        {pages ? <div id="bill-print">
          {pages.map((components, index) => (<div className={'print-page' + (auto ? ' auto' : '')} key={index} style={{...config.style, overflow: 'hidden', boxSizing: 'border-box'}}><Row className="component-wrap">{this.getComponents(components)}</Row></div>))}
          {pages.map((components, index) => (<div className={'print-page' + (auto ? ' auto' : '') + (rePos ? ' reset-position' : '')} key={index} style={{...config.style, overflow: 'hidden', boxSizing: 'border-box'}}><Row className="component-wrap">{this.getComponents(components)}</Row></div>))}
        </div> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
        {config && window.GLOB.breakpoint ? <DebugTable /> : null}