zhou zhou
7 天以前 029559f7cedded183bd1fbd09a5ebb576a9fa21d
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
  }
@@ -383,6 +410,21 @@
    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
  }
  if (normalized.type === 'line') {
    normalized.direction = element?.direction === 'vertical' ? 'vertical' : 'horizontal'
    normalized.borderWidth = Math.max(0.2, normalizeNumber(element?.borderWidth, 0.4))
@@ -431,6 +473,10 @@
    }
    normalized.columns = normalizeTableColumns(element?.columns, normalized.w)
    normalized.rows = normalizeTableRows(element?.rows)
    normalized.w = Math.max(
      normalizeNumber(normalized.w, 0),
      normalized.columns.reduce((total, column) => total + normalizeNumber(column?.width, 0), 0)
    )
    normalized.h = Math.max(
      normalizeNumber(normalized.h, 0),
      normalized.rows.reduce((total, row) => total + normalizeNumber(row?.height, 0), 0)
@@ -645,6 +691,18 @@
    })
  }
  if (type === 'image') {
    return normalizeElement({
      ...common,
      w: 20,
      h: 20,
      src: '',
      naturalWidth: 0,
      naturalHeight: 0,
      objectFit: 'contain'
    })
  }
  if (type === 'line') {
    return normalizeElement({
      ...common,