x-print-designer 0.4.7 → 0.4.10
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 +24 -4
- package/dist/{JsBarcode-DaJP3cMD.js → JsBarcode-hwIbESSq.js} +1 -1
- package/dist/{browser-PaZLWyYp.js → browser-B42qU2Gc.js} +1 -1
- package/dist/{dom-to-image-more.min-DtQ9SBfy.js → dom-to-image-more.min-CU_b0kYq.js} +1 -1
- package/dist/{index-Bn1xBFgs.js → index-B22omX0t.js} +1 -1
- package/dist/{web-component-Br3Z4YwZ.js → index-CdthNk7W.js} +17509 -16818
- package/dist/{index.es-DOTR4Gpv.js → index.es-CiDqHgnT.js} +1 -1
- package/dist/{jspdf.es.min-CNj84VyV.js → jspdf.es.min-CChwRLqD.js} +1 -1
- package/dist/{jszip.min-DaIRYCRX.js → jszip.min-vJ-K28K8.js} +1 -1
- package/dist/print-designer.css +1 -1
- package/dist/print-designer.es.js +13 -2
- package/dist/print-designer.umd.js +38 -38
- package/dist/web-component.d.ts +56 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -350,17 +350,37 @@ designer.setMode('report')
|
|
|
350
350
|
| `setTestData(data)` | `Record<string, any>` | `void` | 设置测试/预览数据(等价 Vue 组件的 `sample-data`) |
|
|
351
351
|
| `setSampleData(data)` | `Record<string, any>` | `void` | `setTestData` 的别名 |
|
|
352
352
|
| `setVariables(vars)` | `Record<string, any>` | `void` | 打印/导出时注入真实变量(覆盖 testData 中的同名字段) |
|
|
353
|
-
| `setTemplates(list, opts?)` | `Array<Template>, object?` | `void
|
|
354
|
-
| `loadTemplate(id)` | `string` | `Promise<
|
|
353
|
+
| `setTemplates(list, opts?)` | `Array<Template>, object?` | `Promise<void>` | 设置预设模板列表并加载当前模板。`opts` 可选:`{ currentTemplateId?: string }`。返回的 Promise 在画布 pages 填充完成后 resolve,可据此消除时序竞态 |
|
|
354
|
+
| `loadTemplate(id)` | `string` | `Promise<boolean>` | 加载指定模板到画布。resolve 时 pages 已填充;返回 `false` 表示因前置条件(如正在编辑自定义元素)未触发 |
|
|
355
355
|
| `loadTemplateData(data)` | `Record<string, any>` | `boolean` | 直接加载模板 JSON 数据到画布,返回是否成功 |
|
|
356
356
|
| `getTemplateData()` | — | `Record<string, any>` | 获取当前模板完整数据 |
|
|
357
357
|
| `getPreviewHtml()` | — | `Promise<string>` | 获取预览 HTML 字符串 |
|
|
358
358
|
| `print(options?)` | `PrintOptions` | `Promise<void>` | 执行打印,详见[打印与导出](#打印与导出) |
|
|
359
359
|
| `export(options?)` | `ExportOptions` | `Promise<void>` | 导出 PDF / 图片 / HTML,详见[打印与导出](#打印与导出) |
|
|
360
|
-
| `setPreviewMode(options)` | `PreviewModeOptions` | `void` |
|
|
360
|
+
| `setPreviewMode(options)` | `PreviewModeOptions` | `void` | 进入独立预览面板模式。传入的 `pages` 若含循环页(`loopDataVariable`),预览时会自动按数据展开成 N 页 |
|
|
361
361
|
| `exitPreviewMode()` | — | `void` | 退出预览模式,返回编辑器 |
|
|
362
362
|
| `setBranding(config)` | `{ title?, logoUrl?, showTitle?, showLogo? }` | `void` | 设置品牌标识 |
|
|
363
|
-
| `
|
|
363
|
+
| `setLanguage(lang)` | `'zh'` \| `'en'` | `void` | 切换语言 |
|
|
364
|
+
| `setCrudMode(mode, opts?)` | `'local'` \| `'remote'`, `{ skipAutoLoad?: boolean }` | `void` | 切换 CRUD 模式。`skipAutoLoad: true` 跳过 remote 模式下自动 `loadTemplates + loadTemplate` 的链式加载,适用于已通过 `setTemplates` 提供数据的场景,避免双次加载闪烁 |
|
|
365
|
+
| `expandLoopPages(pages, ctx?)` | `Page[], LoopExpandContext?` | `Page[]` | 循环页展开:按 `page.loopDataVariable` + 数据数组,把 1 个模板页展开成 N 页。不传 `ctx` 时默认使用当前 store 数据(导出语义) |
|
|
366
|
+
| `hasLoopPage(pages)` | `Page[]?` | `boolean` | 判断页面数组中是否含循环页 |
|
|
367
|
+
| `collapseLoopPages(currentPages, originalPages)` | `Page[], Page[]` | `Page[]` | 折叠已展开的循环页,还原为带 `loopDataVariable` 的单个模板页。适用于报告模式保存前还原模板结构 |
|
|
368
|
+
|
|
369
|
+
### 事件参考
|
|
370
|
+
|
|
371
|
+
Web Component 元素会派发以下自定义事件,可通过 `addEventListener` 监听:
|
|
372
|
+
|
|
373
|
+
| 事件名 | 触发时机 | `detail` 结构 |
|
|
374
|
+
|--------|---------|--------------|
|
|
375
|
+
| `ready` | 组件挂载完成、API 可调用时(下一个 tick 派发) | 无 |
|
|
376
|
+
| `templateloaded` | 模板加载完成、画布 pages 已填充时 | `{ id: string, mode: 'template' \| 'report' }` |
|
|
377
|
+
| `print` | 开始执行打印前 | `{ request: DesignerPrintRequest }` |
|
|
378
|
+
| `printed` | 打印成功完成 | `{ request, result }` |
|
|
379
|
+
| `export` | 开始导出前 | `{ request: DesignerExportRequest }` |
|
|
380
|
+
| `exported` | 导出成功完成(pdf/html/images/pdfBlob/imageBlob) | `{ request }` 或 `{ request, blob }`(Blob 类型) |
|
|
381
|
+
| `error` | 打印/导出/内部渲染出错 | `{ scope: 'print' \| 'export' \| 'getPreviewHtml' \| 'render', error, info? }` |
|
|
382
|
+
|
|
383
|
+
> **时序提示**:若需要在模板加载完成后执行操作(如注入运行时数据),监听 `templateloaded` 事件,或 `await` `setTemplates` / `loadTemplate` 返回的 Promise,二者等价且都比轮询 `store.pages` 更可靠。
|
|
364
384
|
|
|
365
385
|
### 基本使用示例
|
|
366
386
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, computed, onUnmounted, watch, shallowRef, loader, onMounted, nextTick, ref } from "./
|
|
1
|
+
import { defineComponent, h, computed, onUnmounted, watch, shallowRef, loader, onMounted, nextTick, ref } from "./index-CdthNk7W.js";
|
|
2
2
|
var __defProp$2 = Object.defineProperty;
|
|
3
3
|
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|