From 97d4a153c57d8a8c7845cecbf92a0e9bc698091f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 24 十一月 2022 16:31:39 +0800
Subject: [PATCH] 2022-11-24

---
 src/views/billprint/index.jsx |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/src/views/billprint/index.jsx b/src/views/billprint/index.jsx
index bc5c29d..379eecf 100644
--- a/src/views/billprint/index.jsx
+++ b/src/views/billprint/index.jsx
@@ -345,7 +345,7 @@
             component.cols = getColumns(component.cols)
           }
 
-          if (component.wrap.datatype === 'static') {
+          if (component.wrap && component.wrap.datatype === 'static') {
             component.format = ''
           }
     
@@ -704,6 +704,13 @@
     return image
   }
 
+  chartToImage(canvas) {
+    let image = new Image()
+    image.src = canvas.toDataURL('image/jpg')
+    image.style = `width:100%;height:${canvas.style.height || '100%'};`
+    return image
+  }
+
   print = () => {
     const { config, printing } = this.state
     
@@ -722,6 +729,21 @@
       }
     }
 
+    let charts = document.getElementsByTagName('canvas')
+
+    if (charts.length) {
+      for (let i = 0; i < charts.length; i++) {
+        let img = this.chartToImage(charts[i])
+        let parentNode = charts[i].parentNode
+  
+        parentNode.append(img)
+      }
+
+      while (charts[0]) {
+        charts[0].remove()
+      }
+    }
+
     let jubuData = document.getElementById('bill-print').innerHTML
 
     this.setState({printing: true})

--
Gitblit v1.8.0