king
2023-11-05 ab949bb71eadda3ec1736ccdcfaa1b12b04cce6a
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -270,6 +270,9 @@
            Object.keys(cell).forEach(key => {
              let _key = key.toLowerCase()
              if (/^\$/.test(_key)) return
              _cell[_key] = cell[key]
            })
@@ -564,16 +567,28 @@
  execCustomPrint = (printlist, formdata) => {
    const { btn } = this.props
    let callback = null
    if (/callback\(\)/.test(btn.verify.printFunc)) {
      callback = () => {
    this.execSuccess({
      ErrCode: '-1',
      message: '',
      status: true
    })
      }
    } else {
      this.execSuccess({
        ErrCode: '-1',
        message: '',
        status: true
      })
    }
    try {
      // eslint-disable-next-line
      let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc)
      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
      let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', 'callback', btn.verify.printFunc)
      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback)
      // 自定义打印示例
      // let defaultPrinter = printer.defaultPrinter || 'lackprinter'
@@ -769,18 +784,11 @@
    } catch (e) {
      console.warn(e)
      try {
        // eslint-disable-next-line
        let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})')
        evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
      } catch (error) {
        console.warn(error)
        notification.warning({
          top: 92,
          message: '自定义函数执行错误!',
          duration: 5
        })
      }
    }
  }
@@ -1761,26 +1769,35 @@
      return
    }
    if (printerList.length === 0) {
      this.execSuccess({
        ErrCode: '-1',
        message: '未获取到打印信息!',
        status: true
      })
      return
    }
    if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) {
      socket = new WebSocket('ws://' + btn.verify.linkUrl)
    } else {
      this.syncMessageSend(printerList)
      this.syncMessageSend(printerList, () => {
      this.execSuccess({
        ErrCode: 'S',
        message: '打印请求已发出。',
        status: true
      })
      })
    }
    // 打开Socket
    socket.onopen = () =>{
      this.syncMessageSend(printerList)
      this.syncMessageSend(printerList, () => {
      this.execSuccess({
        ErrCode: 'S',
        message: '打印请求已发出。',
        status: true
        })
      })
    }
    // 监听消息
@@ -1835,17 +1852,26 @@
    }
  }
  syncMessageSend = (list) => {
  syncMessageSend = (list, callback) => {
    let param = list.shift()
    if (socket && param) {
    if (socket) {
      try {
      socket.send(JSON.stringify(param))
      } catch(e) {
        console.warn('打印请求发送失败!')
      }
    }
    if (list && list.length > 0) {
      setTimeout(() => {this.syncMessageSend(list)}, 3000)
    if (list.length > 0) {
      setTimeout(() => {
        this.syncMessageSend(list, callback)
      }, 3000)
    } else {
      callback()
    }
  }
  /**
   * @description 操作成功后处理
   * 1、excel导出,成功后取消导出按钮加载中状态