vg-print 1.0.414 → 1.0.415

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
@@ -1,36 +1,497 @@
1
- # vue-plugin-hiprint-demo
2
1
 
3
- #### Description
4
- vg-print代码
2
+ An out-of-the-box print designer component library (Vue 3). Currently focused on the single component `FullDesigner`, while exposing underlying `hiprint` capabilities and client direct connection (`hiwebSocket`) configuration, facilitating rapid integration of template design, preview, browser printing, PDF/image export, and direct printing functions.
5
3
 
6
- #### Software Architecture
7
- Software architecture description
4
+ You can install and experience the features directly. Features are constantly being improved, please update in time. Feedback and suggestions are welcome.
5
+ No domain restrictions, available offline. Provides one-on-one technical support.
6
+ Search `vg-print` on npm.
7
+ Contact me: QQ 984239686 or use the WeChat group on the homepage to solve problems.
8
8
 
9
- #### Installation
9
+ ## Silent Printing Client Tool Installer
10
10
 
11
- 1. xxxx
12
- 2. xxxx
13
- 3. xxxx
11
+ ![Silent Printing Client Tool](https://gitee.com/gao111/electron-vg-print/raw/master/electron-hiprint.png)
14
12
 
15
- #### Instructions
13
+ More info and download:
14
+ ```text
15
+ https://gitee.com/gao111/electron-vg-print
16
+ ```
17
+ Client tool download:
18
+ ```text
19
+ https://download.csdn.net/download/github_38400706/92538739
20
+ ```
16
21
 
17
- 1. xxxx
18
- 2. xxxx
19
- 3. xxxx
22
+ ## Features
20
23
 
21
- #### Contribution
24
+ - Full-featured page component `FullDesigner`, ready to use, no need to assemble sub-components
25
+ - Supports preview, browser printing, PDF/image export, direct printing (client required)
26
+ - Configure `hiwebSocket` `host`, `token` and auto-connection via props
27
+ - Exposes instance methods: preview, print, export, connection control, etc., for external calls
28
+ - Integrates and exports `hiprint` for advanced customization at the template object level
22
29
 
23
- 1. Fork the repository
24
- 2. Create Feat_xxx branch
25
- 3. Commit your code
26
- 4. Create Pull Request
30
+ ## Installation
27
31
 
32
+ ```bash
33
+ npm i vg-print
34
+ ```
28
35
 
29
- #### Gitee Feature
36
+ ## Header Component
30
37
 
31
- 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32
- 2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33
- 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34
- 4. The most valuable open source project [GVP](https://gitee.com/gvp)
35
- 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36
- 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
38
+ - Used for the top area of the page, with built-in common operation buttons and printer settings; supports customization via `props` and `slots`.
39
+ - Embedded in `FullDesigner` by default; can also be used separately.
40
+
41
+ ### Props
42
+
43
+ - `logoHtml: string` Custom HTML fragment for the left Logo area
44
+ - `title: string` Left title text
45
+ - `printCount: number` Number of copies, default `1` (supports `v-model:printCount`)
46
+ - `printerName: string` Currently selected printer name (supports `v-model:printerName`)
47
+ - `printerList: Array<{ name: string; label: string }>` Printer list
48
+ - `waitShowPrinter: boolean` Show loading state for "Browser Print" button
49
+ - `languages: Array<{ label: string; value: string }>` Language switch dropdown options
50
+
51
+ ### Events (Emits)
52
+
53
+ - `preview` Open preview
54
+ - `print-view` Browser print
55
+ - `to-pdf` Export PDF
56
+ - `to-image` Export Image
57
+ - `print` Direct print (client required)
58
+ - `clear-paper` Clear (with secondary confirmation)
59
+ - `save` Save (primary key of split button)
60
+ - `edit-template` Open "Edit Template Data" dialog
61
+ - `edit-data` Open "Edit Print Data" dialog
62
+ - `lang-change` Language switch (value is language code: `cn`, `en`, `de`, `es`, `fr`, `it`, `ja`, `ru`, `cn_tw`)
63
+ - `feedback` Feedback/Help
64
+
65
+ ### Slots
66
+
67
+ - `headerLeft` Left area (default: logo + title)
68
+ - `headerCenter` Middle custom area (default empty)
69
+ - `headerRight` Right operation area (default: printer and a group of buttons)
70
+
71
+ ### Important Note on Styles
72
+
73
+ If you find page styles missing during external calls, please import the print style.
74
+ Copy `node_modules/@vg-print/hiprint/dist/css/print-lock.css` to your development resource directory (e.g., `public` directory in Vue).
75
+ If your site is `https://www.abcd.com/index.html`, ensure `https://www.abcd.com/print-lock.css` is accessible.
76
+ Add `print-lock.css` to your project's `index.html` with `media="print"`.
77
+
78
+ ```html
79
+ <link rel="stylesheet" type="text/css" media="print" href="/print-lock.css" />
80
+ ```
81
+
82
+ ### Usage Example: With FullDesigner
83
+
84
+ ```vue
85
+ <template>
86
+ <FullDesigner
87
+ ref="designer"
88
+ :initial-template="tpl"
89
+ :initial-print-data="rows"
90
+ default-lang="cn"
91
+ :hi-host="host"
92
+ :hi-token="token"
93
+ :hi-auto-connect="true"
94
+ @save="onSave"
95
+ >
96
+ <!-- Top area (Header built-in; can be customized via slot) -->
97
+ <template #headerLeft>
98
+ <div style="display:flex;align-items:center;color:#fff;">
99
+ <img src="/logo.svg" style="height:24px;margin-right:8px;" />
100
+ <span>Custom Title</span>
101
+ </div>
102
+ </template>
103
+ <template #headerCenter>
104
+ <el-tag type="success">Middle Custom Area</el-tag>
105
+ </template>
106
+ <!-- No need to provide headerRight if keeping default buttons; provide if replacing completely -->
107
+ <template #headerRight>
108
+ <el-button size="small" @click="designer.value.preView()">Preview</el-button>
109
+ <el-button size="small" @click="designer.value.printView()">Browser Print</el-button>
110
+ <el-button type="primary" size="small" @click="designer.value.toPdf()">Export PDF</el-button>
111
+ <el-button size="small" @click="designer.value.toImage()">Export Image</el-button>
112
+ <el-button size="small" @click="designer.value.print()">Direct Print</el-button>
113
+ <el-button type="warning" size="small" @click="onClear()">Clear</el-button>
114
+ <el-button type="success" size="small" @click="onSaveDirect()">Save</el-button>
115
+ </template>
116
+ </FullDesigner>
117
+ </template>
118
+
119
+ <script setup>
120
+ import { ref } from 'vue'
121
+ const designer = ref(null)
122
+ const host = ref('http://127.0.0.1:17521')
123
+ const token = ref('')
124
+ const tpl = { panels: [ /* ... */ ] }
125
+ const rows = [{ title: 'Pathology Report', name: 'DongDong' }]
126
+ const onSave = ({ template, data }) => { /* Save to backend */ }
127
+ const onClear = () => { /* Clear data/elements */ }
128
+ const onSaveDirect = () => designer.value?.save()
129
+ </script>
130
+ ```
131
+
132
+ ### Usage Example: Header Alone
133
+
134
+ ```vue
135
+ <template>
136
+ <Header
137
+ v-model:printCount="count"
138
+ v-model:printerName="printer"
139
+ :printerList="printers"
140
+ :waitShowPrinter="loading"
141
+ :languages="langs"
142
+ title="Print Designer"
143
+ @preview="onPreview"
144
+ @print-view="onPrintView"
145
+ @to-pdf="onToPdf"
146
+ @to-image="onToImage"
147
+ @print="onPrint"
148
+ @clear-paper="onClear"
149
+ @save="onSave"
150
+ @lang-change="onLangChange"
151
+ @feedback="onFeedback"
152
+ />
153
+ </template>
154
+ ```
155
+
156
+ ### Responsive Strategy (Built-in)
157
+
158
+ - Automatically hides the middle area and secondary buttons when the window shrinks, keeping key operations like "Save" and "Feedback"; left logo/title are unaffected.
159
+ - Breakpoints:
160
+ - `≤1600px` Hide middle area
161
+ - `≤1400px` Hide copies, printer selection, preview, browser print, export PDF, export image
162
+ - `≤1200px` Hide direct print, language switch
163
+ - `≤992px` Hide clear
164
+ - `≤768px` Hide title text (keep Logo)
165
+
166
+ > Tip: If you need fully custom buttons, provide the `headerRight` slot.
167
+
168
+ ---
169
+
170
+ ## Preview Component
171
+
172
+ - Independent preview modal component, supports rendering template HTML, selecting printer, exporting PDF/image, direct printing, etc.
173
+ - Can be used separately or with `FullDesigner`.
174
+
175
+ ### Props
176
+
177
+ - `printTemplate: object` Template object (`hiprint.PrintTemplate` or return value of `createTemplate`)
178
+ - `printData: object | array` Print data
179
+ - `printerList: Array<{ name: string; label: string }>` Printer list
180
+ - `selectedPrinter: string` Selected printer name
181
+ - `showPdf: boolean` Show "Export PDF" button, default `true`
182
+ - `showImg: boolean` Show "Export Image" button, default `true`
183
+ - `showPrint2: boolean` Show "Direct Print" button, default `true`
184
+ - `modalShow: boolean` Modal visibility (supports `v-model:modalShow`)
185
+ - `width: string | number` Modal width (default `'80%'`)
186
+ - `defaultLang: string` Component i18n language (used when Standalone); supports `cn`, `en`, `de`, `es`, `fr`, `it`, `ja`, `ru`, `cn_tw`; default `cn`
187
+
188
+ ### Events (Emits)
189
+
190
+ - `update:modalShow` Two-way binding for modal visibility
191
+ - `update:selectedPrinter` Selected printer change
192
+ - `close` Close modal
193
+
194
+ ### Exposed Methods (defineExpose)
195
+
196
+ - `show(template, data, width?)` Show and render preview content; can pass template/data and width
197
+ - `hideModal()` Close modal
198
+ - `init()` Initialize (internal use)
199
+ - `getTarget()` Get preview container DOM
200
+
201
+ ### Usage Example (Standalone)
202
+
203
+ ```vue
204
+ <template>
205
+ <el-button @click="openPreview">Show Preview</el-button>
206
+ <Preview
207
+ ref="previewRef"
208
+ v-model:modalShow="visible"
209
+ default-lang="cn"
210
+ :printerList="printers"
211
+ :selectedPrinter="printer"
212
+ @update:selectedPrinter="printer = $event"
213
+ />
214
+ </template>
215
+
216
+ <script setup>
217
+ import { ref } from 'vue'
218
+ import { Preview, createTemplate } from 'vg-print'
219
+ import 'vg-print/style.css'
220
+
221
+ const previewRef = ref(null)
222
+ const visible = ref(false)
223
+ const printers = ref([{ name: 'HP_001', label: 'HP Printer' }])
224
+ const printer = ref('')
225
+
226
+ const tmplJson = { panels: [ /* ... */ ] }
227
+ const data = { title: 'Report', name: 'DongDong' }
228
+
229
+ const openPreview = () => {
230
+ const tpl = createTemplate(tmplJson) // Or pass hiprint.PrintTemplate
231
+ previewRef.value.show(tpl, data, '80%')
232
+ }
233
+ </script>
234
+ ```
235
+
236
+ ### Usage Example (With FullDesigner)
237
+
238
+ ```vue
239
+ <template>
240
+ <FullDesigner ref="designer" default-lang="cn" />
241
+ <Preview ref="previewRef" v-model:modalShow="visible" />
242
+ <el-button @click="designer.value.preView()">Use FullDesigner's Preview</el-button>
243
+ <el-button @click="showCustomPreview">Use Preview Component</el-button>
244
+ </template>
245
+
246
+ <script setup>
247
+ import { ref } from 'vue'
248
+ const designer = ref(null)
249
+ const previewRef = ref(null)
250
+ const visible = ref(false)
251
+
252
+ const showCustomPreview = () => {
253
+ const tpl = designer.value.getTemplate() // Assuming method exposed
254
+ const data = designer.value.getPrintData() // Assuming method exposed
255
+ previewRef.value.show(tpl, data, '80%')
256
+ }
257
+ </script>
258
+ ```
259
+
260
+ ### Note
261
+
262
+ - Please import `vg-print/style.css` when using the component library.
263
+ - `Preview` automatically renders content based on `printTemplate` and `printData`.
264
+ - If using `Preview` separately without plugin installation, set `default-lang`.
265
+
266
+ Style Import:
267
+
268
+ ```javascript
269
+ // Global style
270
+ import 'vg-print/style.css'
271
+
272
+ // Print lock style (Recommended)
273
+ // In `index.html`:
274
+ // <link rel="stylesheet" type="text/css" media="print" href="/css/print-lock.css" />
275
+ ```
276
+
277
+ Environment: Vue 3, Node >= 18.18.
278
+
279
+ ## Quick Start
280
+
281
+ ```javascript
282
+ // main.ts
283
+ import { createApp } from 'vue'
284
+ import App from './App.vue'
285
+ import vgPrint from 'vg-print'
286
+ import 'vg-print/style.css'
287
+
288
+ createApp(App).use(vgPrint).mount('#app')
289
+ ```
290
+
291
+ ```vue
292
+ <template>
293
+ <FullDesigner
294
+ ref="designer"
295
+ :hi-host="'http://127.0.0.1:17521'"
296
+ :hi-token="'your-token'"
297
+ :hi-auto-connect="true"
298
+ />
299
+ <!-- Buttons... -->
300
+ </template>
301
+ <script setup>
302
+ // ... Same as above
303
+ </script>
304
+ ```
305
+
306
+ ## API (FullDesigner)
307
+
308
+ ### Props
309
+
310
+ - `hi-host: string` Client service address
311
+ - `hi-token: string` Client auth token
312
+ - `hi-auto-connect: boolean` Auto connect to client
313
+ - `initial-template: object` Initial template JSON
314
+ - `initial-print-data: object | array` Initial print data
315
+ - `default-lang: string` Default language
316
+
317
+ ### Methods
318
+
319
+ - `preView()` Open preview
320
+ - `printView()` Browser print
321
+ - `print()` Direct print
322
+ - `toPdf()` Export PDF
323
+ - `toPdf2()` Export PDF with paper layout
324
+ - `toImage()` Export Image
325
+ - `toImage2()` Export Image with paper layout
326
+ - `toImage()` Export Image
327
+ - `setHiwebSocket(host, token, cb)` Set client address/token (Respects autoConnect state)
328
+ - `setHost(host, token, cb)` Set client address/token and connect immediately (Standard API)
329
+ - `connect(cb)` Connect to client
330
+ - `disconnect()` Disconnect
331
+ - `disAutoConnect()` Disable auto-connect
332
+
333
+ ### Events
334
+
335
+ - `save` Save template and data
336
+
337
+ ## Advanced Usage (hiprint)
338
+
339
+ ```javascript
340
+ import { hiprint, defaultElementTypeProvider } from 'vg-print'
341
+ // Global Config
342
+ hiprint.setConfig({ showAdsorbLine: true, showPosition: true, showSizeBox: true })
343
+ // Register Plugins
344
+ hiprint.register({ authKey: '', plugins: [] })
345
+ // Init
346
+ hiprint.init({
347
+ host: 'http://localhost:17521',
348
+ token: '',
349
+ lang: 'en'
350
+ })
351
+ // Create Template
352
+ const tpl = new hiprint.PrintTemplate({ template: {} })
353
+ // Design
354
+ tpl.design('#hiprint-printTemplate', { grid: true })
355
+ // Print
356
+ tpl.print({ name: 'Example' })
357
+ ```
358
+
359
+ ### Auth Key and Default Watermark
360
+
361
+ - **Design State**: No default watermark.
362
+ - **Runtime State**:
363
+ - No Auth: Default watermark or "Trial Version" suffix.
364
+ - With Auth: No default watermark.
365
+
366
+ Register:
367
+ ```javascript
368
+ hiprint.register({ authKey: 'YOUR_KEY' });
369
+ ```
370
+
371
+ ## Lightweight Runtime API
372
+
373
+ Use when you only need "Template + Data" capabilities without the designer UI.
374
+
375
+ ```javascript
376
+ import { createTemplate, printBrowser, exportPdf, exportImage } from 'vg-print'
377
+
378
+ const tpl = createTemplate(tmplJson)
379
+ printBrowser(tpl, printData)
380
+ exportPdf(tpl, printData, 'filename')
381
+ ```
382
+
383
+ ### Export PDF / Image
384
+
385
+ `exportPdf` / `exportImage` are lightweight wrappers around the template instance methods:
386
+
387
+ - `exportPdf(tpl, data, filename, options)` → `tpl.toPdf(data, filename, options)`
388
+ - `exportPdf2(tpl, data, filename, options)` → `tpl.toPdf2(data, filename, options)`
389
+
390
+ - `exportImage(tpl, data, options)` → `tpl.toImage(data, options)`
391
+ - `exportImage2(tpl, data, options)` → `tpl.toImage2(data, options)`
392
+
393
+ #### Export PDF
394
+
395
+ **Mode A: Normal export (follow template paging)**
396
+
397
+ ```js
398
+ // No paperWidth/paperHeight: export pages exactly like preview pagination
399
+ exportPdf(tpl, printData, 'report', {
400
+ onProgress: (cur, total) => console.log('toPdf', Math.floor((cur / total) * 100))
401
+ })
402
+ ```
403
+
404
+ **Mode B: Layout export (tile small labels into a big paper, e.g. A4)**
405
+
406
+ ```js
407
+ exportPdf(tpl, printData, 'labels', {
408
+ paperWidth: 210, // mm
409
+ paperHeight: 297, // mm
410
+ perPage: 6, // put 6 labels per sheet (rest goes to next sheet)
411
+ leftOffset: -1, // -1: center; >=0: left margin (mm)
412
+ topOffset: -1, // -1: center; >=0: top margin (mm)
413
+ scale: 2, // clarity vs performance (pixelRatio also supported)
414
+ onProgress: (cur, total) => console.log('toPdf', Math.floor((cur / total) * 100))
415
+ })
416
+ ```
417
+
418
+ **Layout rules**
419
+
420
+ - With `paperWidth/paperHeight` (or `usePaperType: true`):
421
+ - `perPage > 0`: fixed “N per sheet”
422
+ - `perPage = 0` or omitted: auto-fill “as many as can fit per sheet”
423
+ - Without paper size:
424
+ - Export follows template pagination; `perPage` does not apply in this mode.
425
+
426
+ #### Export Image
427
+
428
+ **Mode A: Normal export (follow template paging)**
429
+
430
+ ```js
431
+ // Recommended: one image per page (avoid very long images)
432
+ await exportImage(tpl, printData, {
433
+ isDownload: true,
434
+ name: 'page',
435
+ splitPages: true,
436
+ type: 'image/png', // QR/barcode recommended
437
+ pixelRatio: 2,
438
+ toType: 'blob'
439
+ })
440
+ ```
441
+
442
+ **Optional: merge into long images**
443
+
444
+ ```js
445
+ // limit: N pages per output image; limit<=0 merges all pages into one (can be huge)
446
+ await exportImage(tpl, printData, {
447
+ isDownload: true,
448
+ name: 'merged',
449
+ limit: 6,
450
+ type: 'image/jpeg',
451
+ pixelRatio: 2,
452
+ quality: 0.85
453
+ })
454
+ ```
455
+
456
+ **Mode B: Layout export (tile small labels into a big paper, e.g. A4)**
457
+
458
+ ```js
459
+ // In layout mode, `limit` works like “labels per sheet”
460
+ await exportImage(tpl, printData, {
461
+ paperWidth: 210,
462
+ paperHeight: 297,
463
+ limit: 6,
464
+ isDownload: true,
465
+ name: 'A4-layout',
466
+ splitPages: true,
467
+ type: 'image/png',
468
+ pixelRatio: 2
469
+ })
470
+ ```
471
+
472
+ **Layout rules**
473
+
474
+ - With `paperWidth/paperHeight`:
475
+ - `limit > 0`: fixed “N per sheet”
476
+ - `limit = 0` or omitted: auto-fill “as many as can fit per sheet”
477
+ - Without paper size:
478
+ - `splitPages: true`: one image per page (recommended)
479
+ - `splitPages: false` + `limit > 0`: merge N pages per long image
480
+ - `splitPages: false` + `limit <= 0`: merge all pages into one long image (not recommended)
481
+
482
+ #### Common options
483
+
484
+ - `pixelRatio` / `scale`: render scale (higher = clearer but slower)
485
+ - `forcePng` (PDF): force PNG for QR/barcode
486
+ - `maxCanvasPixels`: cap per-page canvas pixels to reduce freezes
487
+ - `debugPerf`: log per-page render time to console
488
+
489
+ ### Notes
490
+
491
+ - Inject `print-lock.css` in `index.html`.
492
+ - Direct printing needs a client.
493
+ - SSR compatible.
494
+
495
+ ## Full Example
496
+
497
+ (See the code block in the Chinese section or above)