vg-print 1.0.213 → 1.0.215
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 +81 -124
- package/dist/index.html +15 -0
- package/dist/static/css/index-CHrdN67h.css +1 -0
- package/dist/static/eot/iconfont-B29x-Pv4.eot +0 -0
- package/dist/static/js/index-o25as6Wf.js +2180 -0
- package/dist/static/js/purify.es-C_uT9hQ1.js +3 -0
- package/dist/static/png/jquery.minicolors-DuhFDKu9.png +0 -0
- package/dist/static/svg/iconfont-CM4zkCXp.svg +203 -0
- package/dist/static/svg/l_img-CfaYkjcP.svg +1 -0
- package/dist/static/svg/v_img-DRoQiI_w.svg +1 -0
- package/dist/static/ttf/iconfont-Cv2qGaA6.ttf +0 -0
- package/dist/static/woff/iconfont-BeWPCfhO.woff +0 -0
- package/package.json +1 -1
- package/dist/purify.es-CKk_t3XZ.js +0 -471
- package/dist/style.css +0 -1
- package/dist/vg-print.es.js +0 -92441
- package/dist/vg-print.umd.js +0 -5165
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# vg-print
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个开箱即用的打印设计器组件库(Vue 3)。现在聚焦于单一组件 `FullDesigner`,同时暴露底层 `hiprint` 能力与客户端直连(`hiwebSocket`)配置,便于快速集成模板设计、预览、浏览器打印、导出 PDF/图片、直接打印等功能。
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- 全功能页面组件 `FullDesigner`,直接使用,无需拼装子组件
|
|
8
|
+
- 支持预览、浏览器打印、导出 PDF/图片、直接打印(需客户端)
|
|
9
|
+
- 通过属性配置 `hiwebSocket` 的 `host`、`token` 与自动连接
|
|
10
|
+
- 暴露实例方法:预览、打印、导出、连接控制等,外部可直接调用
|
|
11
|
+
- 集成并导出 `hiprint`,可进行模板对象级的高级定制
|
|
11
12
|
|
|
12
13
|
## 安装
|
|
13
14
|
|
|
@@ -15,18 +16,18 @@
|
|
|
15
16
|
npm i vg-print
|
|
16
17
|
```
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
样式引入(确保设计与打印样式生效):
|
|
19
20
|
|
|
20
21
|
```
|
|
21
22
|
// 全局样式(组件库样式)
|
|
22
23
|
import 'vg-print/style.css'
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
-
在 `index.html`
|
|
25
|
+
// 打印锁样式(推荐;保证打印时样式稳定)
|
|
26
|
+
// 在 `index.html` 中引入:
|
|
26
27
|
<link rel="stylesheet" type="text/css" media="print" href="https://cdn.jsdelivr.net/npm/vue-plugin-hiprint@latest/dist/print-lock.css" />
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
环境要求:Vue 3、Node >= 18.18。无需单独安装 `vue-plugin-hiprint
|
|
30
|
+
环境要求:Vue 3、Node >= 18.18。无需单独安装 `vue-plugin-hiprint`,本库已内置并导出 `hiprint` 能力。
|
|
30
31
|
|
|
31
32
|
## 快速开始
|
|
32
33
|
|
|
@@ -42,155 +43,111 @@ createApp(App).use(vgPrint).mount('#app')
|
|
|
42
43
|
|
|
43
44
|
```vue
|
|
44
45
|
<template>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
</div>
|
|
46
|
+
<FullDesigner
|
|
47
|
+
ref="designer"
|
|
48
|
+
:hi-host="'http://127.0.0.1:17521'"
|
|
49
|
+
:hi-token="'your-token'"
|
|
50
|
+
:hi-auto-connect="true"
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<el-button @click="preview">预览</el-button>
|
|
54
|
+
<el-button @click="printBrowser">浏览器打印</el-button>
|
|
55
|
+
<el-button @click="exportPdf">导出 PDF</el-button>
|
|
56
|
+
<el-button @click="exportImage">导出图片</el-button>
|
|
57
|
+
<el-button @click="directPrint">直接打印(需客户端)</el-button>
|
|
58
58
|
</template>
|
|
59
59
|
|
|
60
60
|
<script setup>
|
|
61
61
|
import { ref } from 'vue'
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const designer = ref(null)
|
|
63
|
+
|
|
64
|
+
// 预览
|
|
65
|
+
const preview = () => designer.value.preView()
|
|
66
|
+
// 浏览器打印
|
|
67
|
+
const printBrowser = () => designer.value.printView()
|
|
68
|
+
// 直接打印(需客户端已连接)
|
|
69
|
+
const exportPdf = () => designer.value.toPdf()
|
|
70
|
+
// 导出图片
|
|
71
|
+
const exportImage = () => designer.value.toImage()
|
|
72
|
+
// 直接打印(需客户端已连接)
|
|
73
|
+
const directPrint = () => designer.value.print()
|
|
74
|
+
|
|
75
|
+
// 连接控制与参数设置
|
|
76
|
+
const setHostToken = () => designer.value.setHiwebSocket('http://127.0.0.1:17521', 'token')
|
|
77
|
+
// 主动连接客户端
|
|
78
|
+
const connect = () => designer.value.connect()
|
|
79
|
+
// 断开客户端
|
|
80
|
+
const disconnect = () => designer.value.disconnect()
|
|
81
|
+
// 关闭自动连接策略
|
|
82
|
+
const disableAutoConnect = () => designer.value.disAutoConnect()
|
|
76
83
|
</script>
|
|
77
84
|
```
|
|
78
85
|
|
|
79
|
-
##
|
|
86
|
+
## API(FullDesigner)
|
|
80
87
|
|
|
81
|
-
###
|
|
88
|
+
### 属性(Props)
|
|
82
89
|
|
|
83
|
-
- `
|
|
84
|
-
- `
|
|
85
|
-
- `
|
|
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`
|
|
90
|
+
- `hi-host: string` 客户端服务地址(`hiwebSocket.host`),如 `http://127.0.0.1:17521`
|
|
91
|
+
- `hi-token: string` 客户端鉴权令牌(`hiwebSocket.token`)
|
|
92
|
+
- `hi-auto-connect: boolean` 是否自动连接客户端,默认 `true`
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
以上属性支持运行时动态修改,组件内部会监听并应用。
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
- `title` string 左侧标题,默认 `sv-print`
|
|
99
|
-
- `onPreviewClick: (e) => boolean` 返回 `true` 阻止默认行为
|
|
100
|
-
- 事件:`preview`
|
|
101
|
-
- 插槽:`headerLeft`、`headerCenter`、`headerRight`
|
|
96
|
+
### 方法(通过组件 ref 调用)
|
|
102
97
|
|
|
103
|
-
|
|
98
|
+
- `preView()` 打开预览弹窗
|
|
99
|
+
- `printView()` 浏览器打印
|
|
100
|
+
- `print()` 直接打印(需客户端已连接)
|
|
101
|
+
- `toPdf()` 导出为 PDF(内置示例参数)
|
|
102
|
+
- `toImage()` 导出为图片(内置示例参数)
|
|
103
|
+
- `setHiwebSocket(host: string, token?: string, cb?: Function)` 设置客户端地址与令牌并重连
|
|
104
|
+
- `connect(cb?: Function)` 主动连接客户端
|
|
105
|
+
- `disconnect()` 断开客户端
|
|
106
|
+
- `disAutoConnect()` 关闭自动连接策略
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
- `printData` object 打印数据
|
|
107
|
-
- `printerList` array 打印机列表
|
|
108
|
-
- `selectedPrinter` string 默认选中打印机名称,支持 `v-model:selectedPrinter`
|
|
109
|
-
- `showPdf`/`showImg`/`showPrint2` boolean 控制按钮
|
|
110
|
-
- `modalShow` boolean 控制显示
|
|
111
|
-
- 方法:`init(template, data)`、`getTarget()`、`show()`
|
|
108
|
+
## 高级用法(hiprint)
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
- `target` string 容器 Id 或 ClassName
|
|
116
|
-
- `dragKey` string 拖拽标识
|
|
117
|
-
- `dragStyle` string 初始位置与大小,如 `width:200px;height:200px;left:238px;top:95px`
|
|
118
|
-
- `mode` string `default | top | left | bottom | right | fixed`
|
|
119
|
-
- `show` boolean 是否显示
|
|
120
|
-
- 插槽:`iconTitle`、`body`
|
|
121
|
-
|
|
122
|
-
## 与 hiprint 的集成
|
|
123
|
-
|
|
124
|
-
初始化与配置:
|
|
110
|
+
本库导出 `hiprint`,可直接创建与操作模板对象(`hiprint.PrintTemplate`):
|
|
125
111
|
|
|
126
112
|
```js
|
|
127
|
-
import { hiprint, defaultElementTypeProvider } from '
|
|
128
|
-
|
|
113
|
+
import { hiprint, defaultElementTypeProvider } from 'vg-print'
|
|
114
|
+
// 全局配置
|
|
129
115
|
hiprint.setConfig({ showAdsorbLine: true, showPosition: true, showSizeBox: true })
|
|
116
|
+
// 注册插件
|
|
130
117
|
hiprint.register({ authKey: '', plugins: [] })
|
|
118
|
+
// 初始化元素提供器 (默认元素提供器)
|
|
131
119
|
hiprint.init({ providers: [new defaultElementTypeProvider()] })
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
渲染与打印:
|
|
135
|
-
|
|
136
|
-
```js
|
|
120
|
+
// 创建模板对象
|
|
137
121
|
const tpl = new hiprint.PrintTemplate({ template: {} })
|
|
122
|
+
// 设计模板
|
|
138
123
|
tpl.design('#hiprint-printTemplate', { grid: true })
|
|
124
|
+
// 打印(需客户端已连接)
|
|
139
125
|
tpl.print({ name: '示例' })
|
|
126
|
+
// 打印2(需客户端已连接)
|
|
140
127
|
tpl.print2({ name: '示例' }, { printer: '' })
|
|
128
|
+
// 导出 PDF(内置示例参数)
|
|
141
129
|
tpl.toPdf({ name: '示例' }, '打印预览pdf', { paperWidth: 210, paperHeight: 297, scale: 2, perPage: 6 })
|
|
130
|
+
// 导出图片(内置示例参数)
|
|
142
131
|
tpl.toImage({ name: '示例' }, { isDownload: true, name: '图片', limit: 1, type: 'image/jpeg', pixelRatio: 2 })
|
|
143
132
|
```
|
|
144
133
|
|
|
145
|
-
##
|
|
146
|
-
|
|
147
|
-
```vue
|
|
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>
|
|
152
|
-
|
|
153
|
-
<script setup>
|
|
154
|
-
import { ref } from 'vue'
|
|
155
|
-
import { hiprint } from 'vue-plugin-hiprint'
|
|
156
|
-
|
|
157
|
-
const selected = ref('')
|
|
158
|
-
const previewRef = ref(null)
|
|
159
|
-
|
|
160
|
-
const open = () => {
|
|
161
|
-
const template = new hiprint.PrintTemplate({ template: {} })
|
|
162
|
-
previewRef.value.init(template, { name: '示例' })
|
|
163
|
-
previewRef.value.show()
|
|
164
|
-
}
|
|
165
|
-
</script>
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## 构建与发布
|
|
169
|
-
|
|
170
|
-
打包组件库:
|
|
134
|
+
## 注意事项
|
|
171
135
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
136
|
+
- 建议在 `index.html` 注入 `print-lock.css`,保证打印样式稳定
|
|
137
|
+
- 直接打印需配套客户端(Electron 或服务端),跨域部署需启用 HTTPS
|
|
138
|
+
- 若使用自定义 `host/token`,确保客户端配置一致且网络可达
|
|
175
139
|
|
|
176
|
-
|
|
140
|
+
## 构建
|
|
177
141
|
|
|
178
|
-
|
|
142
|
+
开发与构建:
|
|
179
143
|
|
|
180
144
|
```
|
|
181
|
-
npm
|
|
182
|
-
npm
|
|
145
|
+
npm run dev # 开发
|
|
146
|
+
npm run build # 应用构建
|
|
147
|
+
npm run build:lib# 组件库构建
|
|
183
148
|
```
|
|
184
149
|
|
|
185
|
-
如包名冲突,请在 `package.json` 中修改为未占用的名称。
|
|
186
|
-
|
|
187
|
-
## 注意事项
|
|
188
|
-
|
|
189
|
-
- 必须在 `index.html` 注入 `print-lock.css`,保证打印样式稳定
|
|
190
|
-
- 直接打印需配套客户端,跨域部署需启用 HTTPS
|
|
191
|
-
- 建议在渲染前调用 `hiprint.setConfig` 配置设计器显示选项
|
|
192
|
-
|
|
193
150
|
## 源码位置
|
|
194
151
|
|
|
195
152
|
- 入口与导出:`packages/index.ts`
|
|
196
|
-
-
|
|
153
|
+
- 完整页面组件:`src/views/index.vue`
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>vue-plugin-hiprint-demo</title>
|
|
7
|
+
<link rel="icon" href="/favicon.ico" />
|
|
8
|
+
<link rel="stylesheet" type="text/css" media="print" href="/css/print-lock.css" />
|
|
9
|
+
<script type="module" crossorigin src="/static/js/index-o25as6Wf.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/static/css/index-CHrdN67h.css">
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="app"></div>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|