vg-print-vue2 1.0.210 → 1.0.301
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +17 -5
- package/README.md +27 -31
- package/dist/style.css +459 -254
- package/dist/vg-print-vue2.es.js +15799 -43756
- package/package.json +14 -15
package/README.en.md
CHANGED
|
@@ -33,6 +33,21 @@ https://download.csdn.net/download/github_38400706/92538739
|
|
|
33
33
|
npm i vg-print-vue2
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
If you need client direct printing (`hiwebSocket`), install the optional dependency in your host app:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm i socket.io-client
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
In your main entry file (e.g., `main.ts`):
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { io } from 'socket.io-client'
|
|
46
|
+
import { setSocketIo } from 'vg-print'
|
|
47
|
+
|
|
48
|
+
setSocketIo(io)
|
|
49
|
+
```
|
|
50
|
+
|
|
36
51
|
## Header Component
|
|
37
52
|
|
|
38
53
|
- Used for the top area of the page, with built-in common operation buttons and printer settings; supports customization via `props` and `slots`.
|
|
@@ -372,9 +387,9 @@ new Vue({
|
|
|
372
387
|
- `printView()` Browser print
|
|
373
388
|
- `print()` Direct print
|
|
374
389
|
- `toPdf()` Export PDF
|
|
375
|
-
- `
|
|
390
|
+
- `toPdf()` Export PDF with paper layout
|
|
376
391
|
- `toImage()` Export Image
|
|
377
|
-
- `
|
|
392
|
+
- `toImage()` Export Image with paper layout
|
|
378
393
|
- `toImage()` Export Image
|
|
379
394
|
- `setHiwebSocket(host, token, cb)` Set client address/token (Respects autoConnect state)
|
|
380
395
|
- `setHost(host, token, cb)` Set client address/token and connect immediately (Standard API)
|
|
@@ -437,10 +452,7 @@ exportPdf(tpl, printData, 'filename')
|
|
|
437
452
|
`exportPdf` / `exportImage` are lightweight wrappers around the template instance methods:
|
|
438
453
|
|
|
439
454
|
- `exportPdf(tpl, data, filename, options)` → `tpl.toPdf(data, filename, options)`
|
|
440
|
-
- `exportPdf2(tpl, data, filename, options)` → `tpl.toPdf2(data, filename, options)`
|
|
441
|
-
|
|
442
455
|
- `exportImage(tpl, data, options)` → `tpl.toImage(data, options)`
|
|
443
|
-
- `exportImage2(tpl, data, options)` → `tpl.toImage2(data, options)`
|
|
444
456
|
|
|
445
457
|
#### Export PDF
|
|
446
458
|
|
package/README.md
CHANGED
|
@@ -109,6 +109,25 @@ hiprint.register({
|
|
|
109
109
|
```bash
|
|
110
110
|
npm i vg-print-vue2
|
|
111
111
|
```
|
|
112
|
+
### 可选依赖:直连打印/客户端连接(socket.io-client)
|
|
113
|
+
|
|
114
|
+
- 本库默认不内置 `socket.io-client`,以减少默认安装体积。
|
|
115
|
+
- 仅当你需要“直连打印/客户端连接(hiwebSocket)”能力(如 `print()` / `print2()` / 自动连接)时,才需要安装并注入:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm i socket.io-client
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
在项目入口(如 `main.ts`)注入:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import { io } from 'socket.io-client'
|
|
125
|
+
import { setSocketIo } from 'vg-print'
|
|
126
|
+
|
|
127
|
+
setSocketIo(io)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
也可直接使用 `window.io = io`(等价)。
|
|
112
131
|
|
|
113
132
|
## Header 顶部工具栏组件
|
|
114
133
|
|
|
@@ -680,10 +699,8 @@ export default {
|
|
|
680
699
|
- `preView()` 打开预览弹窗;将当前模板与数据渲染为预览 HTML
|
|
681
700
|
- `printView()` 浏览器打印;不依赖客户端,调起系统打印对话框
|
|
682
701
|
- `print()` 直接打印;需客户端已连接,按当前选定打印机输出
|
|
683
|
-
- `toPdf()` 导出 PDF
|
|
684
|
-
- `
|
|
685
|
-
- `toImage()` 导出图片;使用内置 A4 排版示例参数导出
|
|
686
|
-
- `toImage2()` 导出图片;支持自定义参数,如缩放比例、页边距等(通过@zumer/snapdom库插件)
|
|
702
|
+
- `toPdf()` 导出 PDF;当前统一使用 `@zumer/snapdom` 渲染,支持缩放比例、页边距等参数
|
|
703
|
+
- `toImage()` 导出图片;当前统一使用 `@zumer/snapdom` 渲染,支持缩放比例、页边距等参数
|
|
687
704
|
|
|
688
705
|
- `setHiwebSocket(host: string, token?: string, cb?: Function)` 设置客户端地址与令牌并尝试重连;`cb(status, msg)` 为连接回调
|
|
689
706
|
- `connect(cb?: Function)` 主动连接客户端;`cb(status, msg)` 为连接回调
|
|
@@ -878,8 +895,8 @@ tpl.toPdf(this.printDataVar, '打印预览pdf', {
|
|
|
878
895
|
}
|
|
879
896
|
}
|
|
880
897
|
});
|
|
881
|
-
//
|
|
882
|
-
tpl.
|
|
898
|
+
// 当前 toPdf 内部统一使用 @zumer/snapdom 导出 PDF
|
|
899
|
+
tpl.toPdf(this.printDataVar, '打印预览pdf', {
|
|
883
900
|
onProgress: (cur, total) => {
|
|
884
901
|
// 导出进度100%的时候关闭等待
|
|
885
902
|
if (cur === total) {
|
|
@@ -924,8 +941,8 @@ tpl.toImage(this.printDataVar, {
|
|
|
924
941
|
}
|
|
925
942
|
})
|
|
926
943
|
|
|
927
|
-
//
|
|
928
|
-
tpl.
|
|
944
|
+
// 当前 toImage 内部统一使用 @zumer/snapdom 导出图片
|
|
945
|
+
tpl.toImage(this.printDataVar, {
|
|
929
946
|
paperWidth: 210,
|
|
930
947
|
paperHeight: 297,
|
|
931
948
|
limit: 6,
|
|
@@ -955,9 +972,7 @@ import {
|
|
|
955
972
|
getHtml,
|
|
956
973
|
printBrowser,
|
|
957
974
|
exportPdf,
|
|
958
|
-
exportPdf2,
|
|
959
975
|
exportImage,
|
|
960
|
-
exportImage2,
|
|
961
976
|
getPrinterList,
|
|
962
977
|
refreshPrinterList,
|
|
963
978
|
getAddress,
|
|
@@ -1020,7 +1035,7 @@ exportPdf(tpl, printData, '打印预览pdf', {
|
|
|
1020
1035
|
})
|
|
1021
1036
|
|
|
1022
1037
|
// 插件方法
|
|
1023
|
-
|
|
1038
|
+
exportPdf(tpl, printData, '打印预览pdf', {
|
|
1024
1039
|
paperWidth: 210,
|
|
1025
1040
|
paperHeight: 297,
|
|
1026
1041
|
perPage: 6,
|
|
@@ -1052,7 +1067,7 @@ await exportImage(tpl, printData, {
|
|
|
1052
1067
|
})
|
|
1053
1068
|
|
|
1054
1069
|
// 插件方法
|
|
1055
|
-
|
|
1070
|
+
exportImage(tpl, printData, {
|
|
1056
1071
|
paperWidth: 210,
|
|
1057
1072
|
paperHeight: 297,
|
|
1058
1073
|
limit: 6,
|
|
@@ -1125,14 +1140,9 @@ disconnect()
|
|
|
1125
1140
|
- 适用:报告类、A4/A5 正常分页模板。
|
|
1126
1141
|
|
|
1127
1142
|
```js
|
|
1128
|
-
// 不传 paperWidth/paperHeight,使用模板的面板尺寸与分页配置
|
|
1129
1143
|
exportPdf(tpl, printData, '打印预览pdf', {
|
|
1130
1144
|
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
1131
1145
|
})
|
|
1132
|
-
|
|
1133
|
-
exportPdf2(tpl, printData, '打印预览pdf', {
|
|
1134
|
-
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
1135
|
-
})
|
|
1136
1146
|
```
|
|
1137
1147
|
|
|
1138
1148
|
#### 模式 B:排版导出(把小模板拼到大纸张,例如 A4)
|
|
@@ -1155,20 +1165,6 @@ exportPdf(tpl, printData, '打印预览pdf', {
|
|
|
1155
1165
|
imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
|
|
1156
1166
|
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
1157
1167
|
})
|
|
1158
|
-
|
|
1159
|
-
exportPdf2(tpl, printData, '打印预览pdf', {
|
|
1160
|
-
paperWidth: 210, // mm
|
|
1161
|
-
paperHeight: 297, // mm
|
|
1162
|
-
perPage: 6, // 每页放 6 个(不够的到下一页)
|
|
1163
|
-
leftOffset: -1, // -1 表示水平居中;>=0 表示左边距 mm
|
|
1164
|
-
topOffset: -1, // -1 表示垂直居中;>=0 表示上边距 mm
|
|
1165
|
-
scale: 1, // 清晰度/性能权衡(也可用 pixelRatio)
|
|
1166
|
-
pdfCompress: true, // 是否压缩PDF 默认 true
|
|
1167
|
-
imageType: 'JPEG', // 图片类型 默认 JPEG 支持 JPEG、PNG
|
|
1168
|
-
imageQuality: 0.92, // 图片质量 0-1 默认 0.92
|
|
1169
|
-
imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
|
|
1170
|
-
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
1171
|
-
})
|
|
1172
1168
|
```
|
|
1173
1169
|
|
|
1174
1170
|
#### 排版规则(重点:perPage=0/不传的行为)
|