vg-print 1.0.384 → 1.0.386

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
@@ -1,7 +1,410 @@
1
1
  # vg-print
2
2
 
3
+ [中文](#chinese) | [English](#english)
4
+
5
+ <span id="english"></span>
6
+
7
+ 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.
8
+
9
+ You can install and experience the features directly. Features are constantly being improved, please update in time. Feedback and suggestions are welcome.
10
+ No domain restrictions, available offline. Provides one-on-one technical support.
11
+ Search `vg-print` on npm.
12
+ Contact me: QQ 984239686 or use the WeChat group on the homepage to solve problems.
13
+
14
+ # Silent Printing Client Tool Installer
15
+
16
+ ![Silent Printing Client Tool](https://gitee.com/gao111/electron-vg-print/raw/master/electron-hiprint.png)
17
+
18
+ More info and download:
19
+ ```
20
+ https://gitee.com/gao111/electron-vg-print
21
+ ```
22
+ Client tool download:
23
+ ```
24
+ https://download.csdn.net/download/github_38400706/92538739
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - Full-featured page component `FullDesigner`, ready to use, no need to assemble sub-components
30
+ - Supports preview, browser printing, PDF/image export, direct printing (client required)
31
+ - Configure `hiwebSocket` `host`, `token` and auto-connection via props
32
+ - Exposes instance methods: preview, print, export, connection control, etc., for external calls
33
+ - Integrates and exports `hiprint` for advanced customization at the template object level
34
+ - Built-in `@sv-print/plugin-api-pdf3` and `@sv-print/plugin-api-image` plugins for more powerful export functions
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ npm i vg-print
40
+ ```
41
+
42
+ ## Header Component
43
+
44
+ - Used for the top area of the page, with built-in common operation buttons and printer settings; supports customization via `props` and `slots`.
45
+ - Embedded in `FullDesigner` by default; can also be used separately.
46
+
47
+ ### Props
48
+
49
+ - `logoHtml: string` Custom HTML fragment for the left Logo area
50
+ - `title: string` Left title text
51
+ - `printCount: number` Number of copies, default `1` (supports `v-model:printCount`)
52
+ - `printerName: string` Currently selected printer name (supports `v-model:printerName`)
53
+ - `printerList: Array<{ name: string; label: string }>` Printer list
54
+ - `waitShowPrinter: boolean` Show loading state for "Browser Print" button
55
+ - `languages: Array<{ label: string; value: string }>` Language switch dropdown options
56
+
57
+ ### Events (Emits)
58
+
59
+ - `preview` Open preview
60
+ - `print-view` Browser print
61
+ - `to-pdf` Export PDF
62
+ - `to-image` Export Image
63
+ - `print` Direct print (client required)
64
+ - `clear-paper` Clear (with secondary confirmation)
65
+ - `save` Save (primary key of split button)
66
+ - `edit-template` Open "Edit Template Data" dialog
67
+ - `edit-data` Open "Edit Print Data" dialog
68
+ - `lang-change` Language switch (value is language code: `cn`, `en`, `de`, `es`, `fr`, `it`, `ja`, `ru`, `cn_tw`)
69
+ - `feedback` Feedback/Help
70
+
71
+ ### Slots
72
+
73
+ - `headerLeft` Left area (default: logo + title)
74
+ - `headerCenter` Middle custom area (default empty)
75
+ - `headerRight` Right operation area (default: printer and a group of buttons)
76
+
77
+ ### Important Note on Styles
78
+
79
+ If you find page styles missing during external calls, please import the print style.
80
+ Copy `node_modules/@vg-print/hiprint/dist/css/print-lock.css` to your development resource directory (e.g., `public` directory in Vue).
81
+ If your site is `https://www.abcd.com/index.html`, ensure `https://www.abcd.com/print-lock.css` is accessible.
82
+ Add `print-lock.css` to your project's `index.html` with `media="print"`.
83
+
84
+ ```html
85
+ <link rel="stylesheet" type="text/css" media="print" href="/print-lock.css" />
86
+ ```
87
+
88
+ ### Usage Example: With FullDesigner
89
+
90
+ ```vue
91
+ <template>
92
+ <FullDesigner
93
+ ref="designer"
94
+ :initial-template="tpl"
95
+ :initial-print-data="rows"
96
+ default-lang="cn"
97
+ :hi-host="host"
98
+ :hi-token="token"
99
+ :hi-auto-connect="true"
100
+ @save="onSave"
101
+ >
102
+ <!-- Top area (Header built-in; can be customized via slot) -->
103
+ <template #headerLeft>
104
+ <div style="display:flex;align-items:center;color:#fff;">
105
+ <img src="/logo.svg" style="height:24px;margin-right:8px;" />
106
+ <span>Custom Title</span>
107
+ </div>
108
+ </template>
109
+ <template #headerCenter>
110
+ <el-tag type="success">Middle Custom Area</el-tag>
111
+ </template>
112
+ <!-- No need to provide headerRight if keeping default buttons; provide if replacing completely -->
113
+ <template #headerRight>
114
+ <el-button size="small" @click="designer.value.preView()">Preview</el-button>
115
+ <el-button size="small" @click="designer.value.printView()">Browser Print</el-button>
116
+ <el-button type="primary" size="small" @click="designer.value.toPdf()">Export PDF</el-button>
117
+ <el-button size="small" @click="designer.value.toImage()">Export Image</el-button>
118
+ <el-button size="small" @click="designer.value.print()">Direct Print</el-button>
119
+ <el-button type="warning" size="small" @click="onClear()">Clear</el-button>
120
+ <el-button type="success" size="small" @click="onSaveDirect()">Save</el-button>
121
+ </template>
122
+ </FullDesigner>
123
+ </template>
124
+
125
+ <script setup>
126
+ import { ref } from 'vue'
127
+ const designer = ref(null)
128
+ const host = ref('http://127.0.0.1:17521')
129
+ const token = ref('')
130
+ const tpl = { panels: [ /* ... */ ] }
131
+ const rows = [{ title: 'Pathology Report', name: 'DongDong' }]
132
+ const onSave = ({ template, data }) => { /* Save to backend */ }
133
+ const onClear = () => { /* Clear data/elements */ }
134
+ const onSaveDirect = () => designer.value?.save()
135
+ </script>
136
+ ```
137
+
138
+ ### Usage Example: Header Alone
139
+
140
+ ```vue
141
+ <template>
142
+ <Header
143
+ v-model:printCount="count"
144
+ v-model:printerName="printer"
145
+ :printerList="printers"
146
+ :waitShowPrinter="loading"
147
+ :languages="langs"
148
+ title="Print Designer"
149
+ @preview="onPreview"
150
+ @print-view="onPrintView"
151
+ @to-pdf="onToPdf"
152
+ @to-image="onToImage"
153
+ @print="onPrint"
154
+ @clear-paper="onClear"
155
+ @save="onSave"
156
+ @lang-change="onLangChange"
157
+ @feedback="onFeedback"
158
+ />
159
+ </template>
160
+ ```
161
+
162
+ ### Responsive Strategy (Built-in)
163
+
164
+ - Automatically hides the middle area and secondary buttons when the window shrinks, keeping key operations like "Save" and "Feedback"; left logo/title are unaffected.
165
+ - Breakpoints:
166
+ - `≤1600px` Hide middle area
167
+ - `≤1400px` Hide copies, printer selection, preview, browser print, export PDF, export image
168
+ - `≤1200px` Hide direct print, language switch
169
+ - `≤992px` Hide clear
170
+ - `≤768px` Hide title text (keep Logo)
171
+
172
+ > Tip: If you need fully custom buttons, provide the `headerRight` slot.
173
+
174
+ ---
175
+
176
+ ## Preview Component
177
+
178
+ - Independent preview modal component, supports rendering template HTML, selecting printer, exporting PDF/image, direct printing, etc.
179
+ - Can be used separately or with `FullDesigner`.
180
+
181
+ ### Props
182
+
183
+ - `printTemplate: object` Template object (`hiprint.PrintTemplate` or return value of `createTemplate`)
184
+ - `printData: object | array` Print data
185
+ - `printerList: Array<{ name: string; label: string }>` Printer list
186
+ - `selectedPrinter: string` Selected printer name
187
+ - `showPdf: boolean` Show "Export PDF" button, default `true`
188
+ - `showImg: boolean` Show "Export Image" button, default `true`
189
+ - `showPrint2: boolean` Show "Direct Print" button, default `true`
190
+ - `modalShow: boolean` Modal visibility (supports `v-model:modalShow`)
191
+ - `width: string | number` Modal width (default `'80%'`)
192
+ - `defaultLang: string` Component i18n language (used when Standalone); supports `cn`, `en`, `de`, `es`, `fr`, `it`, `ja`, `ru`, `cn_tw`; default `cn`
193
+
194
+ ### Events (Emits)
195
+
196
+ - `update:modalShow` Two-way binding for modal visibility
197
+ - `update:selectedPrinter` Selected printer change
198
+ - `close` Close modal
199
+
200
+ ### Exposed Methods (defineExpose)
201
+
202
+ - `show(template, data, width?)` Show and render preview content; can pass template/data and width
203
+ - `hideModal()` Close modal
204
+ - `init()` Initialize (internal use)
205
+ - `getTarget()` Get preview container DOM
206
+
207
+ ### Usage Example (Standalone)
208
+
209
+ ```vue
210
+ <template>
211
+ <el-button @click="openPreview">Show Preview</el-button>
212
+ <Preview
213
+ ref="previewRef"
214
+ v-model:modalShow="visible"
215
+ default-lang="cn"
216
+ :printerList="printers"
217
+ :selectedPrinter="printer"
218
+ @update:selectedPrinter="printer = $event"
219
+ />
220
+ </template>
221
+
222
+ <script setup>
223
+ import { ref } from 'vue'
224
+ import { Preview, createTemplate } from 'vg-print'
225
+ import 'vg-print/style.css'
226
+
227
+ const previewRef = ref(null)
228
+ const visible = ref(false)
229
+ const printers = ref([{ name: 'HP_001', label: 'HP Printer' }])
230
+ const printer = ref('')
231
+
232
+ const tmplJson = { panels: [ /* ... */ ] }
233
+ const data = { title: 'Report', name: 'DongDong' }
234
+
235
+ const openPreview = () => {
236
+ const tpl = createTemplate(tmplJson) // Or pass hiprint.PrintTemplate
237
+ previewRef.value.show(tpl, data, '80%')
238
+ }
239
+ </script>
240
+ ```
241
+
242
+ ### Usage Example (With FullDesigner)
243
+
244
+ ```vue
245
+ <template>
246
+ <FullDesigner ref="designer" default-lang="cn" />
247
+ <Preview ref="previewRef" v-model:modalShow="visible" />
248
+ <el-button @click="designer.value.preView()">Use FullDesigner's Preview</el-button>
249
+ <el-button @click="showCustomPreview">Use Preview Component</el-button>
250
+ </template>
251
+
252
+ <script setup>
253
+ import { ref } from 'vue'
254
+ const designer = ref(null)
255
+ const previewRef = ref(null)
256
+ const visible = ref(false)
257
+
258
+ const showCustomPreview = () => {
259
+ const tpl = designer.value.getTemplate() // Assuming method exposed
260
+ const data = designer.value.getPrintData() // Assuming method exposed
261
+ previewRef.value.show(tpl, data, '80%')
262
+ }
263
+ </script>
264
+ ```
265
+
266
+ ### Note
267
+
268
+ - Please import `vg-print/style.css` when using the component library.
269
+ - `Preview` automatically renders content based on `printTemplate` and `printData`.
270
+ - If using `Preview` separately without plugin installation, set `default-lang`.
271
+
272
+ Style Import:
273
+
274
+ ```javascript
275
+ // Global style
276
+ import 'vg-print/style.css'
277
+
278
+ // Print lock style (Recommended)
279
+ // In `index.html`:
280
+ // <link rel="stylesheet" type="text/css" media="print" href="/css/print-lock.css" />
281
+ ```
282
+
283
+ Environment: Vue 3, Node >= 18.18.
284
+
285
+ ## Quick Start
286
+
287
+ ```javascript
288
+ // main.ts
289
+ import { createApp } from 'vue'
290
+ import App from './App.vue'
291
+ import vgPrint from 'vg-print'
292
+ import 'vg-print/style.css'
293
+
294
+ createApp(App).use(vgPrint).mount('#app')
295
+ ```
296
+
297
+ ```vue
298
+ <template>
299
+ <FullDesigner
300
+ ref="designer"
301
+ :hi-host="'http://127.0.0.1:17521'"
302
+ :hi-token="'your-token'"
303
+ :hi-auto-connect="true"
304
+ />
305
+ <!-- Buttons... -->
306
+ </template>
307
+ <script setup>
308
+ // ... Same as above
309
+ </script>
310
+ ```
311
+
312
+ ## API (FullDesigner)
313
+
314
+ ### Props
315
+
316
+ - `hi-host: string` Client service address
317
+ - `hi-token: string` Client auth token
318
+ - `hi-auto-connect: boolean` Auto connect to client
319
+ - `initial-template: object` Initial template JSON
320
+ - `initial-print-data: object | array` Initial print data
321
+ - `default-lang: string` Default language
322
+
323
+ ### Methods
324
+
325
+ - `preView()` Open preview
326
+ - `printView()` Browser print
327
+ - `print()` Direct print
328
+ - `toPdf()` Export PDF
329
+ - `toImage()` Export Image
330
+ - `setHiwebSocket(host, token, cb)` Set client address/token
331
+ - `connect(cb)` Connect to client
332
+ - `disconnect()` Disconnect
333
+ - `disAutoConnect()` Disable auto-connect
334
+
335
+ ### Events
336
+
337
+ - `save` Save template and data
338
+
339
+ ## Advanced Usage (hiprint)
340
+
341
+ ```javascript
342
+ import { hiprint, defaultElementTypeProvider } from 'vg-print'
343
+ // Global Config
344
+ hiprint.setConfig({ showAdsorbLine: true, showPosition: true, showSizeBox: true })
345
+ // Register Plugins
346
+ hiprint.register({ authKey: '', plugins: [] })
347
+ // Init
348
+ hiprint.init({
349
+ host: 'http://localhost:17521',
350
+ token: '',
351
+ lang: 'en'
352
+ })
353
+ // Create Template
354
+ const tpl = new hiprint.PrintTemplate({ template: {} })
355
+ // Design
356
+ tpl.design('#hiprint-printTemplate', { grid: true })
357
+ // Print
358
+ tpl.print({ name: 'Example' })
359
+ ```
360
+
361
+ ### Auth Key and Default Watermark
362
+
363
+ - **Design State**: No default watermark.
364
+ - **Runtime State**:
365
+ - No Auth: Default watermark or "Trial Version" suffix.
366
+ - With Auth: No default watermark.
367
+
368
+ Register:
369
+ ```javascript
370
+ hiprint.register({ authKey: 'YOUR_KEY' });
371
+ ```
372
+
373
+ ## Lightweight Runtime API
374
+
375
+ Use when you only need "Template + Data" capabilities without the designer UI.
376
+
377
+ ```javascript
378
+ import { createTemplate, printBrowser, exportPdf, exportImage } from 'vg-print'
379
+
380
+ const tpl = createTemplate(tmplJson)
381
+ printBrowser(tpl, printData)
382
+ exportPdf(tpl, printData, 'filename')
383
+ ```
384
+
385
+ ### Export PDF / Image
386
+
387
+ Support normal export and A4 layout export.
388
+
389
+ ### Notes
390
+
391
+ - Inject `print-lock.css` in `index.html`.
392
+ - Direct printing needs a client.
393
+ - SSR compatible.
394
+
395
+ ## Full Example
396
+
397
+ (See the code block in the Chinese section or above)
398
+
399
+
400
+
401
+ ---
402
+
403
+ <span id="chinese"></span>
404
+
405
+ # vg-print
406
+
3
407
  一个开箱即用的打印设计器组件库(Vue 3)。现在聚焦于单一组件 `FullDesigner`,同时暴露底层 `hiprint` 能力与客户端直连(`hiwebSocket`)配置,便于快速集成模板设计、预览、浏览器打印、导出 PDF/图片、直接打印等功能。
4
- ![功能截图](https://gitee.com/gao111/electron-vg-print/raw/master/ScreenShot_2025-12-25_163332_128.png)
5
408
  您可以直接安装引入体验功能.功能在不断完善中,请及时更新使用,欢迎反馈与建议.
6
409
  没有域名限制,无网可用. 提供一对一技术支持.
7
410
  npm搜索vg-print.
@@ -1,4 +1,4 @@
1
- import { l as b } from "./index-CObxKOd4.js";
1
+ import { l as b } from "./index-CfOjmFTG.js";
2
2
  function M(e) {
3
3
  return typeof e == "string" && /^data:image\/svg\+xml/i.test(e);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { W as a } from "./chunk-3VYIPD3A-8-s1FXRt.js";
1
+ import { W as a } from "./chunk-3VYIPD3A-CmWW5n71.js";
2
2
  async function o(r, t) {
3
3
  let i = await a(r, t), e = new Image();
4
4
  return e.src = i.toDataURL(`image/${t.format}`, t.quality), await e.decode(), e.style.width = `${i.width / t.dpr}px`, e.style.height = `${i.height / t.dpr}px`, e;
@@ -1,4 +1,4 @@
1
- import { W as m } from "./chunk-3VYIPD3A-8-s1FXRt.js";
1
+ import { W as m } from "./chunk-3VYIPD3A-CmWW5n71.js";
2
2
  async function a(n, e) {
3
3
  let o = e.type;
4
4
  if (o === "svg") {
@@ -1,5 +1,5 @@
1
- import { m as f } from "./chunk-T4JIPPZO-DQlmVEHv.js";
2
- import { W as t } from "./chunk-3VYIPD3A-8-s1FXRt.js";
1
+ import { m as f } from "./chunk-T4JIPPZO-BmQfzzcF.js";
2
+ import { W as t } from "./chunk-3VYIPD3A-CmWW5n71.js";
3
3
  async function w(n, e) {
4
4
  let c = ((e == null ? void 0 : e.format) || (e == null ? void 0 : e.type) || "").toLowerCase(), a = c === "jpg" ? "jpeg" : c || "png", i = (e == null ? void 0 : e.filename) || `snapdom.${a}`, o = { ...e || {}, format: a, type: a };
5
5
  if (o.dpr = 1, a === "svg") {