z-certificate-editor 1.0.2 → 1.0.3
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/LICENSE +21 -0
- package/README.md +413 -65
- package/dist/assets/index-CujE4kZ0.js +17 -0
- package/dist/{style.css → assets/index-j3Ih4QMK.css} +1 -1
- package/dist/index.html +13 -0
- package/package.json +18 -18
- package/dist/z-certificate-editor.es.js +0 -1602
- package/dist/z-certificate-editor.umd.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 z-certificate-editor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# z-certificate-editor
|
|
2
2
|
|
|
3
3
|
一个功能强大的基于 Vue 3 的可视化证书编辑器,支持拖拽编辑、系统字段关联、模板管理、图片/二维码处理等功能。
|
|
4
4
|
|
|
5
|
+
## 📦 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install z-certificate-editor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
或使用 yarn:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add z-certificate-editor
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
或使用 pnpm:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add z-certificate-editor
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🚀 快速开始
|
|
24
|
+
|
|
25
|
+
### 基础使用
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<template>
|
|
29
|
+
<CertificateEditor @save="handleSave" />
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup>
|
|
33
|
+
import { CertificateEditor } from 'z-certificate-editor'
|
|
34
|
+
import 'z-certificate-editor/dist/style.css'
|
|
35
|
+
|
|
36
|
+
const handleSave = (certificateData) => {
|
|
37
|
+
console.log('证书配置数据:', certificateData)
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 使用自定义系统字段
|
|
43
|
+
|
|
44
|
+
```vue
|
|
45
|
+
<template>
|
|
46
|
+
<CertificateEditor
|
|
47
|
+
:system-fields="customSystemFields"
|
|
48
|
+
@save="handleSave"
|
|
49
|
+
/>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<script setup>
|
|
53
|
+
import { CertificateEditor, SYSTEM_FIELDS } from 'z-certificate-editor'
|
|
54
|
+
import 'z-certificate-editor/dist/style.css'
|
|
55
|
+
|
|
56
|
+
const customSystemFields = [
|
|
57
|
+
{
|
|
58
|
+
key: 'studentId',
|
|
59
|
+
label: '学号',
|
|
60
|
+
placeholder: '{{学号}}',
|
|
61
|
+
category: '学生信息',
|
|
62
|
+
description: '学生的学号'
|
|
63
|
+
},
|
|
64
|
+
...SYSTEM_FIELDS
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
const handleSave = (certificateData) => {
|
|
68
|
+
console.log('证书配置数据:', certificateData)
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 通过组件引用获取数据
|
|
74
|
+
|
|
75
|
+
```vue
|
|
76
|
+
<template>
|
|
77
|
+
<CertificateEditor
|
|
78
|
+
ref="certificateEditorRef"
|
|
79
|
+
@save="handleSave"
|
|
80
|
+
/>
|
|
81
|
+
<button @click="getCurrentData">获取当前配置</button>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script setup>
|
|
85
|
+
import { ref } from 'vue'
|
|
86
|
+
import { CertificateEditor } from 'z-certificate-editor'
|
|
87
|
+
import 'z-certificate-editor/dist/style.css'
|
|
88
|
+
|
|
89
|
+
const certificateEditorRef = ref(null)
|
|
90
|
+
|
|
91
|
+
const handleSave = (certificateData) => {
|
|
92
|
+
console.log('保存的数据:', certificateData)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const getCurrentData = () => {
|
|
96
|
+
if (certificateEditorRef.value) {
|
|
97
|
+
const data = certificateEditorRef.value.getCertificateData()
|
|
98
|
+
console.log('当前配置:', data)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
</script>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 📖 完整文档
|
|
105
|
+
|
|
106
|
+
以下是完整的项目文档和使用说明。
|
|
107
|
+
|
|
5
108
|
## ✨ 功能特性
|
|
6
109
|
|
|
7
110
|
### 核心功能
|
|
@@ -11,6 +114,7 @@
|
|
|
11
114
|
- 🖼️ **图片元素**: 支持本地上传、URL输入、关联系统字段(如用户头像)
|
|
12
115
|
- 🔲 **二维码元素**: 支持文本内容、URL输入、关联系统字段(如证书编号、身份证号)
|
|
13
116
|
- 🎯 **系统字段关联**: 动态关联系统字段,实现证书内容的自动化填充
|
|
117
|
+
- ⚙️ **自定义系统字段**: 支持通过 props 传入自定义系统字段配置,灵活适配不同业务场景
|
|
14
118
|
- 📐 **精确定位**: 支持精确的位置(X、Y)和尺寸(宽度、高度)设置
|
|
15
119
|
- 🎨 **丰富的文本格式**: 字体大小、字体族、粗体、斜体、下划线、颜色、对齐方式、行高等
|
|
16
120
|
|
|
@@ -60,95 +164,98 @@ drawcert/
|
|
|
60
164
|
└── README.md
|
|
61
165
|
```
|
|
62
166
|
|
|
63
|
-
##
|
|
167
|
+
## 🚀 安装和运行
|
|
64
168
|
|
|
65
|
-
###
|
|
169
|
+
### 环境要求
|
|
170
|
+
|
|
171
|
+
- Node.js >= 22.21.0
|
|
172
|
+
- npm >= 11.6.2
|
|
173
|
+
|
|
174
|
+
### 安装依赖
|
|
66
175
|
|
|
67
176
|
```bash
|
|
68
|
-
npm install
|
|
177
|
+
npm install
|
|
69
178
|
```
|
|
70
179
|
|
|
71
|
-
###
|
|
72
|
-
|
|
73
|
-
```vue
|
|
74
|
-
<template>
|
|
75
|
-
<CertificateEditor />
|
|
76
|
-
</template>
|
|
180
|
+
### 开发模式
|
|
77
181
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
import 'z-certificate-editor/style.css'
|
|
81
|
-
</script>
|
|
182
|
+
```bash
|
|
183
|
+
npm run dev
|
|
82
184
|
```
|
|
83
185
|
|
|
84
|
-
|
|
186
|
+
启动后访问 `http://localhost:3000`(或终端显示的地址)
|
|
85
187
|
|
|
86
|
-
|
|
87
|
-
<template>
|
|
88
|
-
<div>
|
|
89
|
-
<DesignPanel @add-element="handleAddElement" />
|
|
90
|
-
<CanvasArea :elements="elements" />
|
|
91
|
-
<PropertiesPanel :element="selectedElement" />
|
|
92
|
-
</div>
|
|
93
|
-
</template>
|
|
188
|
+
### 构建生产版本
|
|
94
189
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
DesignPanel,
|
|
98
|
-
CanvasArea,
|
|
99
|
-
PropertiesPanel
|
|
100
|
-
} from 'z-certificate-editor'
|
|
101
|
-
import 'z-certificate-editor/style.css'
|
|
102
|
-
</script>
|
|
190
|
+
```bash
|
|
191
|
+
npm run build
|
|
103
192
|
```
|
|
104
193
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```javascript
|
|
108
|
-
import {
|
|
109
|
-
SYSTEM_FIELDS,
|
|
110
|
-
replaceFields,
|
|
111
|
-
extractFields,
|
|
112
|
-
PRESET_TEMPLATES
|
|
113
|
-
} from 'z-certificate-editor'
|
|
194
|
+
构建产物将输出到 `dist` 目录
|
|
114
195
|
|
|
115
|
-
|
|
116
|
-
console.log(SYSTEM_FIELDS)
|
|
196
|
+
### 预览生产版本
|
|
117
197
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const fieldData = { name: '张三', gender: '先生' }
|
|
121
|
-
const result = replaceFields(text, fieldData)
|
|
122
|
-
// 结果: '张三(先生)'
|
|
123
|
-
|
|
124
|
-
// 提取字段
|
|
125
|
-
const fields = extractFields(text)
|
|
126
|
-
// 结果: [{ key: 'name', label: '姓名', ... }, { key: 'gender', label: '性别称呼', ... }]
|
|
198
|
+
```bash
|
|
199
|
+
npm run preview
|
|
127
200
|
```
|
|
128
201
|
|
|
129
|
-
##
|
|
202
|
+
## 📖 使用说明
|
|
130
203
|
|
|
131
|
-
###
|
|
204
|
+
### 自定义系统字段
|
|
132
205
|
|
|
133
|
-
|
|
134
|
-
- npm >= 11.6.2
|
|
206
|
+
`CertificateEditor` 组件支持通过 `systemFields` prop 传入自定义系统字段配置,实现灵活的字段管理。
|
|
135
207
|
|
|
136
|
-
|
|
208
|
+
#### 在 App.vue 中使用
|
|
137
209
|
|
|
138
|
-
```
|
|
139
|
-
|
|
210
|
+
```vue
|
|
211
|
+
<template>
|
|
212
|
+
<CertificateEditor :system-fields="customSystemFields" />
|
|
213
|
+
</template>
|
|
214
|
+
|
|
215
|
+
<script setup>
|
|
216
|
+
import { ref } from 'vue'
|
|
217
|
+
import CertificateEditor from './components/CertificateEditor.vue'
|
|
218
|
+
import { SYSTEM_FIELDS } from './utils/fieldManager.js'
|
|
219
|
+
|
|
220
|
+
// 定义自定义系统字段
|
|
221
|
+
const customSystemFields = ref([
|
|
222
|
+
// 添加自定义字段
|
|
223
|
+
{
|
|
224
|
+
key: 'studentId',
|
|
225
|
+
label: '学号',
|
|
226
|
+
placeholder: '{{学号}}',
|
|
227
|
+
category: '学生信息',
|
|
228
|
+
description: '学生的学号'
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
key: 'className',
|
|
232
|
+
label: '班级名称',
|
|
233
|
+
placeholder: '{{班级名称}}',
|
|
234
|
+
category: '学生信息',
|
|
235
|
+
description: '学生所在班级'
|
|
236
|
+
},
|
|
237
|
+
// 保留默认字段
|
|
238
|
+
...SYSTEM_FIELDS
|
|
239
|
+
])
|
|
240
|
+
</script>
|
|
140
241
|
```
|
|
141
242
|
|
|
142
|
-
|
|
243
|
+
#### 字段对象格式
|
|
143
244
|
|
|
144
|
-
|
|
145
|
-
npm run dev
|
|
146
|
-
```
|
|
245
|
+
每个系统字段对象必须包含以下属性:
|
|
147
246
|
|
|
148
|
-
|
|
247
|
+
- `key` (String, 必需): 字段的唯一标识符,用于在代码中引用
|
|
248
|
+
- `label` (String, 必需): 字段的显示名称,显示在界面上
|
|
249
|
+
- `placeholder` (String, 必需): 字段的占位符格式,如 `{{姓名}}`
|
|
250
|
+
- `category` (String, 可选): 字段的分类,用于分组显示
|
|
251
|
+
- `description` (String, 可选): 字段的描述信息
|
|
149
252
|
|
|
253
|
+
#### 注意事项
|
|
150
254
|
|
|
151
|
-
|
|
255
|
+
- 如果不传入 `systemFields` prop,组件将使用默认的 `SYSTEM_FIELDS`
|
|
256
|
+
- 自定义字段的 `key` 必须唯一,避免与默认字段冲突
|
|
257
|
+
- 字段的 `placeholder` 格式必须为 `{{字段名}}` 的形式
|
|
258
|
+
- 自定义字段会自动在字段选择对话框、属性面板等位置显示
|
|
152
259
|
|
|
153
260
|
### 基本操作流程
|
|
154
261
|
|
|
@@ -284,7 +391,8 @@ npm run dev
|
|
|
284
391
|
|
|
285
392
|
- 点击顶部工具栏的"保存"按钮
|
|
286
393
|
- 系统会将当前证书配置(模板、元素列表、字段数据)输出到浏览器控制台
|
|
287
|
-
-
|
|
394
|
+
- 同时触发 `save` 事件,将数据传递给父组件
|
|
395
|
+
- 父组件可以通过事件处理函数接收保存的数据
|
|
288
396
|
|
|
289
397
|
**保存的数据结构**:
|
|
290
398
|
```json
|
|
@@ -317,6 +425,113 @@ npm run dev
|
|
|
317
425
|
}
|
|
318
426
|
```
|
|
319
427
|
|
|
428
|
+
#### 在父组件中获取保存的数据
|
|
429
|
+
|
|
430
|
+
有两种方式可以在父组件中获取证书配置数据:
|
|
431
|
+
|
|
432
|
+
**方式一:通过事件监听(推荐)**
|
|
433
|
+
|
|
434
|
+
当用户点击保存按钮时,组件会触发 `save` 事件,父组件可以通过监听该事件获取数据:
|
|
435
|
+
|
|
436
|
+
```vue
|
|
437
|
+
<template>
|
|
438
|
+
<CertificateEditor
|
|
439
|
+
:system-fields="customSystemFields"
|
|
440
|
+
@save="handleSave"
|
|
441
|
+
/>
|
|
442
|
+
</template>
|
|
443
|
+
|
|
444
|
+
<script setup>
|
|
445
|
+
import { ref } from 'vue'
|
|
446
|
+
import CertificateEditor from './components/CertificateEditor.vue'
|
|
447
|
+
|
|
448
|
+
const handleSave = (certificateData) => {
|
|
449
|
+
console.log('接收到保存的数据:', certificateData)
|
|
450
|
+
|
|
451
|
+
// 在这里可以处理保存的数据,例如:
|
|
452
|
+
// - 发送到服务器
|
|
453
|
+
// - 保存到本地存储
|
|
454
|
+
// - 进行数据验证
|
|
455
|
+
// 等等...
|
|
456
|
+
}
|
|
457
|
+
</script>
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**方式二:通过组件方法主动获取**
|
|
461
|
+
|
|
462
|
+
父组件可以通过组件引用调用 `getCertificateData()` 方法,随时获取当前的证书配置数据(无需点击保存按钮):
|
|
463
|
+
|
|
464
|
+
```vue
|
|
465
|
+
<template>
|
|
466
|
+
<CertificateEditor
|
|
467
|
+
ref="certificateEditorRef"
|
|
468
|
+
:system-fields="customSystemFields"
|
|
469
|
+
/>
|
|
470
|
+
<button @click="getData">获取当前配置</button>
|
|
471
|
+
</template>
|
|
472
|
+
|
|
473
|
+
<script setup>
|
|
474
|
+
import { ref } from 'vue'
|
|
475
|
+
import CertificateEditor from './components/CertificateEditor.vue'
|
|
476
|
+
|
|
477
|
+
const certificateEditorRef = ref(null)
|
|
478
|
+
|
|
479
|
+
const getData = () => {
|
|
480
|
+
if (certificateEditorRef.value) {
|
|
481
|
+
const data = certificateEditorRef.value.getCertificateData()
|
|
482
|
+
console.log('当前证书配置:', data)
|
|
483
|
+
// 处理数据...
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
</script>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**完整示例**:
|
|
490
|
+
|
|
491
|
+
```vue
|
|
492
|
+
<template>
|
|
493
|
+
<CertificateEditor
|
|
494
|
+
ref="certificateEditorRef"
|
|
495
|
+
:system-fields="customSystemFields"
|
|
496
|
+
@save="handleSave"
|
|
497
|
+
/>
|
|
498
|
+
<button @click="getCurrentData">获取当前配置</button>
|
|
499
|
+
</template>
|
|
500
|
+
|
|
501
|
+
<script setup>
|
|
502
|
+
import { ref } from 'vue'
|
|
503
|
+
import CertificateEditor from './components/CertificateEditor.vue'
|
|
504
|
+
import { SYSTEM_FIELDS } from './utils/fieldManager.js'
|
|
505
|
+
|
|
506
|
+
const customSystemFields = ref([...SYSTEM_FIELDS])
|
|
507
|
+
const certificateEditorRef = ref(null)
|
|
508
|
+
|
|
509
|
+
// 方式一:监听保存事件
|
|
510
|
+
const handleSave = (certificateData) => {
|
|
511
|
+
console.log('用户点击保存,数据:', certificateData)
|
|
512
|
+
|
|
513
|
+
// 示例:保存到本地存储
|
|
514
|
+
localStorage.setItem('certificateConfig', JSON.stringify(certificateData))
|
|
515
|
+
|
|
516
|
+
// 示例:发送到服务器
|
|
517
|
+
// fetch('/api/certificate/save', {
|
|
518
|
+
// method: 'POST',
|
|
519
|
+
// headers: { 'Content-Type': 'application/json' },
|
|
520
|
+
// body: JSON.stringify(certificateData)
|
|
521
|
+
// })
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// 方式二:主动获取数据
|
|
525
|
+
const getCurrentData = () => {
|
|
526
|
+
if (certificateEditorRef.value) {
|
|
527
|
+
const data = certificateEditorRef.value.getCertificateData()
|
|
528
|
+
console.log('当前配置数据:', data)
|
|
529
|
+
return data
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
</script>
|
|
533
|
+
```
|
|
534
|
+
|
|
320
535
|
## 🧩 组件说明
|
|
321
536
|
|
|
322
537
|
### CertificateEditor
|
|
@@ -328,6 +543,43 @@ npm run dev
|
|
|
328
543
|
- 协调各子组件的通信
|
|
329
544
|
- 提供预览和保存功能
|
|
330
545
|
|
|
546
|
+
**Props**:
|
|
547
|
+
- `systemFields` (Array, 可选): 自定义系统字段配置数组
|
|
548
|
+
- 如果不传入,将使用默认的 `SYSTEM_FIELDS`
|
|
549
|
+
- 字段对象格式:
|
|
550
|
+
```javascript
|
|
551
|
+
{
|
|
552
|
+
key: '字段唯一标识',
|
|
553
|
+
label: '字段显示名称',
|
|
554
|
+
placeholder: '{{占位符}}',
|
|
555
|
+
category: '字段分类',
|
|
556
|
+
description: '字段描述'
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
- 示例:
|
|
560
|
+
```javascript
|
|
561
|
+
const customFields = [
|
|
562
|
+
{
|
|
563
|
+
key: 'customField',
|
|
564
|
+
label: '自定义字段',
|
|
565
|
+
placeholder: '{{自定义字段}}',
|
|
566
|
+
category: '其他',
|
|
567
|
+
description: '这是一个自定义字段'
|
|
568
|
+
},
|
|
569
|
+
...SYSTEM_FIELDS // 可以结合默认字段使用
|
|
570
|
+
]
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
**Events**:
|
|
574
|
+
- `save`: 当用户点击保存按钮时触发
|
|
575
|
+
- 参数:`certificateData` (Object) - 证书配置数据对象
|
|
576
|
+
- 数据结构包含:`template`、`elements`、`fieldData`、`timestamp`
|
|
577
|
+
|
|
578
|
+
**Exposed Methods**:
|
|
579
|
+
- `getCertificateData()`: 获取当前证书配置数据
|
|
580
|
+
- 返回:`Object` - 证书配置数据对象
|
|
581
|
+
- 使用方式:通过组件引用调用 `certificateEditorRef.value.getCertificateData()`
|
|
582
|
+
|
|
331
583
|
### DesignPanel
|
|
332
584
|
|
|
333
585
|
左侧设计面板,提供元素添加和模板管理功能。
|
|
@@ -357,6 +609,7 @@ npm run dev
|
|
|
357
609
|
- `selectedElement`: Object | null - 当前选中的元素
|
|
358
610
|
- `fieldData`: Object - 字段数据对象
|
|
359
611
|
- `template`: Object - 当前选中的模板
|
|
612
|
+
- `systemFields`: Array - 系统字段配置数组(从 CertificateEditor 传递)
|
|
360
613
|
|
|
361
614
|
**Events**:
|
|
362
615
|
- `select-element`: 选择元素时触发
|
|
@@ -374,6 +627,7 @@ npm run dev
|
|
|
374
627
|
|
|
375
628
|
**Props**:
|
|
376
629
|
- `element`: Object - 当前选中的元素
|
|
630
|
+
- `systemFields`: Array - 系统字段配置数组(从 CertificateEditor 传递)
|
|
377
631
|
|
|
378
632
|
**Events**:
|
|
379
633
|
- `update-element`: 更新元素时触发
|
|
@@ -402,6 +656,13 @@ npm run dev
|
|
|
402
656
|
- 支持搜索字段
|
|
403
657
|
- 插入字段占位符到文本内容
|
|
404
658
|
|
|
659
|
+
**Props**:
|
|
660
|
+
- `visible`: Boolean - 对话框显示状态
|
|
661
|
+
- `currentText`: String - 当前文本内容
|
|
662
|
+
- `selectionStart`: Number - 文本选择起始位置
|
|
663
|
+
- `selectionEnd`: Number - 文本选择结束位置
|
|
664
|
+
- `systemFields`: Array - 系统字段配置数组(从 PropertiesPanel 传递)
|
|
665
|
+
|
|
405
666
|
### CertificatePreview
|
|
406
667
|
|
|
407
668
|
证书预览组件,以模态框形式显示最终证书效果。
|
|
@@ -411,6 +672,13 @@ npm run dev
|
|
|
411
672
|
- 自动替换所有字段占位符为实际数据
|
|
412
673
|
- 支持关闭预览
|
|
413
674
|
|
|
675
|
+
**Props**:
|
|
676
|
+
- `visible`: Boolean - 预览对话框显示状态
|
|
677
|
+
- `elements`: Array - 元素列表
|
|
678
|
+
- `template`: Object - 当前选中的模板
|
|
679
|
+
- `fieldData`: Object - 字段数据对象
|
|
680
|
+
- `systemFields`: Array - 系统字段配置数组(从 CertificateEditor 传递)
|
|
681
|
+
|
|
414
682
|
## 🛠️ 技术栈
|
|
415
683
|
|
|
416
684
|
- **Vue 3**: 使用 Composition API 进行组件开发
|
|
@@ -418,6 +686,71 @@ npm run dev
|
|
|
418
686
|
- **原生 CSS**: 无第三方CSS框架,纯原生样式
|
|
419
687
|
- **Canvas/HTML**: 基于HTML和CSS的渲染,非Canvas绘制
|
|
420
688
|
|
|
689
|
+
## 🔌 API 参考
|
|
690
|
+
|
|
691
|
+
### CertificateEditor Props
|
|
692
|
+
|
|
693
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
694
|
+
|--------|------|--------|------|
|
|
695
|
+
| `systemFields` | `Array` | `SYSTEM_FIELDS` | 自定义系统字段配置数组 |
|
|
696
|
+
|
|
697
|
+
### CertificateEditor Events
|
|
698
|
+
|
|
699
|
+
| 事件名 | 参数 | 说明 |
|
|
700
|
+
|--------|------|------|
|
|
701
|
+
| `save` | `certificateData: Object` | 当用户点击保存按钮时触发,传递证书配置数据 |
|
|
702
|
+
|
|
703
|
+
### CertificateEditor Exposed Methods
|
|
704
|
+
|
|
705
|
+
| 方法名 | 参数 | 返回值 | 说明 |
|
|
706
|
+
|--------|------|--------|------|
|
|
707
|
+
| `getCertificateData()` | - | `Object` | 获取当前证书配置数据,无需点击保存按钮 |
|
|
708
|
+
|
|
709
|
+
### 系统字段对象格式
|
|
710
|
+
|
|
711
|
+
```typescript
|
|
712
|
+
interface SystemField {
|
|
713
|
+
key: string // 字段唯一标识
|
|
714
|
+
label: string // 字段显示名称
|
|
715
|
+
placeholder: string // 占位符格式,如 "{{姓名}}"
|
|
716
|
+
category?: string // 字段分类(可选)
|
|
717
|
+
description?: string // 字段描述(可选)
|
|
718
|
+
}
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### 证书配置数据格式
|
|
722
|
+
|
|
723
|
+
```typescript
|
|
724
|
+
interface CertificateData {
|
|
725
|
+
template: {
|
|
726
|
+
id: string
|
|
727
|
+
name: string
|
|
728
|
+
type: 'vertical' | 'horizontal'
|
|
729
|
+
background: string
|
|
730
|
+
width: number
|
|
731
|
+
height: number
|
|
732
|
+
}
|
|
733
|
+
elements: Array<{
|
|
734
|
+
id: number
|
|
735
|
+
type: 'text' | 'longtext' | 'image' | 'qrcode'
|
|
736
|
+
x: number
|
|
737
|
+
y: number
|
|
738
|
+
width: number
|
|
739
|
+
height?: number
|
|
740
|
+
content?: string
|
|
741
|
+
style?: object
|
|
742
|
+
imageSource?: 'url' | 'field'
|
|
743
|
+
imageUrl?: string
|
|
744
|
+
imageField?: string
|
|
745
|
+
qrcodeSource?: 'url' | 'field'
|
|
746
|
+
qrcodeContent?: string
|
|
747
|
+
qrcodeField?: string
|
|
748
|
+
}>
|
|
749
|
+
fieldData: Record<string, any>
|
|
750
|
+
timestamp: string
|
|
751
|
+
}
|
|
752
|
+
```
|
|
753
|
+
|
|
421
754
|
## 📋 系统字段列表
|
|
422
755
|
|
|
423
756
|
系统内置了丰富的字段类型,按类别组织:
|
|
@@ -474,6 +807,7 @@ npm run dev
|
|
|
474
807
|
- [x] 图片元素(本地上传、URL、关联字段)
|
|
475
808
|
- [x] 二维码元素(文本内容、URL、关联字段)
|
|
476
809
|
- [x] 系统字段关联
|
|
810
|
+
- [x] 自定义系统字段支持(通过 props 传入)
|
|
477
811
|
- [x] 预设模板管理
|
|
478
812
|
- [x] 自定义模板上传
|
|
479
813
|
- [x] 字段数据管理
|
|
@@ -493,10 +827,24 @@ npm run dev
|
|
|
493
827
|
- [ ] 模板收藏和分类
|
|
494
828
|
- [ ] 响应式设计适配
|
|
495
829
|
|
|
830
|
+
|
|
496
831
|
## 📄 许可证
|
|
497
832
|
|
|
498
833
|
MIT
|
|
499
834
|
|
|
835
|
+
## 📝 版本历史
|
|
836
|
+
|
|
837
|
+
### 1.0.3
|
|
838
|
+
- 初始版本发布
|
|
839
|
+
- 支持可视化证书编辑
|
|
840
|
+
- 支持系统字段关联
|
|
841
|
+
- 支持模板管理
|
|
842
|
+
- 支持图片和二维码元素
|
|
843
|
+
- 支持保存和预览功能
|
|
844
|
+
- 支持自定义系统字段
|
|
845
|
+
- 支持通过事件和方法获取保存的数据
|
|
846
|
+
- 发布为 npm 包,支持 ES 模块和 UMD 格式
|
|
847
|
+
|
|
500
848
|
## 👨💻 开发说明
|
|
501
849
|
|
|
502
850
|
### 核心概念
|