king
2022-02-09 d59f518f466274b2caeb2e01c10c92deafe7c93b
src/views/printTemplate/print.js
@@ -4,7 +4,7 @@
   * @param  {Object}    configs      配置信息
   * @param  {Boolean}   selectId     编辑元素
   */
  static sketch (configs, selectId) {
  static sketch (configs, selectId, debug = false) {
    if (!configs.height || !configs.width) return
    if (configs.height / configs.width > 10 || configs.width / configs.height > 10) return
@@ -36,6 +36,13 @@
          element.fontSize = element.fontSize * sizeradio
        } else if (element.type === 'qrcode') {
          element.qrcodeWidth = element.qrcodeWidth * ratio
          if (element.qrcodeWidth > element.height) {
            element.qrcodeWidth = element.height
          }
          if (element.qrcodeWidth > element.width) {
            element.qrcodeWidth = element.width
          }
        } else if (element.type === 'image') {
          element.imgWidth = element.imgWidth * ratio
          element.imgHeight = element.imgHeight * ratio
@@ -43,7 +50,7 @@
      })
      return new Promise(resolve => {
        this.sketchothers(context, elements, selectId, ratio, resolve)
        this.sketchothers(context, elements, selectId, debug, ratio, resolve)
      })
    } else {
      return new Promise(resolve => {
@@ -57,7 +64,7 @@
   * @param  {Object}    context    画布对象
   * @param  {Object}    elements   图片文字信息
   */
  static sketchothers (context, elements, selectId, ratio, resolve) {
  static sketchothers (context, elements, selectId, debug, ratio, resolve) {
    let element = elements.splice(0, 1)[0] // 逐个绘制图片文字
    let textLineSpace = 5 // 绘制时行间距,防止文字重叠
    context.save()
@@ -73,6 +80,12 @@
    if (selectId === element.uuid) { // 选中元素,设置外部阴影
      context.shadowBlur = 5
      context.shadowColor = '#1890ff'
      context.fillStyle = 'white'
      context.fillRect(element.left, element.top, element.width || 1, element.height || 1)
      context.shadowBlur = 0
    } else if (debug) {
      context.shadowBlur = 3
      context.shadowColor = 'orange'
      context.fillStyle = 'white'
      context.fillRect(element.left, element.top, element.width || 1, element.height || 1)
      context.shadowBlur = 0
@@ -117,7 +130,7 @@
    if (!element.width || !element.height) {
      context.restore() // 重置画布
      if (elements.length > 0) {
        this.sketchothers(context, elements, selectId, ratio, resolve)
        this.sketchothers(context, elements, selectId, debug, ratio, resolve)
      } else {
        this.cachesketch(context, resolve)
      }
@@ -131,6 +144,14 @@
      context.fillStyle = element.fontColor
      let lines = element.value.split('\n')
      if (!element.value && element.field) {
        if (element.field === 'other_field') {
          lines = [element.cusfield || '']
        } else {
          lines = [element.field]
        }
      }
      let _y = element.top + element.padding + element.fontSize + element.borderSize
      let _left = element.left + element.borderSize + element.padding
      let _right = element.left + element.width - element.padding - element.borderSize
@@ -258,7 +279,7 @@
      context.restore() // 重置画布
      if (elements.length > 0) {
        this.sketchothers(context, elements, selectId, ratio, resolve)
        this.sketchothers(context, elements, selectId, debug, ratio, resolve)
      } else {
        this.cachesketch(context, resolve)
      }
@@ -301,7 +322,7 @@
        context.restore() // 重置画布
        if (elements.length > 0) {
          this.sketchothers(context, elements, selectId, ratio, resolve)
          this.sketchothers(context, elements, selectId, debug, ratio, resolve)
        } else {
          this.cachesketch(context, resolve)
        }
@@ -314,7 +335,7 @@
  
          context.restore() // 重置画布
          if (elements.length > 0) {
            this.sketchothers(context, elements, selectId, ratio, resolve)
            this.sketchothers(context, elements, selectId, debug, ratio, resolve)
          } else {
            this.cachesketch(context, resolve)
          }
@@ -343,7 +364,7 @@
        context.restore() // 重置画布
        if (elements.length > 0) {
          this.sketchothers(context, elements, selectId, ratio, resolve)
          this.sketchothers(context, elements, selectId, debug, ratio, resolve)
        } else {
          this.cachesketch(context, resolve)
        }
@@ -353,7 +374,7 @@
  
          context.restore() // 重置画布
          if (elements.length > 0) {
            this.sketchothers(context, elements, selectId, ratio, resolve)
            this.sketchothers(context, elements, selectId, debug, ratio, resolve)
          } else {
            this.cachesketch(context, resolve)
          }
@@ -385,7 +406,7 @@
        
        context.restore() // 重置画布
        if (elements.length > 0) {
          this.sketchothers(context, elements, selectId, ratio, resolve)
          this.sketchothers(context, elements, selectId, debug, ratio, resolve)
        } else {
          this.cachesketch(context, resolve)
        }
@@ -395,7 +416,7 @@
  
          context.restore() // 重置画布
          if (elements.length > 0) {
            this.sketchothers(context, elements, selectId, ratio, resolve)
            this.sketchothers(context, elements, selectId, debug, ratio, resolve)
          } else {
            this.cachesketch(context, resolve)
          }
@@ -404,7 +425,7 @@
      image.onerror = () => {
        context.restore() // 重置画布
        if (elements.length > 0) {
          this.sketchothers(context, elements, selectId, ratio, resolve)
          this.sketchothers(context, elements, selectId, debug, ratio, resolve)
        } else {
          this.cachesketch(context, resolve)
        }