@bluechaine/print-designer 0.1.0 → 0.1.2
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 +104 -1
- package/README.md +118 -1
- package/dist/print-client/index.cjs +1071 -0
- package/dist/print-client/index.cjs.map +1 -0
- package/dist/print-client/index.mjs +1055 -0
- package/dist/print-client/index.mjs.map +1 -0
- package/dist/types/src/components/Designer.vue.d.ts +35 -4
- package/dist/types/src/components/Preview.vue.d.ts +33 -2
- package/dist/types/src/core/batch-print.d.ts +30 -0
- package/dist/types/src/core/designer-utils.d.ts +13 -3
- package/dist/types/src/core/hiprint-bridge.d.ts +4 -6
- package/dist/types/src/core/print-client.d.ts +30 -0
- package/dist/types/src/i18n/en-US.d.ts +12 -0
- package/dist/types/src/i18n/zh-CN.d.ts +12 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/print-client-entry.d.ts +5 -0
- package/dist/types/src/types.d.ts +51 -0
- package/dist/vue2/index.cjs +1061 -340
- package/dist/vue2/index.cjs.map +1 -1
- package/dist/vue2/index.mjs +1038 -328
- package/dist/vue2/index.mjs.map +1 -1
- package/dist/vue2/index.umd.cjs +1061 -340
- package/dist/vue2/index.umd.cjs.map +1 -1
- package/dist/vue2/style.css +55 -1
- package/dist/vue3/index.cjs +1065 -344
- package/dist/vue3/index.cjs.map +1 -1
- package/dist/vue3/index.mjs +1042 -332
- package/dist/vue3/index.mjs.map +1 -1
- package/dist/vue3/index.umd.cjs +1065 -344
- package/dist/vue3/index.umd.cjs.map +1 -1
- package/dist/vue3/style.css +55 -1
- package/package.json +15 -5
package/README.en.md
CHANGED
|
@@ -66,7 +66,7 @@ const styleOption = {
|
|
|
66
66
|
| `Designer` | Root component — panels, header, toolbar, preview |
|
|
67
67
|
| `Header` | Top bar: file actions + optional quick-insert element tabs |
|
|
68
68
|
| `Toolbar` | Undo/redo, alignment, z-index, font, lock, copy/paste, zoom, panel toggles |
|
|
69
|
-
| `Preview` | Print preview modal (
|
|
69
|
+
| `Preview` | Print preview modal (browser / silent print / PDF / image export) |
|
|
70
70
|
| `DragBox` | Reusable draggable / foldable floating panel shell |
|
|
71
71
|
|
|
72
72
|
## Customization
|
|
@@ -149,6 +149,109 @@ import { pluginApiImage } from '@bluechaine/print-designer/plugins/api-image'
|
|
|
149
149
|
import { pluginViewCodeEdit } from '@bluechaine/print-designer/plugins/view-code-edit'
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## Silent print (print2)
|
|
153
|
+
|
|
154
|
+
Silent printing requires the [electron-hiprint](https://gitee.com/CcSimple/electron-hiprint) desktop client (default port `17521`). `vue-plugin-hiprint` talks to it over socket.io and skips the browser print dialog.
|
|
155
|
+
|
|
156
|
+
Optional peer: `socket.io-client@^4.5` (match your `vue-plugin-hiprint` version).
|
|
157
|
+
|
|
158
|
+
### Inside the designer preview
|
|
159
|
+
|
|
160
|
+
After opening preview:
|
|
161
|
+
|
|
162
|
+
1. Click **Connect Client**
|
|
163
|
+
2. Pick a printer from the dropdown
|
|
164
|
+
3. Click **Silent Print** (`print2`)
|
|
165
|
+
|
|
166
|
+
Or pass `:auto-connect="true"` to connect when the designer mounts.
|
|
167
|
+
|
|
168
|
+
`previewOptions`:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const previewOptions = {
|
|
172
|
+
showBrowserPrint: true, // browser print button, default true
|
|
173
|
+
showPrint2: true, // silent print button, default true
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Programmatic use in the designer
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
function onDesigned(e: any) {
|
|
181
|
+
const utils = e.designerUtils
|
|
182
|
+
|
|
183
|
+
utils.setConnect(true, (connected) => {
|
|
184
|
+
if (!connected) return
|
|
185
|
+
const printers = utils.getPrinterList()
|
|
186
|
+
void utils.print2({ name: 'demo' }, {
|
|
187
|
+
printer: printers[0]?.name ?? '',
|
|
188
|
+
title: 'Outbound',
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Batch: pass an array to `print2`:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
await utils.print2(orders, {
|
|
198
|
+
printer: 'Printer name',
|
|
199
|
+
title: 'Batch print',
|
|
200
|
+
printByFragments: true,
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Browser batch print (no client required)
|
|
205
|
+
|
|
206
|
+
You can print many records at once without electron-hiprint. The designer merges every record into a multi-page HTML and triggers the browser print dialog only once inside a hidden iframe.
|
|
207
|
+
|
|
208
|
+
In preview:
|
|
209
|
+
|
|
210
|
+
1. Pass an array as `printData`
|
|
211
|
+
2. Set the copies-per-record value (default 1)
|
|
212
|
+
3. Click **Batch Print** — the browser dialog opens just once
|
|
213
|
+
|
|
214
|
+
Programmatic:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
function onDesigned(e: any) {
|
|
218
|
+
const utils = e.designerUtils
|
|
219
|
+
const orders = [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
220
|
+
await utils.batchPrint(orders, {
|
|
221
|
+
copies: 2, // 6 pages total
|
|
222
|
+
title: 'Batch outbound',
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Or call the helper directly:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { batchPrint } from '@bluechaine/print-designer'
|
|
231
|
+
await batchPrint(printTemplate, orders, { copies: 3 })
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Best for human-confirmed batches. Unattended silent printing still requires `print2` + electron-hiprint.
|
|
235
|
+
|
|
236
|
+
### Headless use in other projects
|
|
237
|
+
|
|
238
|
+
Without mounting `Designer`, import `@bluechaine/print-designer/print-client`:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
import { getPrintClient } from '@bluechaine/print-designer/print-client'
|
|
242
|
+
|
|
243
|
+
const client = getPrintClient()
|
|
244
|
+
|
|
245
|
+
const status = await client.connect({ host: 'http://localhost:17521' })
|
|
246
|
+
if (!status.connected) throw new Error(status.message)
|
|
247
|
+
|
|
248
|
+
const printers = client.getPrinterList()
|
|
249
|
+
await client.printByTemplate(templateJson, printData, {
|
|
250
|
+
printer: printers[0]?.name ?? '',
|
|
251
|
+
title: 'Silent print',
|
|
252
|
+
})
|
|
253
|
+
```
|
|
254
|
+
|
|
152
255
|
## License
|
|
153
256
|
|
|
154
257
|
MIT
|
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ const styleOption = {
|
|
|
63
63
|
| `Designer` | 根组件,组装面板、顶栏、工具栏、预览 |
|
|
64
64
|
| `Header` | 顶栏:文件操作 + 可选的元素快捷插入 |
|
|
65
65
|
| `Toolbar` | 撤销/重做、对齐、层级、字号、锁定、复制粘贴、缩放、面板开关 |
|
|
66
|
-
| `Preview` |
|
|
66
|
+
| `Preview` | 打印预览弹窗(浏览器打印 / 静默打印 / PDF / 图片导出) |
|
|
67
67
|
| `DragBox` | 可拖拽、可折叠的浮层面板容器 |
|
|
68
68
|
|
|
69
69
|
## 自定义
|
|
@@ -146,6 +146,123 @@ import { pluginApiImage } from '@bluechaine/print-designer/plugins/api-image'
|
|
|
146
146
|
import { pluginViewCodeEdit } from '@bluechaine/print-designer/plugins/view-code-edit'
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
+
## 静默打印(print2)
|
|
150
|
+
|
|
151
|
+
静默打印需要安装 [electron-hiprint](https://gitee.com/CcSimple/electron-hiprint) 客户端(默认端口 `17521`)。`vue-plugin-hiprint` 通过 socket.io 与客户端通信,不弹出浏览器打印框。
|
|
152
|
+
|
|
153
|
+
可选 peer:`socket.io-client@^4.5`(与 `vue-plugin-hiprint` 版本匹配)。
|
|
154
|
+
|
|
155
|
+
### 设计器预览内使用
|
|
156
|
+
|
|
157
|
+
打开预览后可:
|
|
158
|
+
|
|
159
|
+
1. 点击 **连接客户端**
|
|
160
|
+
2. 在下拉框选择打印机
|
|
161
|
+
3. 点击 **静默打印**(`print2`)
|
|
162
|
+
|
|
163
|
+
也可设置 `:auto-connect="true"`,设计器挂载后自动连接客户端。
|
|
164
|
+
|
|
165
|
+
`previewOptions`:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const previewOptions = {
|
|
169
|
+
showBrowserPrint: true, // 浏览器打印按钮,默认 true
|
|
170
|
+
showPrint2: true, // 静默打印按钮,默认 true
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 设计器内编程调用
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
function onDesigned(e: any) {
|
|
178
|
+
const utils = e.designerUtils
|
|
179
|
+
|
|
180
|
+
utils.setConnect(true, (connected) => {
|
|
181
|
+
if (!connected) return
|
|
182
|
+
const printers = utils.getPrinterList()
|
|
183
|
+
void utils.print2({ name: '测试' }, {
|
|
184
|
+
printer: printers[0]?.name ?? '',
|
|
185
|
+
title: '出库单',
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
批量打印:将数组传给 `print2`:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
await utils.print2(orders, {
|
|
195
|
+
printer: '打印机名称',
|
|
196
|
+
title: '批量出库',
|
|
197
|
+
printByFragments: true,
|
|
198
|
+
})
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 浏览器批量打印(无需客户端)
|
|
202
|
+
|
|
203
|
+
不安装 electron-hiprint 也能批量打印 —— 设计器把多条数据合并成多页 HTML,在隐藏 iframe 中只触发一次浏览器打印对话框:
|
|
204
|
+
|
|
205
|
+
预览弹窗内:
|
|
206
|
+
|
|
207
|
+
1. 把多条数据传给 `printData`(支持数组)
|
|
208
|
+
2. 在「每条份数」里填份数(默认 1)
|
|
209
|
+
3. 点 **批量打印**,浏览器只弹一次打印框
|
|
210
|
+
|
|
211
|
+
编程调用:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
function onDesigned(e: any) {
|
|
215
|
+
const utils = e.designerUtils
|
|
216
|
+
const orders = [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
217
|
+
await utils.batchPrint(orders, {
|
|
218
|
+
copies: 2, // 每条打印 2 份,共 6 页
|
|
219
|
+
title: '批量出库单',
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
或直接调用底层函数:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { batchPrint } from '@bluechaine/print-designer'
|
|
228
|
+
await batchPrint(printTemplate, orders, { copies: 3 })
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
适用:偶发批量、人工确认场景;要无人值守静默打印仍推荐 `print2` + electron-hiprint。
|
|
232
|
+
|
|
233
|
+
### Headless:其它项目独立调用
|
|
234
|
+
|
|
235
|
+
不挂载 `Designer` 时,使用 `@bluechaine/print-designer/print-client`:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { getPrintClient } from '@bluechaine/print-designer/print-client'
|
|
239
|
+
|
|
240
|
+
const client = getPrintClient()
|
|
241
|
+
|
|
242
|
+
const status = await client.connect({ host: 'http://localhost:17521' })
|
|
243
|
+
if (!status.connected) throw new Error(status.message)
|
|
244
|
+
|
|
245
|
+
const printers = client.getPrinterList()
|
|
246
|
+
await client.printByTemplate(templateJson, printData, {
|
|
247
|
+
printer: printers[0]?.name ?? '',
|
|
248
|
+
title: '静默打印',
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// 批量
|
|
252
|
+
await client.printByTemplate(templateJson, [row1, row2, row3], {
|
|
253
|
+
printer: '打印机名称',
|
|
254
|
+
title: '批量打印',
|
|
255
|
+
})
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
事件订阅:
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
client.onConnectionChange((status) => console.log(status))
|
|
262
|
+
client.onPrintSuccess((data) => console.log('done', data))
|
|
263
|
+
client.onPrintError((err) => console.error(err))
|
|
264
|
+
```
|
|
265
|
+
|
|
149
266
|
## 许可
|
|
150
267
|
|
|
151
268
|
MIT
|