vg-print 1.0.208 → 1.0.209
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 +117 -209
- package/dist/style.css +1 -1
- package/dist/vg-print.es.js +83881 -0
- package/dist/vg-print.umd.js +5143 -0
- package/package.json +8 -21
- package/dist/hiprint-designer.es.js +0 -80516
- package/dist/hiprint-designer.umd.js +0 -3518
package/README.md
CHANGED
|
@@ -1,288 +1,196 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vg-print-designer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个基于 `vue-plugin-hiprint` 的打印设计器组件库(Vue 3)。将项目中的设计页封装为可复用组件,提供 `Designer`、`Header`、`Preview`、`DragBox` 四个组件,方便在任何业务项目中快速集成打印模板设计、预览与导出能力。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 可视化拖拽设计打印模板,支持网格线、面板激活等配置
|
|
8
|
+
- 预览支持导出 PDF/图片、浏览器打印、直接打印(需客户端)
|
|
9
|
+
- 插件机制可扩展元素类型,与 `vue-plugin-hiprint` 完整兼容
|
|
10
|
+
- 组件化封装,按需组合 `Header/Designer/Preview/DragBox`
|
|
4
11
|
|
|
5
12
|
## 安装
|
|
6
13
|
|
|
7
|
-
```
|
|
14
|
+
```
|
|
8
15
|
npm i vg-print
|
|
9
16
|
```
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
样式引入(确保设计器与打印样式生效):
|
|
12
19
|
|
|
13
|
-
```html
|
|
14
|
-
<link rel="stylesheet" type="text/css" media="print" href="/print-lock.css" />
|
|
15
20
|
```
|
|
21
|
+
// 全局样式(组件库样式)
|
|
22
|
+
import 'vg-print/style.css'
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```html
|
|
24
|
+
// 打印锁样式(可选;库已内置常用样式,如需严格 media="print" 可额外添加)
|
|
25
|
+
在 `index.html` 中引入打印锁样式:
|
|
20
26
|
<link rel="stylesheet" type="text/css" media="print" href="https://cdn.jsdelivr.net/npm/vue-plugin-hiprint@latest/dist/print-lock.css" />
|
|
21
27
|
```
|
|
22
28
|
|
|
29
|
+
环境要求:Vue 3、Node >= 18.18。无需单独安装 `vue-plugin-hiprint`,本插件已内置并导出 `hiprint` 能力。
|
|
30
|
+
|
|
23
31
|
## 快速开始
|
|
24
32
|
|
|
25
|
-
```
|
|
33
|
+
```js
|
|
26
34
|
// main.ts
|
|
27
35
|
import { createApp } from 'vue'
|
|
28
36
|
import App from './App.vue'
|
|
29
|
-
import
|
|
37
|
+
import vgPrint from 'vg-print'
|
|
30
38
|
import 'vg-print/style.css'
|
|
31
|
-
import 'element-plus/dist/index.css'
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
app.use(HiprintDesigner, { name: '$hiPrint', autoConnect: true })
|
|
35
|
-
app.mount('#app')
|
|
40
|
+
createApp(App).use(vgPrint).mount('#app')
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
```vue
|
|
39
44
|
<template>
|
|
40
|
-
<
|
|
41
|
-
:template="template"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<DragBox target="SVPrint" drag-key="test" drag-style="width:200px;height:200px;left:238px;top:95px" :show="true">
|
|
54
|
-
<template #iconTitle>
|
|
55
|
-
<i class="svicon sv-print"></i><span>自定义拖拽框</span>
|
|
56
|
-
</template>
|
|
57
|
-
<template #body>
|
|
58
|
-
<div>自定义拖拽框内容</div>
|
|
59
|
-
</template>
|
|
60
|
-
</DragBox>
|
|
61
|
-
</template>
|
|
62
|
-
</Designer>
|
|
63
|
-
|
|
64
|
-
<Preview ref="previewRef" :modalShow="false" />
|
|
45
|
+
<div style="width: 100vw; height: 97vh;">
|
|
46
|
+
<Designer :template="template" :printData="printData" :config="config" :plugins="plugins" @ready="onReady">
|
|
47
|
+
<template #header>
|
|
48
|
+
<Header title="打印设计器" />
|
|
49
|
+
</template>
|
|
50
|
+
<template #other>
|
|
51
|
+
<DragBox target="SVPrint" drag-key="demo" drag-style="width:200px;height:200px;left:238px;top:95px" :show="true" />
|
|
52
|
+
</template>
|
|
53
|
+
</Designer>
|
|
54
|
+
|
|
55
|
+
<Preview ref="previewRef" />
|
|
56
|
+
<el-button @click="showPreview">显示预览</el-button>
|
|
57
|
+
</div>
|
|
65
58
|
</template>
|
|
59
|
+
|
|
66
60
|
<script setup>
|
|
67
61
|
import { ref } from 'vue'
|
|
68
|
-
import {
|
|
69
|
-
import { Designer, Header, Preview, DragBox } from 'vg-print'
|
|
62
|
+
import { hiprint } from 'vue-plugin-hiprint'
|
|
70
63
|
|
|
71
64
|
const template = ref({})
|
|
65
|
+
const printData = ref({ name: '示例' })
|
|
66
|
+
const config = ref({ showAdsorbLine: true, showPosition: true, showSizeBox: true })
|
|
67
|
+
const plugins = ref([])
|
|
72
68
|
const previewRef = ref(null)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
previewRef.value.init(tpl, { name: 'i不简' })
|
|
69
|
+
|
|
70
|
+
const onReady = (tpl) => {}
|
|
71
|
+
const showPreview = () => {
|
|
72
|
+
const tpl = new hiprint.PrintTemplate({ template: template.value })
|
|
73
|
+
previewRef.value.init(tpl, printData.value)
|
|
79
74
|
previewRef.value.show()
|
|
80
75
|
}
|
|
81
|
-
|
|
82
|
-
const providers = [new defaultElementTypeProvider()]
|
|
83
|
-
const plugins = []
|
|
84
76
|
</script>
|
|
85
77
|
```
|
|
86
78
|
|
|
87
|
-
##
|
|
79
|
+
## 组件概览
|
|
88
80
|
|
|
89
81
|
### Designer
|
|
90
82
|
|
|
91
|
-
- `template` object 模板 json
|
|
92
|
-
- `printData` object
|
|
93
|
-
- `templateKey` string
|
|
94
|
-
- `title` string
|
|
95
|
-
- `designOptions` object
|
|
96
|
-
- `paperList`
|
|
97
|
-
- `config` object
|
|
98
|
-
- `plugins` object[]
|
|
99
|
-
- `authKey` string
|
|
100
|
-
- `
|
|
101
|
-
- `
|
|
102
|
-
|
|
103
|
-
事件与插槽:
|
|
104
|
-
|
|
105
|
-
- 事件:`onDesigned({ detail: { hiprint, designerUtils } })`,其中 `designerUtils.printTemplate` 为当前模板实例
|
|
106
|
-
- 插槽:`#header` 顶部区域;`#other` 其他扩展区域
|
|
83
|
+
- `template` object 模板 json 或模板对象,默认 `{}`
|
|
84
|
+
- `printData` object 打印数据,默认 `{}`
|
|
85
|
+
- `templateKey` string 本地缓存键,默认 `default-template`
|
|
86
|
+
- `title` string 默认导出文件名,默认 `默认模板.json`
|
|
87
|
+
- `designOptions` object 设计参数,如 `{ grid: true, activePanel: true }`
|
|
88
|
+
- `paperList` array 可选纸张列表
|
|
89
|
+
- `config` object `hiprint.setConfig` 参数,需在渲染前设置
|
|
90
|
+
- `plugins` object[] 插件数组,`hiprint.register({ authKey, plugins })`
|
|
91
|
+
- `authKey` string 插件授权 key
|
|
92
|
+
- 事件:`ready(hiprintTemplate)`
|
|
93
|
+
- 插槽:`header`、`other`
|
|
107
94
|
|
|
108
95
|
### Header
|
|
109
96
|
|
|
110
|
-
- `logoHtml` string 左侧 logo
|
|
111
|
-
- `title` string
|
|
112
|
-
- `
|
|
113
|
-
- `
|
|
114
|
-
- `
|
|
115
|
-
- `menuList` string[] 菜单列表
|
|
116
|
-
- `onPreviewClick(e): boolean` 预览点击;返回 `true` 阻止默认行为
|
|
117
|
-
|
|
118
|
-
插槽:`#headerLeft`、`#headerCenter`、`#headerRight`
|
|
97
|
+
- `logoHtml` string 左侧 logo HTML,默认 `<i class="svp-header-logo svicon sv-print"></i>`
|
|
98
|
+
- `title` string 左侧标题,默认 `sv-print`
|
|
99
|
+
- `onPreviewClick: (e) => boolean` 返回 `true` 阻止默认行为
|
|
100
|
+
- 事件:`preview`
|
|
101
|
+
- 插槽:`headerLeft`、`headerCenter`、`headerRight`
|
|
119
102
|
|
|
120
103
|
### Preview
|
|
121
104
|
|
|
122
|
-
- `printTemplate`
|
|
123
|
-
- `printData`
|
|
105
|
+
- `printTemplate` object 模板对象(`hiprint.PrintTemplate`)
|
|
106
|
+
- `printData` object 打印数据
|
|
124
107
|
- `printerList` array 打印机列表
|
|
125
|
-
- `selectedPrinter` string
|
|
126
|
-
- `showPdf` boolean
|
|
127
|
-
- `
|
|
128
|
-
- `
|
|
129
|
-
- `modalShow` boolean 是否显示
|
|
130
|
-
|
|
131
|
-
方法:`getTarget()`、`init(tpl, data)`、`show()`、`print()`、`toPdf()`、`toImage(options)`、`directPrint()`
|
|
108
|
+
- `selectedPrinter` string 默认选中打印机名称,支持 `v-model:selectedPrinter`
|
|
109
|
+
- `showPdf`/`showImg`/`showPrint2` boolean 控制按钮
|
|
110
|
+
- `modalShow` boolean 控制显示
|
|
111
|
+
- 方法:`init(template, data)`、`getTarget()`、`show()`
|
|
132
112
|
|
|
133
113
|
### DragBox
|
|
134
114
|
|
|
135
115
|
- `target` string 容器 Id 或 ClassName
|
|
136
116
|
- `dragKey` string 拖拽标识
|
|
137
|
-
- `dragStyle` string
|
|
138
|
-
- `mode` string `default|top|left|bottom|right|fixed`
|
|
117
|
+
- `dragStyle` string 初始位置与大小,如 `width:200px;height:200px;left:238px;top:95px`
|
|
118
|
+
- `mode` string `default | top | left | bottom | right | fixed`
|
|
139
119
|
- `show` boolean 是否显示
|
|
120
|
+
- 插槽:`iconTitle`、`body`
|
|
140
121
|
|
|
141
|
-
|
|
122
|
+
## 与 hiprint 的集成
|
|
142
123
|
|
|
143
|
-
|
|
124
|
+
初始化与配置:
|
|
144
125
|
|
|
145
|
-
|
|
126
|
+
```js
|
|
127
|
+
import { hiprint, defaultElementTypeProvider } from 'vue-plugin-hiprint'
|
|
146
128
|
|
|
147
|
-
|
|
148
|
-
|
|
129
|
+
hiprint.setConfig({ showAdsorbLine: true, showPosition: true, showSizeBox: true })
|
|
130
|
+
hiprint.register({ authKey: '', plugins: [] })
|
|
131
|
+
hiprint.init({ providers: [new defaultElementTypeProvider()] })
|
|
149
132
|
```
|
|
150
133
|
|
|
151
|
-
|
|
152
|
-
import { hiprint } from 'vg-print'
|
|
153
|
-
import pluginEleBwip from '@sv-print/plugin-ele-bwip-js'
|
|
134
|
+
渲染与打印:
|
|
154
135
|
|
|
155
|
-
|
|
136
|
+
```js
|
|
137
|
+
const tpl = new hiprint.PrintTemplate({ template: {} })
|
|
138
|
+
tpl.design('#hiprint-printTemplate', { grid: true })
|
|
139
|
+
tpl.print({ name: '示例' })
|
|
140
|
+
tpl.print2({ name: '示例' }, { printer: '' })
|
|
141
|
+
tpl.toPdf({ name: '示例' }, '打印预览pdf', { paperWidth: 210, paperHeight: 297, scale: 2, perPage: 6 })
|
|
142
|
+
tpl.toImage({ name: '示例' }, { isDownload: true, name: '图片', limit: 1, type: 'image/jpeg', pixelRatio: 2 })
|
|
156
143
|
```
|
|
157
144
|
|
|
158
|
-
|
|
145
|
+
## 完整示例(预览组件)
|
|
159
146
|
|
|
160
147
|
```vue
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
<template>
|
|
149
|
+
<Preview ref="previewRef" :showPdf="true" :showImg="true" :showPrint2="true" v-model:selectedPrinter="selected" />
|
|
150
|
+
<el-button @click="open">预览</el-button>
|
|
151
|
+
</template>
|
|
165
152
|
|
|
166
|
-
|
|
167
|
-
import {
|
|
153
|
+
<script setup>
|
|
154
|
+
import { ref } from 'vue'
|
|
155
|
+
import { hiprint } from 'vue-plugin-hiprint'
|
|
168
156
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
showPosition: true,
|
|
172
|
-
showSizeBox: true,
|
|
173
|
-
})
|
|
174
|
-
```
|
|
157
|
+
const selected = ref('')
|
|
158
|
+
const previewRef = ref(null)
|
|
175
159
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const provider = function(options) {
|
|
182
|
-
const addElementTypes = function(context) {
|
|
183
|
-
context.removePrintElementTypes('ibujianModule')
|
|
184
|
-
context.addPrintElementTypes('ibujianModule', [
|
|
185
|
-
new hiprint.PrintElementTypeGroup('i不简', [
|
|
186
|
-
{
|
|
187
|
-
tid: 'ibujianModule.text',
|
|
188
|
-
type: 'text',
|
|
189
|
-
title: '文本',
|
|
190
|
-
options: { title: '文本2', field: 'text', testData: '123' }
|
|
191
|
-
}
|
|
192
|
-
])
|
|
193
|
-
])
|
|
194
|
-
}
|
|
195
|
-
return { addElementTypes }
|
|
160
|
+
const open = () => {
|
|
161
|
+
const template = new hiprint.PrintTemplate({ template: {} })
|
|
162
|
+
previewRef.value.init(template, { name: '示例' })
|
|
163
|
+
previewRef.value.show()
|
|
196
164
|
}
|
|
197
|
-
|
|
198
|
-
// 传入 Designer
|
|
199
|
-
<Designer :providers="[provider]" :providerMap="{ container: '.hiprintEpContainer', value: 'ibujianModule' }" />
|
|
165
|
+
</script>
|
|
200
166
|
```
|
|
201
167
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
const providerMap = {
|
|
206
|
-
container: '.hiprintEpContainer',
|
|
207
|
-
value: 'defaultModule',
|
|
208
|
-
render: (list) => {
|
|
209
|
-
const $ = globalThis.$
|
|
210
|
-
const container = $('<div class="hiprint-printElement-type"></div>')
|
|
211
|
-
list.forEach(function(item) {
|
|
212
|
-
const box = $(`<div class="draggable-ele-group"><span class="title">${ item.name }</span><div class="list"></div></div>`)
|
|
213
|
-
const typeList = box.find('.list')
|
|
214
|
-
item.printElementTypes.forEach(function(t) {
|
|
215
|
-
typeList.append(`<div class="draggable-ele" draggable="true" data-tid="${t.tid}">${t.title}</div>`)
|
|
216
|
-
})
|
|
217
|
-
container.append(box)
|
|
218
|
-
})
|
|
219
|
-
$(providerMap.container).empty().append(container)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
```
|
|
168
|
+
## 构建与发布
|
|
223
169
|
|
|
224
|
-
|
|
170
|
+
打包组件库:
|
|
225
171
|
|
|
226
|
-
|
|
172
|
+
```
|
|
173
|
+
npm run build:lib
|
|
174
|
+
```
|
|
227
175
|
|
|
228
|
-
|
|
229
|
-
- 浏览器打印:`this.$print(provider, templateJson, printData, options)`
|
|
230
|
-
- 直接打印:`this.$print2(provider, templateJson, printData, options)`(需客户端)
|
|
231
|
-
- 连接控制:`autoConnect(cb)` / `disAutoConnect()`
|
|
176
|
+
产物会生成到 `dist/`:`vg-print-designer.es.js`、`vg-print-designer.umd.js`。
|
|
232
177
|
|
|
233
|
-
|
|
178
|
+
发布到 npm:
|
|
234
179
|
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
|
|
180
|
+
```
|
|
181
|
+
npm login
|
|
182
|
+
npm publish
|
|
238
183
|
```
|
|
239
184
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
```ts
|
|
243
|
-
const clientId = 'AlBaUCNs3AIMFPLZAAAh'
|
|
244
|
-
const client = this.$hiPrint.hiwebSocket.clients[clientId]
|
|
245
|
-
const printer = client.printerList[0]
|
|
185
|
+
如包名冲突,请在 `package.json` 中修改为未占用的名称。
|
|
246
186
|
|
|
247
|
-
|
|
248
|
-
client: clientId,
|
|
249
|
-
printer: printer.name,
|
|
250
|
-
title: '打印预览'
|
|
251
|
-
})
|
|
252
|
-
```
|
|
187
|
+
## 注意事项
|
|
253
188
|
|
|
254
|
-
|
|
189
|
+
- 必须在 `index.html` 注入 `print-lock.css`,保证打印样式稳定
|
|
190
|
+
- 直接打印需配套客户端,跨域部署需启用 HTTPS
|
|
191
|
+
- 建议在渲染前调用 `hiprint.setConfig` 配置设计器显示选项
|
|
255
192
|
|
|
256
|
-
|
|
257
|
-
const tpl = new this.$hiPrint.PrintTemplate({ template: templateJson })
|
|
258
|
-
tpl.toPdf({ name: 'i不简' }, '导出PDF')
|
|
259
|
-
await tpl.toImage({ name: 'i不简' }, { isDownload: true, type: 'image/jpeg', pixelRatio: 2 })
|
|
260
|
-
```
|
|
193
|
+
## 源码位置
|
|
261
194
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
- 必须引入 `print-lock.css`,否则浏览器打印样式会错乱
|
|
265
|
-
- 直接打印需安装并连接 `electron-hiprint` 客户端,线上使用需 `https` 以避免跨域连接失败
|
|
266
|
-
- 模板资源(图片等)建议使用绝对可访问链接或 Base64
|
|
267
|
-
- 纸张列表可参考 A/B 系列(来自 sv-print 文档)
|
|
268
|
-
- 可通过 `hiprint.setConfig` 与组件插槽定制 UI/交互
|
|
269
|
-
- 报错 `defaultElementTypeProvider(...) is not a constructor`:请使用 `new defaultElementTypeProvider()`,不要先调用再 `new`
|
|
270
|
-
- 导入样式 `import 'vg-print/style.css'` 报错:确认包已构建且 `node_modules/vg-print/dist/style.css` 存在;若从本地/仓库直接安装,先执行 `npm run build:lib` 或依赖包的 `prepare`
|
|
271
|
-
- WebSocket `TransportError`:这是自动连接打印客户端失败的提示;如不使用客户端,安装时传入 `{ autoConnect: false }` 或在运行期调用 `disAutoConnect()`
|
|
272
|
-
- 无样式/不可拖拽:请确保在应用入口已 `import 'vg-print/style.css'`,且安装了 `jquery` 依赖;如果使用 `pnpm`,也要确认 `jquery` 没被去重导致未被实际安装
|
|
273
|
-
- 组件按钮/弹窗无样式:请在入口额外引入 Element Plus 样式 `import 'element-plus/dist/index.css'`
|
|
274
|
-
|
|
275
|
-
## 打包与发布
|
|
276
|
-
|
|
277
|
-
- 运行库打包:`npm run build:lib`,产物:`dist/hiprint-designer.es.js`、`dist/hiprint-designer.umd.js`、`dist/style.css`
|
|
278
|
-
- `package.json` 已配置 `main/module/exports` 指向库产物
|
|
279
|
-
- 首次发布:`npm config set registry=https://registry.npmjs.org`、`npm adduser`、`npm publish`
|
|
280
|
-
|
|
281
|
-
## 代码位置索引
|
|
282
|
-
|
|
283
|
-
- 组件安装入口:`src/lib/index.js:9`
|
|
284
|
-
- 全局插件与方法:`src/index.js:34`
|
|
285
|
-
- 设计器:`src/components/Designer.vue:16`
|
|
286
|
-
- 预览:`src/components/Preview.vue:1`
|
|
287
|
-
- 头部:`src/components/Header.vue:1`
|
|
288
|
-
- 拖拽盒:`src/components/DragBox.vue:1`
|
|
195
|
+
- 入口与导出:`packages/index.ts`
|
|
196
|
+
- 组件:`packages/components/Designer.vue`、`packages/components/Header.vue`、`packages/components/Preview.vue`、`packages/components/DragBox.vue`
|