From f99e3966686d3891b814ff28d200b001fcdc8e1e Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 二月 2026 12:54:26 +0800
Subject: [PATCH] 组托优化

---
 rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx b/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
index 99d2114..4ae47d3 100644
--- a/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
+++ b/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
@@ -226,14 +226,6 @@
                 }
             }))
             setData(val)
-            setTimeout(() => {
-                val.forEach((el) => {
-                    jsbarcode(`#barcode${el.code}`, el.code, { height: 30 });
-                });
-            }, 10);
-
-
-
         } else {
             notify(res.data.msg);
         }
@@ -243,8 +235,26 @@
         if (rows?.length > 0) {
             http();
         }
-
     }, [rows]);
+
+    // 鍦ㄦ暟鎹洿鏂板悗鐢熸垚鏉$爜
+    useEffect(() => {
+        if (data.length > 0) {
+            // 绛夊緟DOM鏇存柊鍚庡啀鐢熸垚鏉$爜
+            setTimeout(() => {
+                data.forEach((item) => {
+                    const barcodeElement = document.getElementById(`barcode${item.code}`);
+                    if (barcodeElement) {
+                        try {
+                            jsbarcode(`#barcode${item.code}`, item.code, { height: 30 });
+                        } catch (error) {
+                            console.error(`鐢熸垚鏉$爜澶辫触: ${item.code}`, error);
+                        }
+                    }
+                });
+            }, 100);
+        }
+    }, [data]);
 
 
     return (
@@ -275,8 +285,7 @@
                                 colSpan={9}
                                 style={{ border: '1px solid black' }}
                             >
-                                {/* <img id={"barcode" + item.code} style={{ width: '70%', verticalAlign: 'middle' }} /> */}
-                                <img className="template-code" src={item.barcode} style={{ width: '90%', verticalAlign: 'middle' }} alt="Barcode" />
+                                <img id={`barcode${item.code}`} style={{ width: '90%', verticalAlign: 'middle' }} alt="Barcode" />
                                 <div style={{ letterSpacing: '2px', marginTop: '1px', textAlign: 'center' }}>
                                     <span>{item.code}</span>
                                 </div>

--
Gitblit v1.9.1