diff --git a/src/components/print/Print.vue b/src/components/print/Print.vue index bb96a10..4149eb2 100644 --- a/src/components/print/Print.vue +++ b/src/components/print/Print.vue @@ -9,10 +9,6 @@ 文本 -
- - 图片 -
长文 @@ -21,6 +17,10 @@  表格
+
+  + html +
辅助元素
@@ -210,7 +210,7 @@ // eslint-disable-next-line no-undef $('#hiprint-printTemplate').empty() this.hiprintTemplate = newHiprintPrintTemplate('temulables', { - template: {}, + template: template, settingContainer: '#PrintElementOptionSetting', fields: [{ field: 'html', diff --git a/src/components/print/customProvider.js b/src/components/print/customProvider.js index 377f58e..cb80613 100644 --- a/src/components/print/customProvider.js +++ b/src/components/print/customProvider.js @@ -13,8 +13,12 @@ export const customProvider = function (options) { console.log(data, options, templateData) const elId = options.elId || 'barCode-' + new Date().getTime() const codeWidth = parseInt((options.width - 22) * 0.85) + options.elId = `${elId}` + // eslint-disable-next-line no-undef - $('body').append(`
`) + $('body').append(`
+ +
`) // eslint-disable-next-line no-undef JsBarcode('#'+ elId, '96778555251', { format: "CODE128B", @@ -23,7 +27,6 @@ export const customProvider = function (options) { margin: 0, displayValue: false }) - options.elId = `${elId}` // eslint-disable-next-line no-undef const codeHtml = $(`#codewrapper-${elId}`).html() @@ -68,7 +71,68 @@ export const customProvider = function (options) { options: { width: 316, height: 120, - elId: '' + elId: '', + formatter: function (data, options, templateData) { + console.log(data, options, templateData) + const elId = options.elId || 'barCode-' + new Date().getTime() + const codeWidth = parseInt((options.width - 22) * 0.85) + options.elId = `${elId}` + + // eslint-disable-next-line no-undef + $('body').append(`
+ +
`) + // eslint-disable-next-line no-undef + JsBarcode('#'+ elId, '96778555251', { + format: "CODE128B", + width: 2, + height: parseInt(hinnn.pt.toPx(options.height - 22).toString()) * 0.6, + margin: 0, + displayValue: false + }) + + // eslint-disable-next-line no-undef + const codeHtml = $(`#codewrapper-${elId}`).html() + // eslint-disable-next-line no-undef + $(`body>#codewrapper-${elId}`).remove() + // eslint-disable-next-line no-undef + const resizeObserver = new ResizeObserver(() => { + JsBarcode('#'+ elId, '96778555251', { + format: "CODE128B", + width: 2, + height: parseInt(hinnn.pt.toPx(options.height - 22).toString()) * 0.6, + margin: 0, + displayValue: false + }) + }) + + setTimeout(() => { + const node = document.getElementById(`temuBarCode-${elId}`) + if (node) { + resizeObserver.observe(node) + } + }, 0) + var html = ` +
+
+
(AA+AAA)*20PCS
+
AA 20PCS+AAA 20PCS
+
+
+
+ ${codeHtml} +
+
+
+
1034130097
+
Made in China
+
+
+ ` + return html + }, + }, + printElementType: { } }, { diff --git a/src/utils/index.js b/src/utils/index.js index 31c1822..2563cb5 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -130,6 +130,7 @@ const initWindow = () => { }) window.eval = code => { + console.log(code) return interpreter.evaluate(transformCode(code)) } window.JsBarcode = JsBarcode