diff --git a/src/components/print/Print.vue b/src/components/print/Print.vue index 4149eb2..94af05a 100644 --- a/src/components/print/Print.vue +++ b/src/components/print/Print.vue @@ -43,21 +43,19 @@
常用元素
-
- - 横线 -
-
- - 竖线 -
-
- - 矩形 -
-
- - 圆形 +
+
+ 动态数据(如日期) + 添加 +
+
+
+
{{ item.fieldValue }}
@@ -108,6 +106,20 @@ 取消 + + + + + + + @@ -168,7 +180,13 @@ }, paperPopVisible: false, paperWidth: 200, - paperHeight: 200 + paperHeight: 200, + isShowDynamicForm: false, + dynamicFrom: { + + }, + dynamicFromList: [], + panel: null } }, @@ -197,6 +215,41 @@ }, methods: { + addField() { + this.$set(this.dynamicFrom, `field${this.dynamicFromList.length}`, '') + this.isShowDynamicForm = true + }, + + addItemToCanvas(name) { + this.panel.addPrintText({ + type: 'text', + data: 'XS888888888', + options: { + field: 'barcode', + testData: 'XS888888888', + height: 32, + fontSize: 12, + lineHeight: 18, + textAlign: 'left', + textType: 'barcode', + hideTitle: true + } + }); + }, + + onConfirm() { + this.$refs.form.validate((valid) => { + if (valid) { + this.dynamicFromList.push({ + fieldName: `field${this.dynamicFromList.length}`, + fieldValue: this.dynamicFrom[`field${this.dynamicFromList.length}`] + }) + + this.isShowDynamicForm = false + } + }) + }, + buildLeftElement() { // eslint-disable-next-line no-undef hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item')) @@ -210,12 +263,8 @@ // eslint-disable-next-line no-undef $('#hiprint-printTemplate').empty() this.hiprintTemplate = newHiprintPrintTemplate('temulables', { - template: template, + template: {}, settingContainer: '#PrintElementOptionSetting', - fields: [{ - field: 'html', - - }], onImageChooseClick: (target) => { let input = document.createElement('input') input.setAttribute('type', 'file') @@ -234,10 +283,12 @@ } }) + this.$nextTick(() => { this.hiprintTemplate.design('#hiprint-printTemplate', { grid: true }) + console.log(this.hiprintTemplate.printPanels[0]) }) }, @@ -387,6 +438,10 @@ overflow-y: auto; .title { + display: flex; + align-items: center; + justify-content: space-between; + width: 320px; margin: 14px 0; } diff --git a/src/components/print/customProvider.js b/src/components/print/customProvider.js index cb80613..f6dc3a5 100644 --- a/src/components/print/customProvider.js +++ b/src/components/print/customProvider.js @@ -71,66 +71,7 @@ export const customProvider = function (options) { options: { width: 316, height: 120, - 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 - }, + elId: '' }, printElementType: { } @@ -168,7 +109,7 @@ export const customProvider = function (options) { }, { tid: 'providerModule1.image', - title: 'Logo', + title: '图片', data: 'https://foruda.gitee.com/avatar/1677050350324030848/5400665_ccsimple_1591166830.png!avatar200', type: 'image' } diff --git a/src/utils/index.js b/src/utils/index.js index 4bfed1f..8772501 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -128,7 +128,6 @@ const initWindow = () => { window.JsBarcode = JsBarcode window.eval = (code, context) => { - console.log(code) const interpreter = new Interpreter(context || window, { timeout: 1000, })