vg-print 1.0.219 → 1.0.220
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 +75 -0
- package/dist/style.css +1 -1
- package/dist/vg-print.es.js +29 -25
- package/dist/vg-print.umd.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,3 +198,78 @@ npm run build:lib# 组件库构建
|
|
|
198
198
|
|
|
199
199
|
- 入口与导出:`packages/index.ts`
|
|
200
200
|
- 完整页面组件:`src/views/index.vue`
|
|
201
|
+
## 完整示例
|
|
202
|
+
|
|
203
|
+
```vue
|
|
204
|
+
<template>
|
|
205
|
+
<FullDesigner
|
|
206
|
+
:initial-template="tpl"
|
|
207
|
+
:initial-print-data="rows"
|
|
208
|
+
default-lang="cn"
|
|
209
|
+
:hi-host="host"
|
|
210
|
+
:hi-token="token"
|
|
211
|
+
:hi-auto-connect="true"
|
|
212
|
+
@save="onSave"
|
|
213
|
+
/>
|
|
214
|
+
|
|
215
|
+
<div style="margin-top: 12px;">
|
|
216
|
+
<el-input v-model="host" placeholder="客户端地址,如 http://127.0.0.1:17521" style="width: 360px; margin-right: 8px;" />
|
|
217
|
+
<el-input v-model="token" placeholder="鉴权令牌" style="width: 200px; margin-right: 8px;" />
|
|
218
|
+
<el-button type="primary" @click="applyHostToken">应用连接参数</el-button>
|
|
219
|
+
<el-button style="margin-left:8px;" @click="preview">预览</el-button>
|
|
220
|
+
<el-button style="margin-left:8px;" @click="printBrowser">浏览器打印</el-button>
|
|
221
|
+
</div>
|
|
222
|
+
</template>
|
|
223
|
+
|
|
224
|
+
<script setup>
|
|
225
|
+
import { ref } from 'vue'
|
|
226
|
+
|
|
227
|
+
// 模板(示例)
|
|
228
|
+
const tpl = {
|
|
229
|
+
panels: [
|
|
230
|
+
{
|
|
231
|
+
index: 0,
|
|
232
|
+
paperType: 'A4',
|
|
233
|
+
width: 210,
|
|
234
|
+
height: 297,
|
|
235
|
+
printElements: [
|
|
236
|
+
{
|
|
237
|
+
options: { left: 20, top: 20, title: '标题', field: 'title', fontSize: 18 },
|
|
238
|
+
printElementType: { type: 'text' }
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
options: { left: 20, top: 50, title: '姓名', field: 'name' },
|
|
242
|
+
printElementType: { type: 'text' }
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 数据(对象或数组均可)
|
|
250
|
+
const rows = [{ title: '病理图文报告', name: '东东' }]
|
|
251
|
+
|
|
252
|
+
// 连接参数
|
|
253
|
+
const host = ref('http://127.0.0.1:17521')
|
|
254
|
+
const token = ref('')
|
|
255
|
+
|
|
256
|
+
// 组件引用
|
|
257
|
+
const designer = ref(null)
|
|
258
|
+
|
|
259
|
+
const applyHostToken = () => {
|
|
260
|
+
// 设置客户端地址与令牌,并尝试重连
|
|
261
|
+
designer.value?.setHiwebSocket(host.value, token.value)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 预览与浏览器打印
|
|
265
|
+
const preview = () => designer.value?.preView()
|
|
266
|
+
const printBrowser = () => designer.value?.printView()
|
|
267
|
+
|
|
268
|
+
// 保存事件:拿到模板与数据入库
|
|
269
|
+
const onSave = ({ template, data, templateId }) => {
|
|
270
|
+
// 持久化示例
|
|
271
|
+
// await api.save({ template, data, templateId })
|
|
272
|
+
console.log('save payload:', { template, data, templateId })
|
|
273
|
+
}
|
|
274
|
+
</script>
|
|
275
|
+
```
|