From f3d4db769ba9b51b799d981511a710fd443d0e08 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 21 四月 2025 12:18:03 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/views/printTemplate/print.js |   68 ++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/src/views/printTemplate/print.js b/src/views/printTemplate/print.js
index b2cbe6f..7089c83 100644
--- a/src/views/printTemplate/print.js
+++ b/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,22 +64,28 @@
    * @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()
 
-    if (element.rotate) { // 鍏冪礌鏃嬭浆鏃讹紝璁剧疆鐢诲竷鏃嬭浆瑙掑害
-      let _cx = element.left + element.width / 2
-      let _cy = element.top + element.height / 2
-      context.translate(_cx, _cy) // 绉诲姩鍘熺偣
-      context.rotate(element.rotate * Math.PI / 180)
-      context.translate(-_cx, -_cy) // 鎭㈠鍘熺偣
-    }
+    // if (element.rotate) { // 鍏冪礌鏃嬭浆鏃讹紝璁剧疆鐢诲竷鏃嬭浆瑙掑害
+    //   let _cx = element.left + element.width / 2
+    //   let _cy = element.top + element.height / 2
+    //   context.translate(_cx, _cy) // 绉诲姩鍘熺偣
+    //   context.rotate(element.rotate * Math.PI / 180)
+    //   context.translate(-_cx, -_cy) // 鎭㈠鍘熺偣
+    // }
 
     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
@@ -81,6 +94,7 @@
     // 缁樺埗杈规
     // context.rect(element.left + element.borderSize / 2, element.top + element.borderSize / 2, element.width - element.borderSize, element.height - element.borderSize)
     if (element.borderSize >= 1) {
+      context.beginPath()
       context.strokeStyle = element.borderColor
       context.lineWidth = element.borderSize
       context.rect(element.left, element.top, element.width, element.height)
@@ -117,7 +131,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 +145,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 +280,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 +323,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 +336,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 +365,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 +375,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)
           }
@@ -382,10 +404,10 @@
 
       if (image.complete) {
         context.drawImage(image, _left, _top, element.imgWidth, element.imgHeight)
-
+        
         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,12 +417,20 @@
   
           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)
           }
         }
       }
+      image.onerror = () => {
+        context.restore() // 閲嶇疆鐢诲竷
+        if (elements.length > 0) {
+          this.sketchothers(context, elements, selectId, debug, ratio, resolve)
+        } else {
+          this.cachesketch(context, resolve)
+        }
+      }
     }
   }
 

--
Gitblit v1.8.0