From 2d704fb62459923206071b319f8423c3381145f8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 11 六月 2025 00:18:20 +0800
Subject: [PATCH] 2025-06-11

---
 src/components/barcode/index.jsx |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/components/barcode/index.jsx b/src/components/barcode/index.jsx
index c7dd144..488ed7a 100644
--- a/src/components/barcode/index.jsx
+++ b/src/components/barcode/index.jsx
@@ -11,6 +11,10 @@
     value: PropTypes.any,    // 鏉$爜鍊�
   }
 
+  state = {
+    error: false
+  }
+
   componentDidMount () {
     this.resetBarcode()
   }
@@ -28,22 +32,30 @@
 
     let style = card.style || {}
 
-    JsBarcode(this.barcode, value, {
-      displayValue: card.displayValue === 'true',
-      width: card.interval || 1,
-      height: card.barHeight || 25,
-      margin: 0,
-      fontOptions: `${style.fontWeight || ''} ${style.fontStyle || ''}`,
-      textAlign: style.textAlign || 'left',
-      fontSize: (style.fontSize || 14) + 'px',
-      lineColor: style.color || '#000000'
-    })
+    try {
+      JsBarcode(this.barcode, value, {
+        displayValue: card.displayValue === 'true',
+        width: card.interval || 1,
+        height: card.barHeight || 25,
+        margin: 0,
+        fontOptions: `${style.fontWeight || ''} ${style.fontStyle || ''}`,
+        textAlign: style.textAlign || 'left',
+        fontSize: (style.fontSize || 14) + 'px',
+        lineColor: style.color || '#000000'
+      })
+      this.setState({error: false})
+    } catch (e) {
+      this.setState({error: true})
+    }
 
   }
 
   render() {
+    const { error } = this.state
+
     return (
       <div className="barcode-box">
+        {error ? <span className="barcode-error">瀛楃闈炴硶鎴栬繃闀匡紒</span> : null}
         <svg ref={(ref) => { this.barcode = ref }}/>
       </div>
     )

--
Gitblit v1.8.0