赞
踩
基于hiprint 的vue-plugin-hiprint来打印
hiprint地址:hiprint.io
实现点击某些行的数据,然后点击打印按钮直接弹出下面的打印框
npm install vue-plugin-hiprint
- <link rel="stylesheet" type="text/css" media="print" href="https://cdn.jsdelivr.net/npm/vue-plugin-hiprint@latest/dist/print-lock.css">
- <!-- * 以处理打印所需css, 当然你也可以自行处理-->
- <!-- * 比如: index.html目录下放一个print-lock.css, 然后在index.html添加:-->
- <link rel="stylesheet" type="text/css" media="print" href="/print-lock.css">
- import {hiPrintPlugin} from 'vue-plugin-hiprint'
- Vue.use(hiPrintPlugin, '$pluginName')
this.printTemplate是在hiprint.io中生成的
- handlePrint(){
- this.$pluginName.init();
- let hiprintTemplate = new this.$pluginName.PrintTemplate({
- template: JSON.parse(this.printTemplate),
- });
- var selectedData=this.selectedData;
- hiprintTemplate.print(selectedData);
- }
- {
- "panels": [
- {
- "index": 0,
- "name": 1,
- "height": 297,
- "width": 210,
- "paperHeader": 49.5,
- "paperFooter": 780,
- "printElements": [
- {
- "options": {
- "left": 17.5,
- "top": 87.5,
- "height": 72,
- "width": 550,
- "textAlign": "center",
- "field": "printData",
- "coordinateSync": false,
- "widthHeightSync": false,
- "columns": [
- [
- {
- "width": 40,
- "title": "字段1",
- "field": "one",
- "checked": true,
- "columnId": "one",
- "fixed": false,
- "align": "center"
- },
- {
- "width": 40,
- "title": "字段2",
- "field": "two",
- "checked": true,
- "columnId": "two",
- "fixed": false,
- "rowspan": 1,
- "colspan": 1
- },
- {
- "width": 40,
- "title": "字段三",
- "field": "three",
- "checked": true,
- "columnId": "three",
- "fixed": false,
- "rowspan": 1,
- "colspan": 1
- }
- ]
- ]
- },
- "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
- }
- }
- ],
- "paperNumberLeft": 565.5,
- "paperNumberTop": 819,
- "paperNumberContinue": true,
- "watermarkOptions": {
- "content": "vue-plugin-hiprint",
- "rotate": 25,
- "timestamp": true,
- "format": "YYYY-MM-DD HH:mm"
- }
- }
- ]
- }

- {
- printData: [{
- one: '第一行第一列内容',
- two: '第一行第二列内容',
- three: '第一行第三列内容'
- },
- {
- one: '第二行第一列内容',
- two: '第二行第二列内容',
- three: '第二行第三列内容'
- }]
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。