diff --git a/res/template4.png b/res/template4.png new file mode 100644 index 00000000..8fb2fdb5 Binary files /dev/null and b/res/template4.png differ diff --git a/src/demo/templates/preview.vue b/src/demo/templates/preview.vue index 662d8379..1fc0e53c 100644 --- a/src/demo/templates/preview.vue +++ b/src/demo/templates/preview.vue @@ -56,12 +56,15 @@ export default { // 数据 name: '名称', json: {}, - printData: {} + printData: {}, + // 扩展 css + extendCss: '' } }, methods: { hideModal() { this.visible = false + $("link[media=print]").empty(); }, show(template) { let that = this; @@ -71,6 +74,10 @@ export default { this.name = template.name this.json = template.json this.printData = template.printData + this.extendCss = template.extendCss || ""; + if (this.extendCss.length > 1) { + $(this.extendCss).appendTo($("link[media=print]")); + } let isMounted = $('#template-preview').length <= 0 || $('#template-preview-setting').length <= 0; do { setTimeout(() => { @@ -89,20 +96,33 @@ export default { } while (isMounted) }, print() { + let that = this; this.waitShowPrinter = true this.hiprintTemplate.print(this.printData, {}, { callback: () => { this.waitShowPrinter = false + }, + styleHandler: () => { + return that.extendCss } }) }, toPdf() { - this.hiprintTemplate.toPdf(this.printData, this.name); + let that = this; + this.hiprintTemplate.toPdf(this.printData, this.name, { + styleHandler: () => { + return that.extendCss + } + }); }, print2() { if (hiprint.hiwebSocket.opened) { + let that = this; this.hiprintTemplate.print2(this.printData, { printer: '', title: this.name, + styleHandler: () => { + return that.extendCss + } }) } else this.$message.error('请先连接直接打印客户端') diff --git a/src/demo/templates/template-files/template4.js b/src/demo/templates/template-files/template4.js new file mode 100644 index 00000000..df1cc658 --- /dev/null +++ b/src/demo/templates/template-files/template4.js @@ -0,0 +1,630 @@ +export const name = '自定义渲染表格'; +export const desc = '不一样的表格显示效果'; +export const author = '群友提供' +export const link = 'https://github.com/CcSimple' +// url 或者 base64 或者 require('../../../assets/logo.png') +export const preview = 'https://gitee.com/CcSimple/vue-plugin-hiprint/raw/main/res/template4.png'; +export const extendCss = "" +export const printData = { + title: 'XXXX有限公司', // 标题 + orderId: 'XY202304001', // 订单号 + workId: 'GLSW2023001', // 工程单号 + work_info: [ + { + workId: 'GLSW2023001', // 工程单号 + order_date: '2023-06-03', // 订单日期 + customer: '广州戈蓝生物科技有限公司', // 客户名称 + quality: '做工精细注意细节', // 质量要求 + delivery_date: '2023-06-31', // 交货日期 + } + ], + printDate: '2023/06/03 12:00:00', // 打印日期 + creater: '张三', // 制单人 + checker: '李四', // 审核人 + product_info: [ // 产品信息 + { + product_type: '精装盒', + product_name: 'Benggre臻护凝时皮肤管理套', + product_size: '380*280*45', + product_quantity: 1000, + product_packing: '纸包', + workmanship: '手工、粘、啤', + yinshuase: '四色', + wenjian: '新', + yangpin: '有', + remark: '不明白请及时问清楚', // 备注 + material: [ + { + type_name: '面纸', + name: '350克冰白珠光纸', + quantity: 1400, + size: '787*880(各拼一个)', + warkmanship: '哑胶、浮雕烫金、烫金、击凸、单面印' + }, + {type_name: '内盒卡纸', name: '350克单铜', quantity: 2300, size: '787*880(各拼一个)', warkmanship: ''}, + ] + }, + { + product_type: '精装盒', + product_name: 'Benggre肌肤水润嫩滑肌套', + product_size: '380*280*45', + product_quantity: 1000, + product_packing: '纸包', + workmanship: '哑胶、浮雕烫金、烫金、击凸、手工、粘、啤、单面印', + yinshuase: '四色', + wenjian: '新', + yangpin: '有', + remark: '不明白请及时问清楚', // 备注 + material: [ + { + type_name: '面纸', + name: '350克冰白珠光纸', + quantity: 1400, + size: '787*880(各拼一个)', + warkmanship: '哑胶、浮雕烫金、烫金、击凸、单面印' + }, + {type_name: '内盒卡纸', name: '350克单铜', quantity: 2300, size: '787*880(各拼一个)', warkmanship: ''}, + ] + } + ], + order_remark: 'Benggre臻护凝时皮肤管理套 (尺寸:380*280*45数量1000个)2、Benggre肌肤水润嫩滑肌套 (尺寸:380*280*45数量1000个)3、Benggre光感焕肤套 (尺寸:340*260*45数量1000个)4、Benggre三纹鱼舒缓倍护能量套 (尺寸:380*280*45数量1000个):350克冰白珠光纸四色印刷,工艺烫金、佛雕烫金、激凸,内盒350克单铜过哑膜啤折盒,内有吸塑要放吸塑进去注意质量不要开胶烫金不清晰磨花等情况。跟进一下客户的纸箱', +} +export const json = { + "panels": [ + { + "index": "0", + "name": "1", + "height": 296, + "width": 210, + "paperHeader": "66", + "paperFooter": 813, + "printElements": [ + { + "options": { + "left": 145, + "top": 12.5, + "height": 19.5, + "width": 316.5, + "field": "title", + "testData": "xxxxx有限公司", + "fontSize": 20.25, + "letterSpacing": 6, + "fontWeight": "700", + "textContentVerticalAlign": "middle", + "hideTitle": true, + "title": "企业名称", + "right": 461.25, + "bottom": 33, + "vCenter": 303, + "hCenter": 23.25, + "coordinateSync": false, + "widthHeightSync": false, + "qrCodeLevel": 0, + "textAlign": "center" + }, + "printElementType": { + "title": "企业名称", + "type": "text" + } + }, + { + "options": { + "left": 507, + "top": 15, + "height": 42, + "width": 42, + "field": "workId", + "testData": "MGPT2023002", + "fontSize": 12, + "lineHeight": 18, + "textType": "qrcode", + "title": "二维码", + "right": 549, + "bottom": 51, + "vCenter": 528, + "hCenter": 30, + "coordinateSync": false, + "widthHeightSync": false, + "qrCodeLevel": 0 + }, + "printElementType": { + "title": "二维码", + "type": "text" + } + }, + { + "options": { + "left": 247.5, + "top": 37.5, + "height": 19.5, + "width": 100.5, + "title": "工程单", + "right": 347.25, + "bottom": 42.75, + "vCenter": 297, + "hCenter": 37.875, + "coordinateSync": false, + "widthHeightSync": false, + "fontSize": 18, + "fontWeight": "400", + "letterSpacing": 9, + "textAlign": "center", + "textContentVerticalAlign": "middle", + "lineHeight": 18, + "qrCodeLevel": 0 + }, + "printElementType": { + "title": "文本", + "type": "text" + } + }, + { + "options": { + "left": 13.5, + "top": 45, + "height": 16, + "width": 120, + "field": "orderId", + "testData": "XY20230602001", + "fontSize": 6.75, + "textAlign": "center", + "textContentVerticalAlign": "middle", + "title": "订单编号", + "right": 124.5, + "bottom": 60.25, + "vCenter": 64.5, + "hCenter": 52.25, + "coordinateSync": false, + "widthHeightSync": false, + "qrCodeLevel": 0 + }, + "printElementType": { + "title": "订单编号", + "type": "text" + } + }, + { + "options": { + "left": 7.5, + "top": 61.5, + "height": 9, + "width": 577.5, + "right": 96.75, + "bottom": 64.5, + "vCenter": 51.75, + "hCenter": 60 + }, + "printElementType": { + "title": "横线", + "type": "hline" + } + }, + { + "options": { + "left": 28.5, + "top": 70.5, + "height": 36, + "width": 538.5, + "field": "work_info", + "fields": [ + { + "text": "订单日期", + "field": "order_date" + }, + { + "text": "工程单号", + "field": "workId" + }, + { + "text": "客户名称", + "field": "customer" + }, + { + "text": "交货日期", + "field": "delivery_date" + }, + { + "text": "质量要求", + "field": "quality" + } + ], + "right": 578.5, + "bottom": 109.5, + "vCenter": 303.5, + "hCenter": 91.5, + "coordinateSync": false, + "widthHeightSync": false, + "columns": [ + [ + { + "width": 78.01380865921793, + "title": "订单日期", + "field": "order_date", + "checked": true, + "columnId": "order_date", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "center" + }, + { + "width": 82.37420460893856, + "title": "工程单号", + "field": "workId", + "checked": true, + "columnId": "workId", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "center" + }, + { + "width": 164.95573673184356, + "title": "客户名称", + "field": "customer", + "checked": true, + "columnId": "customer", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "left", + "tableQRCodeLevel": 0, + "tableSummaryTitle": true, + "tableSummary": "" + }, + { + "width": 90.0673840782123, + "title": "交货日期", + "field": "delivery_date", + "checked": true, + "columnId": "delivery_date", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "center" + }, + { + "width": 123.08886592178769, + "title": "质量要求", + "field": "quality", + "checked": true, + "columnId": "quality", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "left", + "tableQRCodeLevel": 0, + "tableSummaryTitle": true, + "tableSummary": "" + } + ] + ] + }, + "printElementType": { + "title": "订单信息(表格)", + "type": "table", + "editable": true, + "columnDisplayEditable": true, + "columnDisplayIndexEditable": true, + "columnTitleEditable": true, + "columnResizable": true, + "columnAlignEditable": true, + "isEnableEditField": true, + "isEnableContextMenu": true, + "isEnableInsertRow": true, + "isEnableDeleteRow": true, + "isEnableInsertColumn": true, + "isEnableDeleteColumn": true, + "isEnableMergeCell": true + } + }, + { + "options": { + "left": 25.5, + "top": 123, + "height": 126, + "width": 546, + "tableFooterRepeat": "no", + "field": "product_info", + "fields": [ + { + "text": "类型", + "field": "product_type" + } + ], + "right": 573, + "bottom": 248.25, + "vCenter": 300, + "hCenter": 185.25, + "coordinateSync": false, + "widthHeightSync": false, + "tableHeaderRepeat": "none", + "tableBorder": "noBorder", + "tableHeaderBorder": "noBorder", + "tableHeaderCellBorder": "noBorder", + "tableBodyRowBorder": "noBorder", + "tableBodyCellBorder": "noBorder", + "tableFooterBorder": "noBorder", + "tableFooterCellBorder": "noBorder", + "columns": [ + [ + { + "width": 546, + "title": "类型", + "field": "product_type", + "checked": true, + "columnId": "product_type", + "fixed": false, + "rowspan": 1, + "colspan": 1, + "align": "left", + "renderFormatter": "function(value,row,index,options){\n let rowTemplate = '';\n rowTemplate += `\n