vg-print 1.0.15 → 1.0.17
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 +252 -1
- package/dist/style.css +1 -1
- package/dist/vg-print.cjs.js +558 -201
- package/dist/vg-print.es.js +25691 -20149
- package/dist/vg-print.umd.js +552 -195
- package/package.json +7 -19
package/README.md
CHANGED
|
@@ -1 +1,252 @@
|
|
|
1
|
-
|
|
1
|
+
# 打印设计器插件(Vue3)
|
|
2
|
+
|
|
3
|
+
可视化打印设计器,基于 `hiprint` 封装,支持组件式与函数式调用,提供 `Designer`、`Header`、`Preview`、`DragBox` 组件与常用 API。包名:`vg-print`。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
- 安装依赖:`npm i vg-print`
|
|
8
|
+
- 引入样式:在应用入口引入 `dist/style.css`
|
|
9
|
+
- 注入打印锁样式:调用 `injectPrintLock()`
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { createApp } from 'vue'
|
|
13
|
+
import App from './App.vue'
|
|
14
|
+
import 'vg-print/dist/style.css'
|
|
15
|
+
import { hiPrintPlugin, injectPrintLock } from 'vg-print'
|
|
16
|
+
|
|
17
|
+
const app = createApp(App)
|
|
18
|
+
app.use(hiPrintPlugin)
|
|
19
|
+
injectPrintLock()
|
|
20
|
+
app.mount('#app')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速上手
|
|
24
|
+
|
|
25
|
+
```vue
|
|
26
|
+
<template>
|
|
27
|
+
<Designer :template="template" @onDesigned="onDesigned">
|
|
28
|
+
<template #header>
|
|
29
|
+
<Header title="sv-print" />
|
|
30
|
+
</template>
|
|
31
|
+
</Designer>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script setup>
|
|
35
|
+
import { ref } from 'vue'
|
|
36
|
+
import { Designer, Header } from 'vg-print'
|
|
37
|
+
import templateJson from './template.json'
|
|
38
|
+
|
|
39
|
+
const template = ref(templateJson)
|
|
40
|
+
const onDesigned = (e) => {
|
|
41
|
+
const { hiprint, designerUtils } = e.detail
|
|
42
|
+
const tpl = designerUtils.printTemplate
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 完整示例(含 providers、plugins、Preview、DragBox)
|
|
48
|
+
|
|
49
|
+
```vue
|
|
50
|
+
<template>
|
|
51
|
+
<div style="width: 100vw; height: 97vh;">
|
|
52
|
+
<Designer
|
|
53
|
+
:template="template"
|
|
54
|
+
:printData="printData"
|
|
55
|
+
:providers="providers"
|
|
56
|
+
:providerMap="providerMap"
|
|
57
|
+
:plugins="plugins"
|
|
58
|
+
:designOptions="{ grid: true, activePanel: true }"
|
|
59
|
+
:lang="'cn'"
|
|
60
|
+
authKey=""
|
|
61
|
+
@onDesigned="onDesigned"
|
|
62
|
+
>
|
|
63
|
+
<template #header>
|
|
64
|
+
<Header title="vg-print" :menuList="['预览','导出']" @preview="openPreview" />
|
|
65
|
+
</template>
|
|
66
|
+
<template #other>
|
|
67
|
+
<DragBox target="SVPrint" drag-key="test" drag-style="width:200px;height:200px;left:238px;top:95px" :show="true">
|
|
68
|
+
<template #iconTitle>
|
|
69
|
+
<span>自定义拖拽框</span>
|
|
70
|
+
</template>
|
|
71
|
+
<template #body>
|
|
72
|
+
<div>扩展内容</div>
|
|
73
|
+
</template>
|
|
74
|
+
</DragBox>
|
|
75
|
+
</template>
|
|
76
|
+
</Designer>
|
|
77
|
+
|
|
78
|
+
<Preview ref="previewRef" />
|
|
79
|
+
</div>
|
|
80
|
+
<button @click="openPreview">显示预览</button>
|
|
81
|
+
<button @click="exportPdf">导出PDF</button>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script setup>
|
|
85
|
+
import { ref } from 'vue'
|
|
86
|
+
import { Designer, Header, Preview, DragBox, hiprint } from 'vg-print'
|
|
87
|
+
import provider from './provider.js'
|
|
88
|
+
import templateJson from './template.json'
|
|
89
|
+
|
|
90
|
+
const template = ref(templateJson)
|
|
91
|
+
const printData = ref({ name: '测试' })
|
|
92
|
+
const providers = ref([provider])
|
|
93
|
+
const providerMap = ref({ container: '.hiprintEpContainer', value: 'defaultModule' })
|
|
94
|
+
const plugins = ref([])
|
|
95
|
+
const previewRef = ref(null)
|
|
96
|
+
let tpl = null
|
|
97
|
+
|
|
98
|
+
const onDesigned = (e) => { tpl = e.detail.designerUtils.printTemplate }
|
|
99
|
+
const openPreview = () => { previewRef.value.init(tpl, printData.value); previewRef.value.show() }
|
|
100
|
+
const exportPdf = () => { tpl && tpl.toPdf(printData.value, '导出', {}) }
|
|
101
|
+
</script>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 组件与 API
|
|
105
|
+
|
|
106
|
+
### Designer
|
|
107
|
+
|
|
108
|
+
- 基础参数:
|
|
109
|
+
- `template: object` 模板 json 或模板对象
|
|
110
|
+
- `printData: object` 设计预览数据
|
|
111
|
+
- `designOptions: object` 设计参数,默认 `{ grid: true, activePanel: true }`
|
|
112
|
+
- `providers: array` 自定义可拖拽元素 provider 列表
|
|
113
|
+
- `provider: function` 单 provider 工厂,默认内置 `defaultElementTypeProvider`
|
|
114
|
+
- `providerMap: object` `{ container: '.hiprintEpContainer', value: 'defaultModule' }`
|
|
115
|
+
- `plugins: array` 插件注册列表
|
|
116
|
+
- `authKey: string` 授权 key
|
|
117
|
+
- `lang: string` 语言
|
|
118
|
+
- 事件:
|
|
119
|
+
- `onDesigned(e)` 返回 `{ hiprint, designerUtils }`,包含 `designerUtils.printTemplate`
|
|
120
|
+
- 插槽:
|
|
121
|
+
- `header` 顶部区域
|
|
122
|
+
- `other` 扩展区域
|
|
123
|
+
|
|
124
|
+
示例:
|
|
125
|
+
|
|
126
|
+
```vue
|
|
127
|
+
<Designer :template="template" :plugins="plugins" :providerMap="{ container: '.hiprintEpContainer', value: 'defaultModule' }" @onDesigned="onDesigned" />
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Header
|
|
131
|
+
|
|
132
|
+
- 参数:
|
|
133
|
+
- `logoHtml: string` 左侧 logo html
|
|
134
|
+
- `title: string` 标题
|
|
135
|
+
- `reEle: boolean|string` 是否重建元素
|
|
136
|
+
- `eleList: array` 元素列表
|
|
137
|
+
- `reMenu: boolean|string` 是否重建菜单
|
|
138
|
+
- `menuList: array` 菜单列表
|
|
139
|
+
- `onPreviewClick: function` 预览点击回调,返回 `true` 阻止默认
|
|
140
|
+
- 事件:
|
|
141
|
+
- `preview` 默认预览点击事件
|
|
142
|
+
- 插槽:
|
|
143
|
+
- `headerLeft` 左侧内容
|
|
144
|
+
- `headerCenter` 中间内容
|
|
145
|
+
- `headerRight` 右侧内容
|
|
146
|
+
|
|
147
|
+
### Preview
|
|
148
|
+
|
|
149
|
+
- 参数:
|
|
150
|
+
- `printTemplate: object|string` 模板对象或 json
|
|
151
|
+
- `printData: object` 打印数据
|
|
152
|
+
- `printerList: array` 打印机列表
|
|
153
|
+
- `selectedPrinter: string` 默认打印机
|
|
154
|
+
- `showPdf: boolean` 是否显示导出 PDF 按钮
|
|
155
|
+
- `showImg: boolean` 是否显示导出图片按钮
|
|
156
|
+
- `showPrint2: boolean` 是否显示直接打印按钮
|
|
157
|
+
- `modalShow: boolean` 是否显示
|
|
158
|
+
- 方法:
|
|
159
|
+
- `init(template, data)` 初始化模板与数据
|
|
160
|
+
- `show()` 显示预览并渲染
|
|
161
|
+
- `getTarget()` 返回内部模板对象
|
|
162
|
+
- `print()` 浏览器打印
|
|
163
|
+
- `toPdf()` 导出 PDF
|
|
164
|
+
- `toImage()` 导出图片
|
|
165
|
+
- `directPrint()` 客户端直接打印
|
|
166
|
+
|
|
167
|
+
示例:
|
|
168
|
+
|
|
169
|
+
```vue
|
|
170
|
+
<template>
|
|
171
|
+
<button @click="testPreview">显示预览</button>
|
|
172
|
+
<Preview ref="previewRef" />
|
|
173
|
+
</template>
|
|
174
|
+
<script setup>
|
|
175
|
+
import { ref } from 'vue'
|
|
176
|
+
import { Preview } from 'vg-print'
|
|
177
|
+
import templateJson from './template.json'
|
|
178
|
+
|
|
179
|
+
const previewRef = ref(null)
|
|
180
|
+
const testPreview = () => {
|
|
181
|
+
previewRef.value.init(templateJson, { name: 'i不简' })
|
|
182
|
+
previewRef.value.show()
|
|
183
|
+
}
|
|
184
|
+
</script>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### DragBox
|
|
188
|
+
|
|
189
|
+
- 参数:
|
|
190
|
+
- `target: string` 目标容器 Id 或 ClassName(配合 `Designer` 的 `other` 插槽使用)
|
|
191
|
+
- `dragKey: string` 拖拽标识
|
|
192
|
+
- `dragStyle: string` 初始位置大小,如 `width:200px;height:200px;left:238px;top:95px`
|
|
193
|
+
- `mode: string` `default|top|left|bottom|right|fixed`
|
|
194
|
+
- `show: boolean` 是否显示
|
|
195
|
+
- 插槽:
|
|
196
|
+
- `iconTitle` 头部图标与标题
|
|
197
|
+
- `body` 内容
|
|
198
|
+
|
|
199
|
+
示例:
|
|
200
|
+
|
|
201
|
+
```vue
|
|
202
|
+
<Designer>
|
|
203
|
+
<template #other>
|
|
204
|
+
<DragBox target="SVPrint" drag-key="test" drag-style="width:200px;height:200px;left:238px;top:95px" :show="true">
|
|
205
|
+
<template #iconTitle>
|
|
206
|
+
<span>自定义拖拽框</span>
|
|
207
|
+
</template>
|
|
208
|
+
<template #body>
|
|
209
|
+
<div>内容</div>
|
|
210
|
+
</template>
|
|
211
|
+
</DragBox>
|
|
212
|
+
</template>
|
|
213
|
+
<template #header>
|
|
214
|
+
<Header title="sv-print" />
|
|
215
|
+
</template>
|
|
216
|
+
</Designer>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 函数式 API
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
import { print, print2, defaultElementTypeProvider } from 'vg-print'
|
|
223
|
+
|
|
224
|
+
const tpl = print(defaultElementTypeProvider, templateJson, { data: {} })
|
|
225
|
+
const tpl2 = print2(defaultElementTypeProvider, templateJson, { data: {} })
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## 可拖拽元素 Provider
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
import { hiprint } from 'vg-print'
|
|
232
|
+
|
|
233
|
+
export default function(options){
|
|
234
|
+
var addElementTypes = function(context){
|
|
235
|
+
context.removePrintElementTypes('ibujianModule')
|
|
236
|
+
context.addPrintElementTypes('ibujianModule', [
|
|
237
|
+
new hiprint.PrintElementTypeGroup('i不简',[{
|
|
238
|
+
tid:'ibujianModule.text', type:'text', title:'文本', options:{ title:'文本2', field:'text', testData:'123' }
|
|
239
|
+
}])
|
|
240
|
+
])
|
|
241
|
+
}
|
|
242
|
+
return { addElementTypes }
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
在 `Designer` 中传入 `providers` 或使用 `providerMap` 构建左侧容器。
|
|
247
|
+
|
|
248
|
+
## 注意事项
|
|
249
|
+
|
|
250
|
+
- 需要在入口引入库样式,并调用 `injectPrintLock()` 注入打印锁样式。
|
|
251
|
+
- 依赖 `jquery` 与 `element-plus`;请在应用中安装并初始化 UI 库。
|
|
252
|
+
- 若使用客户端直连打印,请确保客户端组件可用并已连接。
|