From 89008530667bf165379dd3e99dc4ad5d81ecf187 Mon Sep 17 00:00:00 2001 From: yanran200730 Date: Sat, 26 Oct 2024 22:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/print/Print.vue | 35 +++++++++++++++++++++++++++------ src/view/lables/AddTemplate.vue | 26 +++++++++++++++++++----- src/view/lables/Template.vue | 9 ++++----- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/components/print/Print.vue b/src/components/print/Print.vue index 0761b1a..5a0b7e2 100644 --- a/src/components/print/Print.vue +++ b/src/components/print/Print.vue @@ -68,7 +68,7 @@
文字素材
@@ -279,6 +279,8 @@ this.buildLeftElement() this.buildDesigner() } + + this.getConfig() }, methods: { @@ -287,6 +289,12 @@ this.isShowDynamicForm = true }, + getConfig() { + this.$http.post(`/api/material/getPage`).then(res => { + + }) + }, + addImage(src) { this.panel.addPrintImage({ options: { @@ -303,12 +311,12 @@ el.design(void 0, designPaper) }, - addText(text) { + addText(text, isSetField = true) { this.panel.addPrintText({ options: { - field: text || '', - testData: text || '', - title: '', + field: isSetField ? text : '', + testData: isSetField ? text : '', + title: isSetField ? '' : text, left: 70.5, top: 58.5, width: 140, @@ -435,11 +443,26 @@ }) }, - getHtml() { + save() { + const html = this.elementToString(this.hiprintTemplate.getHtml(this.printData)) + const json = this.hiprintTemplate.getJson() + + return { + html, + json, + params: JSON.stringify(this.dynamicFromList) + } + }, + + preview() { this.html = this.elementToString(this.hiprintTemplate.getHtml(this.printData)) this.isShowPreview = true }, + getHtml() { + return this.elementToString(this.hiprintTemplate.getHtml(this.printData)) + }, + clearPaper() { this.hiprintTemplate.clear() }, diff --git a/src/view/lables/AddTemplate.vue b/src/view/lables/AddTemplate.vue index a0cb3a9..8620bb6 100644 --- a/src/view/lables/AddTemplate.vue +++ b/src/view/lables/AddTemplate.vue @@ -11,7 +11,7 @@ 下载pdf 打印 清空纸张 - 保存 + 保存 @@ -40,7 +40,9 @@ return { name: '', template: template, - printData: {} + printData: {}, + id: '', + isLoading: false } }, @@ -59,7 +61,7 @@ }, preview () { - this.$refs.printRef.getHtml() + this.$refs.printRef.preview() }, savePdf () { @@ -75,8 +77,22 @@ return this.$message.error('模板名称不能为空') } - const json = this.$refs.printRef.exportJson() - console.log(json) + const data = this.$refs.printRef.save() + console.log(data) + + this.isLoading = true + this.$http.post('/api/template/addTemplate', { + name: this.name, + codes: data.html, + content: JSON.stringify(data.json), + params: data.params + }).then(res => { + if (res.code === 0) { + this.isLoading = false + } + }).catch(() => { + this.isLoading = false + }) }, print() { diff --git a/src/view/lables/Template.vue b/src/view/lables/Template.vue index 8bdfd8b..21f6b60 100644 --- a/src/view/lables/Template.vue +++ b/src/view/lables/Template.vue @@ -61,7 +61,7 @@ }, created () { - // this.getList() + this.getList() }, methods: { @@ -74,15 +74,14 @@ }, getList () { - console.log(this.tableData) - this.$http.post('/api/learning/pluginPage', null, { + this.$http.post('/api/template/getPage', null, { params: { ...this.search } }).then(res => { if (res.code === 0) { - // this.tableData = res.data.records - // this.total = res.data.total + this.tableData = res.data.records + this.total = res.data.total } }) },