【新增】模板接口对接

This commit is contained in:
yanran200730
2024-10-26 22:49:11 +08:00
parent 4f4f303867
commit 8900853066
3 changed files with 54 additions and 16 deletions

View File

@@ -68,7 +68,7 @@
<div>文字素材</div> <div>文字素材</div>
</div> </div>
<div class="print-images"> <div class="print-images">
<p v-for="(item, index) in 20" @click="addText(`EVATOST CONSULTING LTD CONSULTING CONSULTING CONSULTING CONSULTING`)" :key="index">EVATOST CONSULTING LTD</p> <p v-for="(item, index) in 20" @click="addText(`EVATOST CONSULTING LTD CONSULTING CONSULTING CONSULTING CONSULTING`, false)" :key="index">EVATOST CONSULTING LTD</p>
</div> </div>
</el-popover> </el-popover>
</div> </div>
@@ -279,6 +279,8 @@
this.buildLeftElement() this.buildLeftElement()
this.buildDesigner() this.buildDesigner()
} }
this.getConfig()
}, },
methods: { methods: {
@@ -287,6 +289,12 @@
this.isShowDynamicForm = true this.isShowDynamicForm = true
}, },
getConfig() {
this.$http.post(`/api/material/getPage`).then(res => {
})
},
addImage(src) { addImage(src) {
this.panel.addPrintImage({ this.panel.addPrintImage({
options: { options: {
@@ -303,12 +311,12 @@
el.design(void 0, designPaper) el.design(void 0, designPaper)
}, },
addText(text) { addText(text, isSetField = true) {
this.panel.addPrintText({ this.panel.addPrintText({
options: { options: {
field: text || '', field: isSetField ? text : '',
testData: text || '', testData: isSetField ? text : '',
title: '', title: isSetField ? '' : text,
left: 70.5, left: 70.5,
top: 58.5, top: 58.5,
width: 140, 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.html = this.elementToString(this.hiprintTemplate.getHtml(this.printData))
this.isShowPreview = true this.isShowPreview = true
}, },
getHtml() {
return this.elementToString(this.hiprintTemplate.getHtml(this.printData))
},
clearPaper() { clearPaper() {
this.hiprintTemplate.clear() this.hiprintTemplate.clear()
}, },

View File

@@ -11,7 +11,7 @@
<el-button @click="savePdf" size="small" type="primary">下载pdf</el-button> <el-button @click="savePdf" size="small" type="primary">下载pdf</el-button>
<el-button @click="print" size="small">打印</el-button> <el-button @click="print" size="small">打印</el-button>
<el-button @click="clearPaper" size="small" type="danger">清空纸张</el-button> <el-button @click="clearPaper" size="small" type="danger">清空纸张</el-button>
<el-button @click="saveTemplate" size="small" type="primary">保存</el-button> <el-button @click="saveTemplate" size="small" type="primary" :loading="isLoading">保存</el-button>
</template> </template>
</ai-title> </ai-title>
</template> </template>
@@ -40,7 +40,9 @@
return { return {
name: '', name: '',
template: template, template: template,
printData: {} printData: {},
id: '',
isLoading: false
} }
}, },
@@ -59,7 +61,7 @@
}, },
preview () { preview () {
this.$refs.printRef.getHtml() this.$refs.printRef.preview()
}, },
savePdf () { savePdf () {
@@ -75,8 +77,22 @@
return this.$message.error('模板名称不能为空') return this.$message.error('模板名称不能为空')
} }
const json = this.$refs.printRef.exportJson() const data = this.$refs.printRef.save()
console.log(json) 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() { print() {

View File

@@ -61,7 +61,7 @@
}, },
created () { created () {
// this.getList() this.getList()
}, },
methods: { methods: {
@@ -74,15 +74,14 @@
}, },
getList () { getList () {
console.log(this.tableData) this.$http.post('/api/template/getPage', null, {
this.$http.post('/api/learning/pluginPage', null, {
params: { params: {
...this.search ...this.search
} }
}).then(res => { }).then(res => {
if (res.code === 0) { if (res.code === 0) {
// this.tableData = res.data.records this.tableData = res.data.records
// this.total = res.data.total this.total = res.data.total
} }
}) })
}, },