vg-print 1.1.205 → 1.1.207

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
@@ -181,6 +181,9 @@ const onSaveDirect = () => designer.value?.save()
181
181
  - `showPdf: boolean` Show "Export PDF" button, default `true`
182
182
  - `showImg: boolean` Show "Export Image" button, default `true`
183
183
  - `showPrint2: boolean` Show "Direct Print" button, default `true`
184
+ - `showPrinterSelect: boolean` Show printer selector area, default `true`
185
+ - `dialogTitle: string` Modal title, default `打印预览`
186
+ - `showTitle: boolean` Show title in modal, default `true`
184
187
  - `modalShow: boolean` Modal visibility (supports `v-model:modalShow`)
185
188
  - `width: string | number` Modal width (default `'80%'`)
186
189
  - `defaultLang: string` Component i18n language (used when Standalone); supports `cn`, `en`, `de`, `es`, `fr`, `it`, `ja`, `ru`, `cn_tw`; default `cn`
@@ -205,6 +208,8 @@ const onSaveDirect = () => designer.value?.save()
205
208
  <el-button @click="openPreview">Show Preview</el-button>
206
209
  <Preview
207
210
  ref="previewRef"
211
+ :show-title="false"
212
+ dialog-title="自定义预览标题"
208
213
  v-model:modalShow="visible"
209
214
  default-lang="cn"
210
215
  :printerList="printers"
@@ -228,7 +233,48 @@ const data = { title: 'Report', name: 'DongDong' }
228
233
 
229
234
  const openPreview = () => {
230
235
  const tpl = createTemplate(tmplJson) // Or pass hiprint.PrintTemplate
231
- previewRef.value.show(tpl, data, '80%')
236
+ // vue2方式:
237
+ previewRef.value?.show(tpl, data, '80%')
238
+ // 或
239
+ previewRef.value?.show(tpl, data)
240
+ // 或
241
+ previewRef.value?.show(tpl, data, {
242
+ width: '80%',
243
+ dialogTitle: '自定义预览',
244
+ showTitle: false,
245
+ showPdf: false,
246
+ showImg: false,
247
+ showPrint2: false,
248
+ showPrinterSelect: false,
249
+ onClick: (type) => {
250
+ // 示例:点击导出 PDF 按钮
251
+ if (type === 'pdf') {
252
+ console.log('[Preview onClick] 导出 PDF')
253
+ return
254
+ }
255
+ console.log('[Preview onClick]', type)
256
+ },
257
+ onClose: () => {
258
+ // 示例:弹窗关闭
259
+ console.log('[Preview onClose] 弹窗已关闭')
260
+ },
261
+ onRender: () => {
262
+ // 示例:预览内容渲染完成
263
+ console.log('[Preview onRender] 预览内容渲染完成')
264
+ },
265
+ callBackOptions: {
266
+ statusCallback: (status) => {
267
+ // 示例:导出进度(PDF/图片)
268
+ if (status.type === 'pdf:progress' || status.type === 'image:progress') {
269
+ const cur = status?.payload?.cur ?? 0
270
+ const total = status?.payload?.total ?? 0
271
+ console.log('[Preview progress]', cur, total)
272
+ return
273
+ }
274
+ console.log('[Preview status]', status.type, status.message || '')
275
+ }
276
+ }
277
+ })
232
278
  }
233
279
  </script>
234
280
  ```
@@ -494,4 +540,4 @@ await exportImage(tpl, printData, {
494
540
 
495
541
  ## Full Example
496
542
 
497
- (See the code block in the Chinese section or above)
543
+ (See the code block in the Chinese section or above)
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # vg-print
2
2
 
3
- [开源免费]一个开箱即用的打印设计器组件库(Vue 3)。现在聚焦于单一组件 `FullDesigner`,同时暴露底层 `hiprint` 能力与客户端直连(`hiwebSocket`)配置,便于快速集成模板设计、预览、浏览器打印、导出 PDF/图片、直接打印等功能。
3
+ [开源免费]一个开箱即用的打印设计器组件库(Vue 3)。现在聚焦于单一组件 `FullDesigner`,同时暴露底层 `hiprint` 能力与客户端直连(`hiwebSocket`)配置,便于快速集成模板设计、预览、浏览器打印、导出 PDF/图片、直接打印、客户端生成pdf/图片、数据源管理、多语言支持等功能。
4
4
  - 您可以直接安装引入体验功能.功能在不断完善中,请及时更新使用,欢迎反馈与建议,共同成长
5
5
  - 没有域名限制,无网可用. 随时提供帮助和解决问题.
6
6
  - npm搜索vg-print.
7
7
  - 联系我加 QQ: 984239686 或使用首页有微信加入群聊解决问题.
8
8
 
9
- > **Vue 2 版本**: 如果你使用的是 Vue 2+webpack4.0以上,请查看 [vg-print-vue2](https://www.npmjs.com/package/vg-print-vue2)
9
+ > **Vue 2 版本**: 如果你使用的是 Vue2+webpack4.0以上,请查看 [vg-print-vue2](https://www.npmjs.com/package/vg-print-vue2)
10
10
 
11
11
  [vg-print开发者文档](https://www.yuque.com/designdev/vg-print)
12
12
 
@@ -100,7 +100,7 @@ hiprint.register({
100
100
  - 全功能页面组件 `FullDesigner`,直接使用,无需拼装子组件
101
101
  - 支持预览、浏览器打印、导出 PDF/图片、直接打印(需客户端)
102
102
  - 通过属性配置 `hiwebSocket` 的 `host`、`token` 与自动连接
103
- - 暴露实例方法:预览、打印、导出、连接控制等,外部可直接调用
103
+ - 暴露实例方法:预览、打印、导出、客户端生成pdf/图片等,外部可直接调用
104
104
  - 集成并导出 `hiprint`,可进行模板对象级的高级定制
105
105
 
106
106
 
@@ -257,13 +257,24 @@ const onSaveDirect = () => designer.value?.save()
257
257
  - `printData: object | array` 打印数据
258
258
  - `printerList: Array<{ name: string; label: string }>` 打印机列表
259
259
  - `selectedPrinter: string` 选中的打印机名称
260
+ - `dialogTitle: string` 弹窗标题,默认 `打印预览`
261
+ - `dialogTitleHtml: string` 弹窗标题 HTML 内容,默认 `''`(支持 `弹窗标题)
262
+ - `showTitle: boolean` 是否显示标题,默认 `true`
260
263
  - `showPdf: boolean` 是否显示“导出 PDF”按钮,默认 `true`
261
264
  - `showImg: boolean` 是否显示“导出图片”按钮,默认 `true`
262
265
  - `showPrint2: boolean` 是否显示“直接打印”按钮,默认 `true`
266
+ - `showPrinterSelect: boolean` 是否显示“打印机选择”下拉区域,默认 `true`
263
267
  - `modalShow: boolean` 弹窗显隐(支持 `v-model:modalShow`)
264
268
  - `width: string | number` 弹窗宽度(默认 `'80%'`)
265
269
  - `defaultLang: string` 组件内 i18n 语言(Standalone 时使用);支持 `cn`、`en`、`de`、`es`、`fr`、`it`、`ja`、`ru`、`cn_tw`;默认 `cn`
266
270
 
271
+ 预览头部标题使用
272
+ - 传纯文本(原有方式):
273
+ - dialogTitle: '预览单据'
274
+ - 传带标签 HTML:
275
+ - dialogTitleHtml: '<span class="my-title"><i>订单</i>预览</span>'
276
+ - 用插槽完全自定义(推荐,样式控制最灵活):
277
+ - <template #title="{ title, html }">...</template>
267
278
  ### 事件(Emits)
268
279
 
269
280
  - `update:modalShow` 双向绑定弹窗显隐
@@ -272,10 +283,48 @@ const onSaveDirect = () => designer.value?.save()
272
283
 
273
284
  ### 暴露方法(defineExpose)
274
285
 
275
- - `show(template, data, width?)` 显示并渲染预览内容;可传入模板/数据与弹窗宽度
286
+ - `show(template, data, width?)` 显示并渲染预览内容(兼容旧调用)
287
+ - `show(template, data, options?)` 显示并渲染预览内容(推荐)
288
+ - `show(template, data, width, options?)` 同时传入宽度与高级回调参数
276
289
  - `hideModal()` 关闭弹窗
277
290
  - `init()` 初始化(内部使用)
278
- - `getTarget()` 获取预览容器 DOM
291
+ - `getTarget()` 获取当前 `hiprintTemplate` 实例
292
+
293
+
294
+ ### show 方法高级参数(options)
295
+ - 始终回调 { type, message, payload }
296
+ - 但只有“异常/进度”场景才会带 message 或 payload
297
+ - 普通状态(如 show:start 、 render:done 、 image:done )没有额外信息,所以就是 undefined
298
+
299
+ ```ts
300
+ type PreviewShowOptions = {
301
+ width?: string | number
302
+ dialogTitle?: string
303
+ dialogTitleHtml?: string
304
+ showPdf?: boolean
305
+ showImg?: boolean
306
+ showPrint2?: boolean
307
+ showPrinterSelect?: boolean
308
+ showTitle?: boolean
309
+ onClick?: (type: 'pdf' | 'img' | 'print' | 'print2' | 'close') => void
310
+ onClose?: () => void
311
+ onRender?: () => void
312
+ callBackOptions?: {
313
+ statusCallback?: (status: {
314
+ type:
315
+ | 'show:start' | 'show:ready'
316
+ | 'render:start' | 'render:done' | 'render:error'
317
+ | 'pdf:start' | 'pdf:progress' | 'pdf:done' | 'pdf:error'
318
+ | 'image:start' | 'image:progress' | 'image:done' | 'image:error'
319
+ | 'print:start' | 'print:done' | 'print:error'
320
+ | 'directPrint:start' | 'directPrint:progress' | 'directPrint:done' | 'directPrint:error'
321
+ | 'close'
322
+ message?: string
323
+ payload?: any
324
+ }) => void
325
+ }
326
+ }
327
+ ```
279
328
 
280
329
  ### 使用示例(单独使用)
281
330
 
@@ -284,6 +333,8 @@ const onSaveDirect = () => designer.value?.save()
284
333
  <el-button @click="openPreview">显示预览</el-button>
285
334
  <Preview
286
335
  ref="previewRef"
336
+ :show-title="false"
337
+ dialog-title="自定义预览标题"
287
338
  v-model:modalShow="visible"
288
339
  default-lang="cn"
289
340
  :printerList="printers"
@@ -305,9 +356,56 @@ const printer = ref('')
305
356
  const tmplJson = { panels: [ /* ... */ ] }
306
357
  const data = { title: '病理图文报告', name: '东东' }
307
358
 
359
+ // show(template, data, width?)
360
+ // 参数说明:
361
+ // 1) template: createTemplate(...) 返回的模板实例(或 hiprint.PrintTemplate)
362
+ // 2) data: 打印数据(对象或数组)
363
+ // 3) width: 弹窗宽度;支持百分比字符串(如 '80%')或数字(如 980,单位 px)
308
364
  const openPreview = () => {
309
365
  const tpl = createTemplate(tmplJson) // 也可传入 hiprint.PrintTemplate
310
- previewRef.value.show(tpl, data, '80%')
366
+ // vue2方式:
367
+ previewRef.value?.show(tpl, data, '80%')
368
+ // 或
369
+ previewRef.value?.show(tpl, data)
370
+ // 或
371
+ previewRef.value?.show(tpl, data, {
372
+ width: '80%',
373
+ dialogTitle: '自定义预览',
374
+ dialogTitleHtml: '<h2>自定义预览标题</h2>',
375
+ showTitle: false,
376
+ showPdf: false,
377
+ showImg: false,
378
+ showPrint2: false,
379
+ showPrinterSelect: false,
380
+ onClick: (type) => {
381
+ // 示例:点击导出 PDF 按钮
382
+ if (type === 'pdf') {
383
+ console.log('[Preview onClick] 导出 PDF')
384
+ return
385
+ }
386
+ console.log('[Preview onClick]', type)
387
+ },
388
+ onClose: () => {
389
+ // 示例:弹窗关闭
390
+ console.log('[Preview onClose] 弹窗已关闭')
391
+ },
392
+ onRender: () => {
393
+ // 示例:预览内容渲染完成
394
+ console.log('[Preview onRender] 预览内容渲染完成')
395
+ },
396
+ callBackOptions: {
397
+ statusCallback: (status) => {
398
+ // 示例:导出进度(PDF/图片)
399
+ if (status.type === 'pdf:progress' || status.type === 'image:progress') {
400
+ const cur = status?.payload?.cur ?? 0
401
+ const total = status?.payload?.total ?? 0
402
+ console.log('[Preview progress]', cur, total)
403
+ return
404
+ }
405
+ console.log('[Preview status]', status.type, status.message || '')
406
+ }
407
+ }
408
+ })
311
409
  }
312
410
  </script>
313
411
  ```
@@ -340,6 +438,7 @@ const showCustomPreview = () => {
340
438
 
341
439
  - 使用组件库时请引入 `vg-print/style.css`,其中包含自定义图标字体与预览/设计样式。
342
440
  - `Preview` 内部会根据 `printTemplate` 与 `printData` 自动渲染内容;也支持通过 `show(...)` 主动传入。
441
+ - `show(...)` 兼容原签名 `show(template, data, width?)`,建议新项目统一使用 `options` 写法,便于扩展和维护。
343
442
  - 若在外部项目未安装插件(未执行 `app.use(vgPrint)`)而单独使用 `Preview`,请通过 `default-lang` 显式设置语言;安装插件时无需设置,语言默认随全局 i18n。
344
443
 
345
444
 
@@ -1,4 +1,4 @@
1
- import { l as b } from "./index-DIcTZZ1w.js";
1
+ import { l as b } from "./index-B8EY3cmT.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-MW6X4KTL-BcL0iwUt.js";
1
+ import { W as a } from "./chunk-MW6X4KTL-Fna8JcZ0.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-MW6X4KTL-BcL0iwUt.js";
1
+ import { W as m } from "./chunk-MW6X4KTL-Fna8JcZ0.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-Y7FY32AO-CKFAwivO.js";
2
- import { W as t } from "./chunk-MW6X4KTL-BcL0iwUt.js";
1
+ import { m as f } from "./chunk-Y7FY32AO-NbE7aDO_.js";
2
+ import { W as t } from "./chunk-MW6X4KTL-Fna8JcZ0.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") {