vg-print 1.1.303 → 1.1.305

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 CHANGED
@@ -32,6 +32,20 @@ https://download.csdn.net/download/github_38400706/92538739
32
32
  ```bash
33
33
  npm i vg-print
34
34
  ```
35
+ If you need client direct printing (`hiwebSocket`), install the optional dependency in your host app:
36
+
37
+ ```bash
38
+ npm i socket.io-client
39
+ ```
40
+
41
+ In your main entry file (e.g., `main.ts`):
42
+
43
+ ```js
44
+ import { io } from 'socket.io-client'
45
+ import { setSocketIo } from 'vg-print'
46
+
47
+ setSocketIo(io)
48
+ ```
35
49
 
36
50
  ## Header Component
37
51
 
@@ -365,11 +379,8 @@ createApp(App).use(vgPrint).mount('#app')
365
379
  - `preView()` Open preview
366
380
  - `printView()` Browser print
367
381
  - `print()` Direct print
368
- - `toPdf()` Export PDF
369
- - `toPdf2()` Export PDF with paper layout
370
- - `toImage()` Export Image
371
- - `toImage2()` Export Image with paper layout
372
- - `toImage()` Export Image
382
+ - `toPdf()` Export PDF with the `@zumer/snapdom` pipeline, including paper layout options
383
+ - `toImage()` Export image with the `@zumer/snapdom` pipeline, including paper layout options
373
384
  - `setHiwebSocket(host, token, cb)` Set client address/token (Respects autoConnect state)
374
385
  - `setHost(host, token, cb)` Set client address/token and connect immediately (Standard API)
375
386
  - `connect(cb)` Connect to client
@@ -431,10 +442,8 @@ exportPdf(tpl, printData, 'filename')
431
442
  `exportPdf` / `exportImage` are lightweight wrappers around the template instance methods:
432
443
 
433
444
  - `exportPdf(tpl, data, filename, options)` → `tpl.toPdf(data, filename, options)`
434
- - `exportPdf2(tpl, data, filename, options)` → `tpl.toPdf2(data, filename, options)`
435
445
 
436
446
  - `exportImage(tpl, data, options)` → `tpl.toImage(data, options)`
437
- - `exportImage2(tpl, data, options)` → `tpl.toImage2(data, options)`
438
447
 
439
448
  #### Export PDF
440
449
 
package/README.md CHANGED
@@ -106,6 +106,26 @@ hiprint.register({
106
106
  npm i vg-print
107
107
  ```
108
108
 
109
+ ### 可选依赖:直连打印/客户端连接(socket.io-client)
110
+
111
+ - 本库默认不内置 `socket.io-client`,以减少默认安装体积。
112
+ - 仅当你需要“直连打印/客户端连接(hiwebSocket)”能力(如 `print()` / `print2()` / 自动连接)时,才需要安装并注入:
113
+
114
+ ```bash
115
+ npm i socket.io-client
116
+ ```
117
+
118
+ 在项目入口(如 `main.ts`)注入:
119
+
120
+ ```js
121
+ import { io } from 'socket.io-client'
122
+ import { setSocketIo } from 'vg-print'
123
+
124
+ setSocketIo(io)
125
+ ```
126
+
127
+ 也可直接使用 `window.io = io`(等价)。
128
+
109
129
  ## Header 顶部工具栏组件
110
130
 
111
131
  - 用于页面一级头部区域,内置常用操作按钮与打印机设置;支持通过 `props` 与 `slots` 定制。
@@ -635,10 +655,8 @@ const disableAutoConnect = () => designer.value.disAutoConnect()
635
655
  - `preView()` 打开预览弹窗;将当前模板与数据渲染为预览 HTML
636
656
  - `printView()` 浏览器打印;不依赖客户端,调起系统打印对话框
637
657
  - `print()` 直接打印;需客户端已连接,按当前选定打印机输出
638
- - `toPdf()` 导出 PDF;使用内置 A4 排版示例参数导出
639
- - `toPdf2()` 导出 PDF;支持自定义参数,如缩放比例、页边距等(通过@zumer/snapdom库插件)
640
- - `toImage()` 导出图片;使用内置 A4 排版示例参数导出
641
- - `toImage2()` 导出图片;支持自定义参数,如缩放比例、页边距等(通过@zumer/snapdom库插件)
658
+ - `toPdf()` 导出 PDF;使用基于 `@zumer/snapdom` 的导出链路,支持缩放比例、页边距、纸张排版等参数
659
+ - `toImage()` 导出图片;使用基于 `@zumer/snapdom` 的导出链路,支持缩放比例、页边距、纸张排版等参数
642
660
  - `setHiwebSocket(host: string, token?: string, cb?: Function)` 设置客户端地址与令牌并尝试重连;`cb(status, msg)` 为连接回调
643
661
  - `connect(cb?: Function)` 主动连接客户端;`cb(status, msg)` 为连接回调
644
662
  - `disconnect()` 断开客户端连接
@@ -767,6 +785,8 @@ return (result.data || []).map(item => ({
767
785
 
768
786
  本库导出 `hiprint`,可直接创建与操作模板对象(`hiprint.PrintTemplate`):
769
787
 
788
+ 若需要使用“直连打印/客户端连接(hiwebSocket)”相关能力,请先按上文注入 `io`;否则会提示缺失并导致连接失败。
789
+
770
790
  ```js
771
791
  import { hiprint, defaultElementTypeProvider } from 'vg-print'
772
792
  // 全局配置
@@ -834,8 +854,8 @@ tpl.toPdf(this.printDataVar, '打印预览pdf', {
834
854
  }
835
855
  }
836
856
  });
837
- // 这是使用@zumer/snapdom库插件导出PDF的示例,使用方式和toPdf一样
838
- tpl.toPdf2(this.printDataVar, '打印预览pdf', {
857
+ // 使用当前保留的 toPdf 导出链路(基于 @zumer/snapdom
858
+ tpl.toPdf(this.printDataVar, '打印预览pdf', {
839
859
  onProgress: (cur, total) => {
840
860
  // 导出进度100%的时候关闭等待
841
861
  if (cur === total) {
@@ -880,8 +900,8 @@ tpl.toImage(this.printDataVar, {
880
900
  }
881
901
  })
882
902
 
883
- // 这是使用@zumer/snapdom库插件导出图片的示例,使用方式和oImage一样
884
- tpl.toImage2(this.printDataVar, {
903
+ // 使用当前保留的 toImage 导出链路(基于 @zumer/snapdom
904
+ tpl.toImage(this.printDataVar, {
885
905
  paperWidth: 210,
886
906
  paperHeight: 297,
887
907
  limit: 6,
@@ -911,9 +931,7 @@ import {
911
931
  getHtml,
912
932
  printBrowser,
913
933
  exportPdf,
914
- exportPdf2,
915
934
  exportImage,
916
- exportImage2,
917
935
  getPrinterList,
918
936
  refreshPrinterList,
919
937
  getAddress,
@@ -975,23 +993,6 @@ exportPdf(tpl, printData, '打印预览pdf', {
975
993
  }
976
994
  })
977
995
 
978
- // 插件方法
979
- exportPdf2(tpl, printData, '打印预览pdf', {
980
- paperWidth: 210,
981
- paperHeight: 297,
982
- perPage: 6,
983
- leftOffset:-1,
984
- topOffset:-1,
985
- scale: 1, // 清晰度/性能权衡(也可用 pixelRatio) 1:100% 2:200% 3:300%
986
- pdfCompress: true, // 是否压缩PDF 默认 true
987
- imageType: 'JPEG', // 图片类型 默认 JPEG 支持 JPEG、PNG
988
- imageQuality: 0.92, // 图片质量 0-1 默认 0.92
989
- imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
990
- onProgress: (cur: number, total: number) => {
991
- console.log('toPdf 进度', Math.floor((cur/total)*100))
992
- }
993
- })
994
-
995
996
  // 原生方法
996
997
  await exportImage(tpl, printData, {
997
998
  isDownload: true,
@@ -1007,20 +1008,6 @@ await exportImage(tpl, printData, {
1007
1008
  }
1008
1009
  })
1009
1010
 
1010
- // 插件方法
1011
- exportImage2(tpl, printData, {
1012
- paperWidth: 210,
1013
- paperHeight: 297,
1014
- limit: 6,
1015
- isDownload: true,
1016
- name: 'A4排版',
1017
- type: 'image/jpeg',
1018
- pixelRatio: 2,
1019
- onProgress: (cur: number, total: number) => {
1020
- console.log('toImage 进度', Math.floor((cur/total)*100))
1021
- }
1022
- })
1023
-
1024
1011
  // 6) 客户端直连打印(需要本地客户端)
1025
1012
  setHiwebSocket('http://127.0.0.1:17521', 'your-token') // 遵循 autoConnect 状态
1026
1013
  // 或者使用标准 API(设置即连接)
@@ -1093,10 +1080,6 @@ disconnect()
1093
1080
  exportPdf(tpl, printData, '打印预览pdf', {
1094
1081
  onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1095
1082
  })
1096
-
1097
- exportPdf2(tpl, printData, '打印预览pdf', {
1098
- onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1099
- })
1100
1083
  ```
1101
1084
 
1102
1085
  #### 模式 B:排版导出(把小模板拼到大纸张,例如 A4)
@@ -1119,18 +1102,6 @@ exportPdf(tpl, printData, '打印预览pdf', {
1119
1102
  imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
1120
1103
  onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1121
1104
  })
1122
-
1123
- exportPdf2(tpl, printData, '打印预览pdf', {
1124
- paperWidth: 210, // mm
1125
- paperHeight: 297, // mm
1126
- perPage: 6, // 每页放 6 个(不够的到下一页)
1127
- leftOffset: -1, // -1 表示水平居中;>=0 表示左边距 mm
1128
- topOffset: -1, // -1 表示垂直居中;>=0 表示上边距 mm
1129
- scale: 1, // 清晰度/性能权衡(也可用 pixelRatio)
1130
- pdfCompress: true, // 是否压缩PDF 默认 true
1131
- imageType: 'JPEG', // 图片类型 默认 JPEG 支持 JPEG、PNG
1132
- imageQuality: 0.92, // 图片质量 0-1 默认 0.92
1133
- imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
1134
1105
  onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1135
1106
  })
1136
1107
  ```
@@ -1321,4 +1292,3 @@ const onSave = ({ template, data, templateId }) => {
1321
1292
  }
1322
1293
  </script>
1323
1294
  ```
1324
-