From d9ff374c80f3ed9077eae5136a7edea37668afbf Mon Sep 17 00:00:00 2001
From: zhou zhou <zozhouo3o@gmail.com>
Date: 星期五, 17 四月 2026 09:59:08 +0800
Subject: [PATCH] #条码自定义增加图片

---
 rsf-design/src/views/basic-info/wh-mat/matnrPrintTemplate.helpers.js |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/rsf-design/src/views/basic-info/wh-mat/matnrPrintTemplate.helpers.js b/rsf-design/src/views/basic-info/wh-mat/matnrPrintTemplate.helpers.js
index df53418..0ebb9ef 100644
--- a/rsf-design/src/views/basic-info/wh-mat/matnrPrintTemplate.helpers.js
+++ b/rsf-design/src/views/basic-info/wh-mat/matnrPrintTemplate.helpers.js
@@ -75,6 +75,25 @@
   return color || fallback
 }
 
+function getImageNaturalSize(element = {}) {
+  const naturalWidth = normalizeNumber(element?.naturalWidth, 0)
+  const naturalHeight = normalizeNumber(element?.naturalHeight, 0)
+  return {
+    naturalWidth,
+    naturalHeight
+  }
+}
+
+export function getImageMinHeight(width, element = {}, fallback = 8) {
+  const { naturalWidth, naturalHeight } = getImageNaturalSize(element)
+  if (naturalWidth > 0 && naturalHeight > 0) {
+    return Number(
+      ((Math.max(1, normalizeNumber(width, 1)) * naturalHeight) / naturalWidth).toFixed(2)
+    )
+  }
+  return Math.max(8, normalizeNumber(fallback, 8))
+}
+
 function createElementId(prefix = 'el') {
   return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`
 }
@@ -197,6 +216,14 @@
 
   if (base.type === 'qrcode') {
     base.resolvedValue = resolveTemplatePlaceholders(base.valueTemplate, record)
+    return base
+  }
+
+  if (base.type === 'image') {
+    base.resolvedSrc = normalizeText(base.src)
+    base.objectFit = ['contain', 'cover', 'fill'].includes(base.objectFit)
+      ? base.objectFit
+      : 'contain'
     return base
   }
 
@@ -380,6 +407,21 @@
     normalized.valueTemplate = normalizeText(element?.valueTemplate)
     normalized.w = Math.max(8, normalizeNumber(element?.w, 18))
     normalized.h = Math.max(8, normalizeNumber(element?.h, 18))
+    return normalized
+  }
+
+  if (normalized.type === 'image') {
+    normalized.src = normalizeText(element?.src)
+    normalized.objectFit = ['contain', 'cover', 'fill'].includes(element?.objectFit)
+      ? element.objectFit
+      : 'contain'
+    normalized.naturalWidth = Math.max(0, normalizeNumber(element?.naturalWidth, 0))
+    normalized.naturalHeight = Math.max(0, normalizeNumber(element?.naturalHeight, 0))
+    normalized.w = Math.max(8, normalizeNumber(element?.w, 20))
+    normalized.h = Math.max(
+      getImageMinHeight(normalized.w, element, normalizeNumber(element?.h, 20)),
+      normalizeNumber(element?.h, 20)
+    )
     return normalized
   }
 
@@ -645,6 +687,18 @@
     })
   }
 
+  if (type === 'image') {
+    return normalizeElement({
+      ...common,
+      w: 20,
+      h: 20,
+      src: '',
+      naturalWidth: 0,
+      naturalHeight: 0,
+      objectFit: 'contain'
+    })
+  }
+
   if (type === 'line') {
     return normalizeElement({
       ...common,

--
Gitblit v1.9.1