vg-print 1.1.405 → 1.1.407

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.md CHANGED
@@ -1023,16 +1023,15 @@ const preview = async () => {
1023
1023
 
1024
1024
  回调签名:
1025
1025
 
1026
- ```js
1026
+
1027
1027
  beforeGetHtml: ({ template, html }) => html
1028
- ```
1028
+
1029
1029
 
1030
1030
  - `template`:当前 `hiprint.PrintTemplate` 实例
1031
1031
  - `html`:生成的 HTML 字符串(可返回新字符串替换;返回 `undefined/null` 则保持不变)
1032
1032
 
1033
1033
  示例:
1034
1034
 
1035
- ```js
1036
1035
  const tpl = createTemplate(tmplJson)
1037
1036
 
1038
1037
  const html = await getHtml(tpl, printData, {
@@ -1054,13 +1053,12 @@ tpl.print2(printData, {
1054
1053
  title: '打印预览pdf',
1055
1054
  beforeGetHtml: ({ template, html }) => html
1056
1055
  })
1057
- ```
1056
+
1058
1057
 
1059
1058
  // 3) 浏览器打印(不需要客户端)
1060
1059
  printBrowser(tpl, printData)
1061
1060
 
1062
1061
  // 4) 导出 PDF
1063
- // 原生方法
1064
1062
  exportPdf(tpl, printData, '打印预览pdf', {
1065
1063
  paperWidth: 210, // 纸张宽度 默认 210mm
1066
1064
  paperHeight: 297, // 纸张高度 默认 297mm
@@ -1195,8 +1193,6 @@ exportPdf(tpl, printData, '打印预览pdf', {
1195
1193
  imageQuality: 0.92, // 图片质量 0-1 默认 0.92
1196
1194
  imageCompression: 'FAST', // 图片压缩算法 默认 FAST 支持 FAST、MEDIUM、SLOW
1197
1195
  onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1198
- })
1199
- onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
1200
1196
  })
1201
1197
  ```
1202
1198
 
@@ -1294,99 +1290,6 @@ await exportImage(tpl, printData, {
1294
1290
  - `maxCanvasPixels`:单页最大画布像素上限;导出卡顿/崩溃时可调小(例如 `2e7`)。
1295
1291
  - `debugPerf`:输出每页渲染耗时到控制台,便于定位慢点。
1296
1292
 
1297
- ### 导入说明(含描述)
1298
-
1299
- - 所有运行时 API 由库入口直接导出;无需另装 `vue-plugin-hiprint`
1300
- - 如需自定义元素提供器,在调用前执行 `hiprint.init({ providers: [...] })`;默认已初始化内置提供器
1301
-
1302
- ### 适用场景(含描述)
1303
-
1304
- - 后台页面、弹窗、任务流:仅需“模板 + 数据”的预览/打印/导出能力
1305
- - 脚本或批量任务:结合 `exportPdf`/`exportImage` 实现批量导出
1306
-
1307
- ## 注意事项
1308
-
1309
- - 建议在 `index.html` 注入 `print-lock.css`,保证打印样式稳定
1310
- - 直接打印需配套客户端(Electron 或服务端),跨域部署需启用 HTTPS
1311
- - 若使用自定义 `host/token`,确保客户端配置一致且网络可达
1312
- - SSR 兼容:插件安装仅在浏览器环境执行(`typeof window !== 'undefined'`),在 SSR 框架中引入不会因 `window` 未定义报错。
1313
-
1314
- ## 完整示例
1315
-
1316
- ```vue
1317
- <template>
1318
- <FullDesigner
1319
- :initial-template="tpl"
1320
- :initial-print-data="rows"
1321
- default-lang="cn"
1322
- :hi-host="host"
1323
- :hi-token="token"
1324
- :hi-auto-connect="true"
1325
- @save="onSave"
1326
- />
1327
-
1328
- <div style="margin-top: 12px;">
1329
- <el-input v-model="host" placeholder="客户端地址,如 http://127.0.0.1:17521" style="width: 360px; margin-right: 8px;" />
1330
- <el-input v-model="token" placeholder="鉴权令牌" style="width: 200px; margin-right: 8px;" />
1331
- <el-button type="primary" @click="applyHostToken">应用连接参数</el-button>
1332
- <el-button style="margin-left:8px;" @click="preview">预览</el-button>
1333
- <el-button style="margin-left:8px;" @click="printBrowser">浏览器打印</el-button>
1334
- </div>
1335
- </template>
1336
-
1337
- <script setup>
1338
- import { ref } from 'vue'
1339
-
1340
- // 模板(示例)
1341
- const tpl = {
1342
- panels: [
1343
- {
1344
- index: 0,
1345
- paperType: 'A4',
1346
- width: 210,
1347
- height: 297,
1348
- printElements: [
1349
- {
1350
- options: { left: 20, top: 20, title: '标题', field: 'title', fontSize: 18 },
1351
- printElementType: { type: 'text' }
1352
- },
1353
- {
1354
- options: { left: 20, top: 50, title: '姓名', field: 'name' },
1355
- printElementType: { type: 'text' }
1356
- }
1357
- ]
1358
- }
1359
- ]
1360
- }
1361
-
1362
- // 数据(对象或数组均可)
1363
- const rows = [{ title: '病理图文报告', name: '东东' }]
1364
-
1365
- // 连接参数
1366
- const host = ref('http://127.0.0.1:17521')
1367
- const token = ref('')
1368
-
1369
- // 组件引用
1370
- const designer = ref(null)
1371
-
1372
- const applyHostToken = () => {
1373
- // 设置客户端地址与令牌,并尝试重连
1374
- designer.value?.setHiwebSocket(host.value, token.value)
1375
- }
1376
-
1377
- // 预览与浏览器打印
1378
- const preview = () => designer.value?.preView()
1379
- const printBrowser = () => designer.value?.printView()
1380
-
1381
- // 保存事件:拿到模板与数据入库
1382
- const onSave = ({ template, data, templateId }) => {
1383
- // 持久化示例
1384
- // await api.save({ template, data, templateId })
1385
- console.log('save payload:', { template, data, templateId })
1386
- }
1387
- </script>
1388
- ```
1389
-
1390
1293
  ## License
1391
1294
 
1392
1295
  LGPL