vg-print 1.0.2 → 1.0.5

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
@@ -272,4 +272,135 @@ const opened = hiprint.hiwebSocket.opened
272
272
  - 预览组件:`src/vue3/Preview.vue:1-63`
273
273
  - 设计器组件:`src/vue3/Designer.vue:1-42`
274
274
  - 头部组件:`src/vue3/Header.vue:1-38`
275
- - 拖拽组件:`src/vue3/DragBox.vue:1-28`
275
+ - 拖拽组件:`src/vue3/DragBox.vue:1-28`
276
+
277
+ ## 方法使用案例集合
278
+
279
+ ### 注册与 Provider 插件
280
+
281
+ ```
282
+ import { register } from 'vg-print'
283
+ import pluginEleBwip from '@vg-print/plugin-ele-bwip-js'
284
+
285
+ register({
286
+ authKey: '',
287
+ plugins: [
288
+ pluginEleBwip({ /* 插件参数 */ })
289
+ ]
290
+ })
291
+ ```
292
+
293
+ ### 全局配置 setConfig
294
+
295
+ ```
296
+ import { setConfig } from 'vg-print'
297
+
298
+ setConfig({
299
+ showAdsorbLine: true,
300
+ showPosition: true,
301
+ showSizeBox: true
302
+ })
303
+ ```
304
+
305
+ ### 设计器渲染与获取模板
306
+
307
+ ```
308
+ import { createPrintTemplate } from 'vg-print'
309
+
310
+ const t = createPrintTemplate({ template: templateJson })
311
+ t.design('#SVPrint', { grid: true })
312
+ const html = t.getHtml(printData) // 参考 src/views/preview.vue:95-101
313
+ const json = t.getJson() // 参考 src/views/index.vue:882
314
+ ```
315
+
316
+ ### 设置与导出模板 JSON
317
+
318
+ ```
319
+ t.setJson(newJson)
320
+ const exported = t.getJson()
321
+ ```
322
+
323
+ ### 浏览器打印
324
+
325
+ ```
326
+ t.print(printData, { /* options */ })
327
+ ```
328
+
329
+ ### 直接打印(需客户端)
330
+
331
+ ```
332
+ t.print2(printData, {
333
+ title: '打印标题',
334
+ printer: 'HP LaserJet'
335
+ })
336
+ // 判断连接与读取打印机列表
337
+ hiprint.hiwebSocket.opened // 参考 src/views/preview.vue:59-66
338
+ const printers = hiprint.hiwebSocket.getPrinterList() // 参考 src/hiprint/hiprint.bundle.js:7779
339
+ ```
340
+
341
+ ### 导出 PDF(两类模式)
342
+
343
+ 1) 普通模板,导出预览全部页:
344
+
345
+ ```
346
+ t.toPdf(printData, '打印预览pdf')
347
+ ```
348
+
349
+ 2) 小模板 A4 排版(把小模板排到 A4)参考 `src/views/index.vue:704-744`:
350
+
351
+ ```
352
+ t.toPdf(printData, '打印预览pdf', {
353
+ paperWidth: 210,
354
+ paperHeight: 297,
355
+ onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur/total)*100))
356
+ })
357
+ ```
358
+
359
+ ### 导出图片(多页合成、清晰度、排版)
360
+
361
+ ```
362
+ // 多张图片,每张合成 6 页,自动下载 JPEG(参考 src/views/index.vue:704-744)
363
+ await t.toImage(printData, {
364
+ limit: 6,
365
+ isDownload: true,
366
+ name: 'A4排版',
367
+ type: 'image/jpeg',
368
+ pixelRatio: 2,
369
+ quality: 0.8,
370
+ paperWidth: 210,
371
+ paperHeight: 297,
372
+ toType: 'url'
373
+ })
374
+ ```
375
+
376
+ ### 客户端高级 API(选用)
377
+
378
+ ```
379
+ // 刷新打印机列表
380
+ hiprint.hiwebSocket.refreshPrinterList() // 参考 src/hiprint/hiprint.bundle.js:7782
381
+
382
+ // 获取客户端列表与信息
383
+ hiprint.hiwebSocket.getClients() // 参考 src/hiprint/hiprint.bundle.js:7789
384
+ hiprint.hiwebSocket.getClientInfo() // 参考 src/hiprint/hiprint.bundle.js:12551-12554
385
+
386
+ // IPP 打印与请求
387
+ hiprint.hiwebSocket.ippPrint({ /* options */ }) // 参考 src/hiprint/hiprint.bundle.js:7803
388
+ hiprint.hiwebSocket.ippRequest({ /* options */ }) // 参考 src/hiprint/hiprint.bundle.js:7810
389
+ ```
390
+
391
+ ### Vue 插件全局快捷:$print / $print2
392
+
393
+ ```
394
+ // main.js
395
+ import { createApp } from 'vue'
396
+ import App from './App.vue'
397
+ import { hiPrintPlugin } from 'vg-print'
398
+
399
+ const app = createApp(App)
400
+ app.use(hiPrintPlugin) // 全局挂载 this.$print / this.$print2 参考 src/index.js:34-75
401
+ app.mount('#app')
402
+
403
+ // 组件中使用
404
+ this.$print(undefined, templateJson, printData, options)
405
+ this.$print2(undefined, templateJson, printData, options)
406
+ ```