king
2024-09-10 4d6b9f8a2d7b316633e43b489eae9ada949c07b5
src/views/billprint/index.jsx
@@ -1,7 +1,8 @@
import React, { Component } from 'react'
import { is, fromJS } from 'immutable'
import { Col, Row, Spin, notification, Button } from 'antd'
import { Col, Row, Spin, notification, Button, Modal } from 'antd'
import moment from 'moment'
import md5 from 'md5'
import Api from '@/api'
import Utils from '@/utils/utils.js'
@@ -44,8 +45,11 @@
    visible: false,
    rePos: false,
    loading: false,
    auto: true
    auto: true,
    ismob: /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent)
  }
  reloading = false
  UNSAFE_componentWillMount() {
    const { params } = this.props.match
@@ -62,6 +66,7 @@
        let param = JSON.parse(window.decodeURIComponent(window.atob(params.param)))
  
        sessionStorage.setItem('dataM', param.dataM || '')
        this.setState({
          BID: param.id || '',
          tempId: param.tempId,
@@ -87,7 +92,7 @@
  }
  componentDidMount() {
    const _this = this
    const that = this
    if (window.GLOB.sysType !== 'cloud') {
      Object.defineProperty(window, 'debugger', {
@@ -115,7 +120,7 @@
            window.GLOB.breakpoint = value + ''
            sessionStorage.setItem('breakpoint', value)
          }
          _this.debugChange()
          that.debugChange()
        }
      })
    }
@@ -141,7 +146,7 @@
        window.GLOB.breakpoint = false
        sessionStorage.removeItem('breakpoint')
        
        _this.debugChange()
        that.debugChange()
      }
    }
  }
@@ -165,8 +170,6 @@
        sessionStorage.setItem('UserID', result.UserID || '')
        sessionStorage.setItem('LoginUID', result.LoginUID || '')
        sessionStorage.setItem('dataM', 'false')
        this.getMenuParam()
        // 获取系统信息
        let _param = {
@@ -198,6 +201,8 @@
              document.getElementsByTagName('head')[0].appendChild(link)
            }
          }
          this.getMenuParam()
        })
      } else {
        notification.warning({
@@ -251,6 +256,10 @@
          return
        }
        if (config.webTitle) {
          document.title = config.webTitle
        }
        config.style = config.style || {}
        config.pageSize = ['A4', 'A3', 'A5'].includes(config.pageSize) ? config.pageSize : 'A4'
        config.pageLayout = config.pageLayout !== 'horizontal' ? 'vertical' : 'horizontal'
@@ -296,6 +305,22 @@
        config.components = config.components.filter(item => !['tabs', 'search'].includes(item.type))
        if (window.backend && config.allSqls) {
          let urlparam = urlParam || {}
          let keys = Object.keys(urlparam)
          config.allSqls.forEach(item => {
            item.id = md5(window.GLOB.appkey + item.v_id)
            if (item.type === 'datasource' || item.type === 'excelOut') {
              item.urlkeys = keys
              item.urlparam = urlparam
              if (config.flow_code) {
                item.works_flow_code = config.flow_code
              }
            }
            window.GLOB.CacheData.set('sql_' + item.uuid, item)
          })
        }
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
@@ -325,7 +350,7 @@
        let initInters = []
        this.formatInterSetting(config.interfaces, regs, initInters, params, BID)
        this.formatInterSetting(config.interfaces, regs, initInters, params, BID, config.MenuName)
        config.components = config.components.map(component => {
          if (component.action) {
@@ -341,6 +366,8 @@
            component.$searches = []
          }
          component.data = [] // 初始化数据为空
          component.$menuname = (config.MenuName || '') + '-' + (component.name || '')
          if (component.subtype === 'tablecard') { // 兼容
            component.type = 'card'
@@ -360,7 +387,9 @@
            let getColumns = (cols) => {
              return cols.filter(item => {
                if (item.Hide === 'true') return false
                item.IsSort = 'false'
                if (item.type === 'number') {
                  if (typeof(item.decimal) === 'number') {
                    item.round = Math.pow(10, item.decimal)
@@ -466,6 +495,7 @@
          component.setting.arr_field = component.columns ? component.columns.map(col => col.field).join(',') : ''
          component.setting.laypage = false   // 是否分页,转为boolean 统一格式
          component.setting.$name = component.$menuname
          if (component.format === 'object') {
            component.setting.$top = true
@@ -475,6 +505,8 @@
            component.setting.sync = 'false'
            return component
          }
          component.setting.uuid = component.uuid
    
          let _customScript = ''
          let _tailScript = ''
@@ -520,6 +552,12 @@
    
          component.setting.customScript = _customScript // 整理后自定义脚本
          component.setting.tailScript = _tailScript     // 后置自定义脚本
          if (window.backend && config.allSqls) {
            component.setting.sync = 'false'
          } else if (_tailScript) {
            component.setting.sync = 'false'
          }
    
          // floor    组件的层级
          // pageable 是否分页,组件属性,不分页的组件才可以统一查询
@@ -539,7 +577,7 @@
          return component
        })
        _pars = this.getFormatParam(_pars)
        _pars = this.getFormatParam(_pars, config.MenuName)
        if (_pars) {
          _pars.componentId = 'union'
@@ -622,6 +660,9 @@
    if (cell.marks && cell.marks.length === 0) {
      cell.marks = null
    }
    if (cell.anchors && cell.anchors.length === 0) {
      cell.anchors = null
    }
    
    if (['text', 'number', 'formula'].includes(cell.eleType)) {
      cell.innerHeight = cell.innerHeight || 'auto'
@@ -640,7 +681,7 @@
    return cell
  }
  formatInterSetting = (inters, regs, initInters, params, BID) => {
  formatInterSetting = (inters, regs, initInters, params, BID, MenuName) => {
    if (!inters) return []
    let delay = 15
@@ -652,6 +693,7 @@
      inter.setting.supModule = ''
      inter.setting.arr_field = inter.columns.map(col => col.field).join(',')
      inter.setting.$name = (MenuName || '') + '-公共数据源-' + inter.setting.name
      if (inter.setting.interType !== 'system') {
        let param = UtilsDM.getQueryDataParams(inter.setting, [], inter.setting.order || '', 1, 1000, BID)
@@ -666,6 +708,8 @@
        }
        return
      }
      inter.setting.uuid = inter.uuid
      let _customScript = ''
      let _tailScript = ''
@@ -683,7 +727,6 @@
      })
      delete inter.scripts
      inter.setting.$name = '公共数据源-' + inter.setting.name
      inter.setting.execute = inter.setting.execute !== 'false'
      inter.setting.laypage = false
      inter.setting.$top = true
@@ -771,7 +814,7 @@
    }
  }
  getFormatParam = (params) => {
  getFormatParam = (params, MenuName) => {
    const { BID } = this.state
    if (!params || params.length === 0) return ''
@@ -798,6 +841,7 @@
      { reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
      { reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
      { reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
      { reg: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
      { reg: /@typename@/ig, value: `'admin'`},
    ]
@@ -822,8 +866,8 @@
      // 测试系统打印查询语句
      if (window.GLOB.debugger === true) {
        _script && console.info(`${_sql ? '' : '/*不执行默认sql*/\n'}${_script}`)
        _sql &&  console.info(_sql)
        _script && window.mkInfo(`${_sql ? '' : '/*不执行默认sql*/\n'}${_script}`)
        _sql && window.mkInfo(_sql)
      }
      item.columns.forEach(cell => {
@@ -834,17 +878,21 @@
    let param = {
      func: 'sPC_Get_structured_data',
      LText: LText.join(' union all '),
      LText_field: LText_field.join(' union all '),
      BID: BID || '',
      username: userName,
      fullName: fullName
    }
    param.LText = Utils.formatOptions(param.LText)
    param.LText_field = Utils.formatOptions(param.LText_field)
    if (MenuName) {
      param.menuname = MenuName
    }
    param.exec_type = window.GLOB.execType || 'y'
    param.LText = Utils.formatOptions(LText.join(' union all '), param.exec_type)
    param.custom_script = Utils.formatOptions(LText_field.join(' union all '), param.exec_type)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    param.secretkey = Utils.encrypt('', param.timestamp)
    return param
  }
@@ -897,11 +945,18 @@
      return new Promise(resolve => {
        Api.genericInterface(item).then(res => {
          if (!res.status) {
            notification.warning({
              top: 92,
              message: res.message,
              duration: 5
            })
            if (item.func === 'sPC_Get_structured_data' && /将截断字符串或二进制数据/ig.test(res.message)) {
              res.message = res.message + '请检查字段集'
            }
            if (res.ErrCode === 'version_up') {
              this.reloadTabs()
            } else {
              notification.warning({
                top: 92,
                message: res.message,
                duration: 5
              })
            }
            resolve(false)
          } else {
            res.componentId = componentId
@@ -1058,6 +1113,28 @@
      })
      this.setState({loadingview: false, pages, rePos})
    })
  }
  reloadTabs = () => {
    if (this.reloading) return
    let time = new Date().getTime()
    let oldTime = sessionStorage.getItem('mk_reloadTabs')
    if (oldTime && time - oldTime < 180000) return
    sessionStorage.setItem('mk_reloadTabs', time)
    this.reloading = true
    Api.getAppVersion(true).then(() => {
      window.location.reload()
    }, (message) => {
      Modal.error({
        title: message || '系统配置更新失败!',
      })
    })
  }
@@ -1312,7 +1389,7 @@
  }
  render() {
    const { loadingview, viewlost, config, pages, auto, rePos, loading } = this.state
    const { loadingview, viewlost, config, pages, auto, rePos, loading, ismob } = this.state
    return (
      <div className="bill-print-wrap" >
@@ -1322,8 +1399,8 @@
        </div> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
        {config && window.GLOB.breakpoint ? <DebugTable /> : null}
        {pages && !loadingview && !viewlost ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null}
        {!loadingview && !viewlost ? <div className="refresh-button"><Button icon="reload" size="large" shape="circle" onClick={this.reload}></Button></div> : null}
        {pages && !loadingview && !viewlost && !ismob ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null}
        {!loadingview && !viewlost && !ismob ? <div className="refresh-button"><Button icon="reload" size="large" shape="circle" onClick={this.reload}></Button></div> : null}
      </div>
    )
  }