king
2020-03-10 c39ea1f23d21b070188abcf5f4dd5bdd7b47c1f9
src/tabviews/tableshare/actionList/index.jsx
@@ -11,6 +11,7 @@
import './index.scss'
const { confirm } = Modal
let socket = null
class MainAction extends Component {
  static propTpyes = {
@@ -185,7 +186,25 @@
      if (item.funcType === 'changeuser') {
        this.changeUser(item, data)
      } else if (item.funcType === 'print') {
        this.triggerPrint(item, data)
        if (item.execMode === 'pop') {
          this.setState({
            execAction: item,
            tabledata: data,
            btnloading: true
          }, () => {
            this.improveAction(item)
          })
        } else if (item.execMode === 'prompt') {
          confirm({
            title: this.props.dict['main.action.confirm.tip'],
            onOk() {
              _this.triggerPrint(item, data)
            },
            onCancel() {}
          })
        } else {
          this.triggerPrint(item, data)
        }
      }
    } else {
      notification.warning({
@@ -199,8 +218,10 @@
  /**
   * @description 触发打印
   */
  triggerPrint = (item, data) => {
  triggerPrint = (item, data, formdata) => {
    console.log(item)
    console.log(data)
    console.log(formdata)
    if (!item.verify || !item.verify.Template || !item.verify.linkUrl) {
      notification.warning({
        top: 92,
@@ -224,7 +245,33 @@
      Api.getLocalConfig(param).then(res => {
        if (res.status) {
          resolve(res)
          if (!res.ConfigParam) {
            notification.warning({
              top: 92,
              message: '未获取到打印模板信息!',
              duration: 15
            })
            resolve(false)
          } else {
            let configParam = ''
            try {
              configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam)))
            } catch (e) {
              configParam = ''
            }
            if (!configParam) {
              notification.warning({
                top: 92,
                message: '打印模板解析错误!',
                duration: 15
              })
            } else {
              resolve(configParam)
            }
          }
        } else {
          this.execError(res, item)
          resolve(false)
@@ -233,7 +280,87 @@
    }).then(res => {
      console.log(res)
      if (!res) return
      if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + item.verify.linkUrl) {
        socket = new WebSocket('ws://' + item.verify.linkUrl)
      }
      // 打开Socket
      socket.onopen = () =>{
        if (!item.printer) {
          let request  = {
            requestID: '',
            version: '',
            cmd: 'getPrinters'
          }
          socket.send(JSON.stringify(request))
        } else {
          let printdata = {
            cmd: 'print',
            requestID: '',
            version: '',
            task: {
              taskID: '1',
              preview: false,
              printer: item.printer,
              documents: [
                {
                  documentID: '9890000106027',
                  contents: [
                    {
                      data: {
                        barcode: '12345'
                      },
                      templateURL: '{"Version":"","Title":"1234","Author":"U000000001","Description":"","PrintTempNO":"","PageSetting":{"Width":210,"Height":297,"Left":"0","Right":"0","Top":"0","Bottom":"0","Landscape":false},"PageHeader":[],"ReportHeader":{"Control":[{"Name":"","Type":"barcode","Value":"","Field":"barcode","Left":71,"Top":32,"Width":52,"Height":26,"Rotate":0,"BorderSize":0.1,"BorderColor":"black","Align":"center","VerticalAlign":"middle","BackColor":"white","ForeColor":"black","BarcodeType":"code128","BarcodeWidth":31,"BarcodeHeight":10,"BarcodeLabel":true,"LabelSize":12}]},"ReportFooter":[],"PageFooter":[]}'
                    }
                  ]
                }
              ]
            }
          }
          socket.send(JSON.stringify(printdata))
        }
      }
      // 监听消息
      socket.onmessage = (event) => {
        let data = JSON.parse(event.data)
        if (data.defaultPrinter) {
          let printdata = {
            cmd: 'print',
            requestID: '',
            version: '',
            task: {
              taskID: '1',
              preview: false,
              printer: data.defaultPrinter,
              documents: [
                {
                  documentID: '9890000106027',
                  contents: [
                    {
                      data: {
                        barcode: '12345'
                      },
                      templateURL: '{"Version":"","Title":"1234","Author":"U000000001","Description":"","PrintTempNO":"","PageSetting":{"Width":210,"Height":297,"Left":"0","Right":"0","Top":"0","Bottom":"0","Landscape":false},"PageHeader":[],"ReportHeader":{"Control":[{"Name":"","Type":"barcode","Value":"","Field":"barcode","Left":71,"Top":32,"Width":52,"Height":26,"Rotate":0,"BorderSize":0.1,"BorderColor":"black","Align":"center","VerticalAlign":"middle","BackColor":"white","ForeColor":"black","BarcodeType":"code128","BarcodeWidth":31,"BarcodeHeight":10,"BarcodeLabel":true,"LabelSize":12}]},"ReportFooter":[],"PageFooter":[]}'
                    }
                  ]
                }
              ]
            }
          }
          socket.send(JSON.stringify(printdata))
        }
      }
      socket.onerror = () => {
        notification.warning({
          top: 92,
          message: '无法连接到:' + item.verify.linkUrl,
          duration: 10
        })
      }
    })
@@ -309,6 +436,14 @@
  execSubmit = (btn, data, _resolve, formdata) => {
    const { setting, logcolumns } = this.props
    if (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop') {
      this.setState({
        confirmLoading: false,
        visible: false
      })
      this.triggerPrint(btn, data, formdata)
      return
    }
    if (btn.intertype === 'inner') {
      // 使用内部接口时,内部函数和数据源不可同时为空, 使用系统函数时,类型不可为空
      if (!btn.innerFunc && (!btn.sql || (btn.sql && !btn.sqlType))) {