From 432d4351d36545fe9c47978df0ace8e4dc601c84 Mon Sep 17 00:00:00 2001 From: yanran200830 Date: Tue, 22 Oct 2024 11:10:13 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E5=AE=8C?= =?UTF-8?q?=E6=88=90temu=E6=A0=87=E7=AD=BE=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/print/customProvider.js | 42 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/components/print/customProvider.js b/src/components/print/customProvider.js index 55dd1b8..50378e1 100644 --- a/src/components/print/customProvider.js +++ b/src/components/print/customProvider.js @@ -1,6 +1,6 @@ import { hiprint } from 'vue-plugin-hiprint' export const customProvider = function (options) { - var addElementTypes = function (context) { + const addElementTypes = function (context) { context.removePrintElementTypes('customProvider') context.addPrintElementTypes('customProvider', [ new hiprint.PrintElementTypeGroup('', [ @@ -9,31 +9,48 @@ export const customProvider = function (options) { title: 'temu条码', data: 'XS888888888', type: 'html', - formatter: function (title, options, templateData) { - console.log(options, templateData) - var elId = 'barCode-' + new Date().getTime() + formatter: function (data, options, templateData, e, x, target) { + console.log(data, options, templateData) + const elId = options.elId || 'barCode-' + new Date().getTime() + // eslint-disable-next-line no-undef $('body').append('') - // eslint-disable-next-line no-undef JsBarcode('#'+ elId, '96778555251', { format: "CODE128B", width: 2, - height: options.height * 0.6 + 4, + height: parseInt(hinnn.pt.toPx(options.height - 20).toString()) * 0.6 - 3, margin: 0, displayValue: false }) + options.elId = `${elId}` // eslint-disable-next-line no-undef const codeHtml = $(`#${elId}`).html() // eslint-disable-next-line no-undef $(`#${elId}`).remove() // eslint-disable-next-line no-undef - $('document').on('resize', `#${elId}`, e => { - console.log(e) - }); + const resizeObserver = new ResizeObserver(() => { + JsBarcode('#'+ elId, '96778555251', { + format: "CODE128B", + width: 2, + height: parseInt(hinnn.pt.toPx(options.height - 20).toString()) * 0.6 - 3, + margin: 0, + displayValue: false + }) + + const codeWidth = $(`#temuBarCode-${elId} .temuBarCode-code`).width() + $(`#${elId}`).css('width', codeWidth + 'px') + }) + + setTimeout(() => { + const node = document.getElementById(`temuBarCode-${elId}`) + if (node) { + resizeObserver.observe(node) + } + }, 20) var html = ` -
+
(AA+AAA)*20PCS
AA 20PCS+AAA 20PCS
@@ -55,7 +72,8 @@ export const customProvider = function (options) { }, options: { width: 316, - height: 120 + height: 120, + elId: '' } }, { @@ -99,6 +117,6 @@ export const customProvider = function (options) { ]) } return { - addElementTypes: addElementTypes + addElementTypes } }