dascom-le-editor 0.0.35 → 0.0.37
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 +310 -186
- package/dist/editor.css +1 -1
- package/dist/editor.js +1 -1
- package/dist/editor.umd.cjs +182 -182
- package/dist/{main-BRPbb3Yq.js → main-D30TvLBs.js} +43156 -39216
- package/dist/{pdf-C2tRBTRN.js → pdf-DduIVmjR.js} +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
> 标签编辑器组件库,基于 Vue 3 + Fabric.js,支持矩形/圆形/线条/文字/条码/二维码/图片/计数器等元素的设计与编辑。
|
|
4
4
|
|
|
5
|
+
## 目录
|
|
6
|
+
|
|
7
|
+
- [安装](#安装)
|
|
8
|
+
- [使用](#使用)
|
|
9
|
+
- [API 参考](#api-参考)
|
|
10
|
+
- [构造参数](#构造参数)
|
|
11
|
+
- [实例属性](#实例属性)
|
|
12
|
+
- [实例方法](#实例方法)
|
|
13
|
+
- [静态方法](#静态方法)
|
|
14
|
+
- [类型定义](#类型定义)
|
|
15
|
+
- [二级菜单项 key 参考](#二级菜单项-key-参考)
|
|
16
|
+
- [激光配置(LaserConfig)](#激光配置laserconfig)
|
|
17
|
+
- [开启与数量限制](#开启与数量限制)
|
|
18
|
+
- [设置预设列表(外部传入)](#设置预设列表外部传入)
|
|
19
|
+
- [内置字段默认值](#内置字段默认值)
|
|
20
|
+
- [参数对象(FieldDef)字段说明](#参数对象-fielddef-字段说明)
|
|
21
|
+
- [数据流](#数据流)
|
|
22
|
+
|
|
5
23
|
## 安装
|
|
6
24
|
|
|
7
25
|
```bash
|
|
@@ -12,205 +30,265 @@ npm install dascom-le-editor
|
|
|
12
30
|
|
|
13
31
|
```js
|
|
14
32
|
import 'dascom-le-editor/dist/editor.css'
|
|
15
|
-
import
|
|
33
|
+
import LabelEditor from 'dascom-le-editor'
|
|
16
34
|
|
|
17
35
|
// 实例化,传入 html dom + 可选配置参数
|
|
18
|
-
const editorInstance = new
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
disabledTools: ['textname'], // 另一种用法:禁用指定组件(黑名单)
|
|
49
|
-
|
|
50
|
-
disabledMenuItems: ['edit:tagSettings'], // 隐藏指定二级菜单项(黑名单)
|
|
51
|
-
enabledMenuItems: [ // 启用的二级菜单项(白名单),不传则全部显示;与 disabledMenuItems 同时存在时白名单优先
|
|
52
|
-
// 编辑菜单
|
|
53
|
-
'edit:undo', // 撤销
|
|
54
|
-
'edit:redo', // 恢复
|
|
55
|
-
'edit:copy', // 复制
|
|
56
|
-
'edit:paste', // 粘贴
|
|
57
|
-
'edit:cut', // 剪切
|
|
58
|
-
'edit:delete', // 删除
|
|
59
|
-
'edit:exportImage', // 导出图片
|
|
60
|
-
'edit:tagSettings', // 标签属性设置
|
|
61
|
-
// 视图菜单
|
|
62
|
-
'view:objectProps', // 对象属性
|
|
63
|
-
'view:zoom', // 缩放
|
|
64
|
-
'view:ruler', // 标尺
|
|
65
|
-
'view:grid', // 网格
|
|
66
|
-
// 注意:工具(T) 菜单下的二级菜单项由 enabledTools / disabledTools 控制
|
|
67
|
-
],
|
|
36
|
+
const editorInstance = new LabelEditor(dom, {
|
|
37
|
+
// --- 画布 & 模板 ---
|
|
38
|
+
width: 85.6, // 标签宽度 (mm),默认 85.6
|
|
39
|
+
height: 54, // 标签高度 (mm),默认 54
|
|
40
|
+
dpi: 203, // 画布渲染 DPI,默认 600
|
|
41
|
+
maxSize: 1, // 导出 JSON 最大大小 (MB),默认 10
|
|
42
|
+
|
|
43
|
+
// --- 功能开关 ---
|
|
44
|
+
showVarnish: true, // 是否显示光油配置面板,默认 false
|
|
45
|
+
showLaser: 15, // 激光配置最大预设数量。>0 开启;0 / false 不显示(默认 0)
|
|
46
|
+
locale: 'zh-CN', // 编辑器语言,默认跟随浏览器
|
|
47
|
+
layerMaxCount: 2, // 最大图层数 (>1 才展示多图层编辑),默认 1;文件 JSON 内配置优先
|
|
48
|
+
separateLayerMode: false, // 是否启用分联图层模式,默认 false
|
|
49
|
+
separateLayerCount: 2, // 分联图层数,默认 2
|
|
50
|
+
separateLayerNames: ['上联', '下联'], // 分联图层名称,按图层顺序配置
|
|
51
|
+
layerStyleIndependent: false, // 图层背景和描边是否独立,默认 false
|
|
52
|
+
|
|
53
|
+
// --- 菜单 & 工具栏 ---
|
|
54
|
+
visibleMenus: ['edit', 'view', 'tool'], // 顶部菜单栏分区,不传则全部显示
|
|
55
|
+
enabledTools: [ // 启用的工具栏组件(白名单),不传则全部启用
|
|
56
|
+
'rect', 'circle', 'line', 'text', 'barcode', 'barcode2d',
|
|
57
|
+
'image', 'counter', 'json', 'table',
|
|
58
|
+
],
|
|
59
|
+
disabledTools: ['textname'], // 禁用的工具栏组件(黑名单)
|
|
60
|
+
disabledMenuItems: ['edit:tagSettings'], // 隐藏指定二级菜单项(黑名单)
|
|
61
|
+
enabledMenuItems: [ // 启用的二级菜单项(白名单),白名单优先
|
|
62
|
+
'edit:undo', 'edit:redo', 'edit:copy', 'edit:paste',
|
|
63
|
+
'edit:cut', 'edit:delete', 'edit:exportImage', 'edit:tagSettings',
|
|
64
|
+
'view:objectProps', 'view:zoom', 'view:ruler', 'view:grid',
|
|
65
|
+
],
|
|
68
66
|
})
|
|
69
|
-
|
|
70
|
-
editorInstance.setLocale('en-US')
|
|
71
|
-
// 获取当前编辑器语言
|
|
72
|
-
editorInstance.getLocale()
|
|
73
|
-
// 导出当前画布 JSON
|
|
74
|
-
const toExportJson = async () => {
|
|
75
|
-
const json = await editorInstance?.exportJson()
|
|
76
|
-
}
|
|
67
|
+
```
|
|
77
68
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
## API 参考
|
|
70
|
+
|
|
71
|
+
### 构造参数
|
|
72
|
+
|
|
73
|
+
`new LabelEditor(el: HTMLElement, options?: EditorConfigOptions)`
|
|
74
|
+
|
|
75
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
76
|
+
| --- | --- | --- | --- |
|
|
77
|
+
| `width` | `number` | 85.6 | 标签宽度 (mm) |
|
|
78
|
+
| `height` | `number` | 54 | 标签高度 (mm) |
|
|
79
|
+
| `dpi` | `number` | 203 | 画布渲染 DPI |
|
|
80
|
+
| `maxSize` | `number` | 0 | 导出 JSON 最大大小 (MB), 0不限制 |
|
|
81
|
+
| `showVarnish` | `boolean` | false | 是否显示光油配置面板 |
|
|
82
|
+
| `showLaser` | `number \| boolean` | 0 | 激光配置最大预设数量。>0 开启,true → 16,0/false 不显示 |
|
|
83
|
+
| `locale` | `string` | 浏览器语言 | 编辑器语言 |
|
|
84
|
+
| `layerMaxCount` | `number \| string` | 1 | 最大图层数,文件 JSON 内配置优先 |
|
|
85
|
+
| `separateLayerMode` | `boolean` | false | 分联图层模式 |
|
|
86
|
+
| `separateLayerCount` | `number \| string` | 2 | 分联图层数 |
|
|
87
|
+
| `separateLayerNames` | `string[]` | - | 分联图层名称 |
|
|
88
|
+
| `layerStyleIndependent` | `boolean` | false | 图层背景和描边是否独立 |
|
|
89
|
+
| `visibleMenus` | `string[]` | 全部 | 菜单栏分区白名单 |
|
|
90
|
+
| `enabledTools` | `string[]` | 全部 | 工具栏组件白名单 |
|
|
91
|
+
| `disabledTools` | `string[]` | [] | 工具栏组件黑名单 |
|
|
92
|
+
| `enabledMenuItems` | `string[]` | 全部 | 二级菜单项白名单,与黑名单同时存在时此优先 |
|
|
93
|
+
| `disabledMenuItems` | `string[]` | [] | 二级菜单项黑名单 |
|
|
94
|
+
|
|
95
|
+
### 实例属性
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
```js
|
|
98
|
+
// 当前已加载的自定义字体名 Set
|
|
99
|
+
editorInstance.loadedFonts // Set<string>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 实例方法
|
|
103
|
+
|
|
104
|
+
#### 生命周期
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
// 销毁编辑器实例。页面卸载 / 重新创建前必须调用,避免内存泄漏和幽灵回调。
|
|
108
|
+
editorInstance.destroy()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### 文件操作
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
// 加载标签 JSON 数据
|
|
115
|
+
// options.newFile: true 表示新建模板,将用外部激光预设重置(不保留模板历史)
|
|
116
|
+
// false / 不传 表示打开已有模板
|
|
117
|
+
editorInstance.loadJson(fileJson: object, { newFile: false })
|
|
118
|
+
|
|
119
|
+
// 导出画布 JSON
|
|
120
|
+
// type: 'checkFile' (默认) 会检查 maxSize;'noCheck' 跳过检查
|
|
121
|
+
const json = await editorInstance.exportJson(type?: 'checkFile' | 'noCheck'): Promise<string>
|
|
93
122
|
|
|
123
|
+
// 获取当前模板 JSON 大小 (KB)
|
|
124
|
+
const sizeKB = await editorInstance.getFileJsonSize(): Promise<number>
|
|
125
|
+
|
|
126
|
+
// 检查当前文件是否需要保存
|
|
127
|
+
const needSave = await editorInstance.checkFileSave(): Promise<boolean>
|
|
128
|
+
|
|
129
|
+
// 开启自动保存,每隔 time ms 检查一次,若文件未保存则通过回调送出 JSON
|
|
130
|
+
editorInstance.openAutoSave((json: string) => {
|
|
131
|
+
// 保存 json
|
|
132
|
+
}, 5000)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### JSON 字段数据
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
// 插入当前文件的字段 JSON,供文本/条码/二维码绑定 JSON Key 使用。
|
|
139
|
+
// 支持传入对象或合法 JSON 字符串。返回 true 表示写入成功或已排队。
|
|
140
|
+
const ok = editorInstance.insertFileFieldJson({ name: '张三', code: 'A001' })
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### 图片导出
|
|
144
|
+
|
|
145
|
+
```js
|
|
94
146
|
// 导出当前画布图片
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
147
|
+
const base64 = await editorInstance.getImage(options?: ExportImageOptions): Promise<string>
|
|
148
|
+
|
|
149
|
+
// 获取双联拼接图片(仅分联模式有效)
|
|
150
|
+
const composed = await editorInstance.getDoubleRibbonsImage(options?: ExportImageOptions): Promise<string>
|
|
151
|
+
|
|
152
|
+
// 获取缩略图,自动适配单图层 / 多行多列 / 双联多图层
|
|
153
|
+
const thumb = await editorInstance.getThumbnailImage(options?: ExportImageOptions): Promise<string>
|
|
98
154
|
|
|
99
|
-
// 获取缩略图,支持单图层,多行多列,双联多图层
|
|
100
|
-
const getThumbnailImage = async ()=>{
|
|
101
|
-
let data = await editorInstance.getThumbnailImage()
|
|
102
|
-
}
|
|
103
155
|
// 统一导出入口:支持当前画布 / JSON、合并 / 独立图层、双联横向拼接
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
})
|
|
114
|
-
const layerImages = data.images
|
|
115
|
-
const composedImage = data.composedImage
|
|
116
|
-
}
|
|
117
|
-
// 双联模式 获取双联拼接后的图片
|
|
118
|
-
const getDoubleRibbonsImage = async ()=>{
|
|
119
|
-
let data = await editorInstance.getDoubleRibbonsImage()
|
|
120
|
-
}
|
|
156
|
+
const merged = await editorInstance.exportImage({ mode: 'merged' })
|
|
157
|
+
const separate = await editorInstance.exportImage({
|
|
158
|
+
mode: 'separate',
|
|
159
|
+
layout: 'doubleRibbons',
|
|
160
|
+
gap: 50,
|
|
161
|
+
})
|
|
162
|
+
// 独立图层模式返回 { images: string[], composedImage: string }
|
|
163
|
+
// 合并模式返回 string
|
|
164
|
+
```
|
|
121
165
|
|
|
122
|
-
|
|
123
|
-
editorInstance.destroy()
|
|
166
|
+
#### 语言
|
|
124
167
|
|
|
125
|
-
|
|
126
|
-
|
|
168
|
+
```js
|
|
169
|
+
// 设置语言
|
|
170
|
+
editorInstance.setLocale('en-US')
|
|
171
|
+
|
|
172
|
+
// 获取当前语言
|
|
173
|
+
editorInstance.getLocale() // 'en-US'
|
|
174
|
+
```
|
|
127
175
|
|
|
128
|
-
|
|
129
|
-
// 开启后会自动启用多图层,并使用初始化配置里的 separateLayerCount / separateLayerNames
|
|
130
|
-
editorInstance.setSeparateLayerMode(isOpen: boolean)
|
|
176
|
+
#### 图层控制
|
|
131
177
|
|
|
178
|
+
```js
|
|
179
|
+
// 启用/禁用多图层编辑
|
|
180
|
+
editorInstance.setMultiLayerEnabled(true)
|
|
181
|
+
editorInstance.toggleMultiLayer(true) // 别名,相同功能
|
|
182
|
+
|
|
183
|
+
// 设置图层最大数量(非分联模式下生效)
|
|
184
|
+
editorInstance.setLayerMaxCount(3)
|
|
132
185
|
|
|
186
|
+
// 设置分联图层模式
|
|
187
|
+
editorInstance.setSeparateLayerMode(true)
|
|
133
188
|
|
|
134
|
-
//
|
|
189
|
+
// 快速进入双联模式(图层名称默认为「上联」「下联」)
|
|
135
190
|
editorInstance.enterDoubleRibbons()
|
|
136
191
|
|
|
137
192
|
// 更新分联图层配置,仅在分联模式开启时同步到已打开的 tab
|
|
138
|
-
editorInstance.setSeparateLayerConfig({
|
|
139
|
-
count: 2,
|
|
140
|
-
names: ['上联', '下联'],
|
|
141
|
-
})
|
|
193
|
+
editorInstance.setSeparateLayerConfig({ count: 2, names: ['上联', '下联'] })
|
|
142
194
|
|
|
143
|
-
//
|
|
144
|
-
editorInstance.
|
|
195
|
+
// 开启/关闭独立图层样式(每个图层可单独设置背景色、背景图、描边)
|
|
196
|
+
await editorInstance.setLayerStyleIndependent(true)
|
|
197
|
+
```
|
|
145
198
|
|
|
146
|
-
|
|
147
|
-
editorInstance.openAutoSave((data) => {
|
|
199
|
+
#### UI 控制
|
|
148
200
|
|
|
149
|
-
|
|
201
|
+
```js
|
|
202
|
+
// 显示/隐藏文件 Tab 栏
|
|
203
|
+
editorInstance.toggleEditTabs(false)
|
|
204
|
+
```
|
|
150
205
|
|
|
151
|
-
|
|
152
|
-
name: string,
|
|
153
|
-
url ? : string
|
|
154
|
-
}
|
|
155
|
-
// fontItem 里有 url,则会自动加载 load 对应url 字体到 页面document
|
|
156
|
-
// 默认字体列表增加自定义字体
|
|
157
|
-
editorInstance.addCustomFontList(fontItem[])
|
|
206
|
+
#### 字体
|
|
158
207
|
|
|
159
|
-
|
|
160
|
-
|
|
208
|
+
```js
|
|
209
|
+
// 添加自定义字体列表。fontItem 含 url 时自动加载到页面。
|
|
210
|
+
editorInstance.addCustomFontList([
|
|
211
|
+
{ name: 'HanSans', url: 'https://example.com/HanSans.otf' },
|
|
212
|
+
])
|
|
161
213
|
|
|
162
|
-
//
|
|
163
|
-
editorInstance.
|
|
214
|
+
// 替换整个字体列表(覆盖默认字体)
|
|
215
|
+
editorInstance.replaceFontList([
|
|
216
|
+
{ name: 'HanSans' },
|
|
217
|
+
])
|
|
164
218
|
|
|
165
|
-
//
|
|
166
|
-
editorInstance.
|
|
167
|
-
|
|
219
|
+
// 编辑器检测到模板使用了未加载字体时,通过此回调通知宿主加载
|
|
220
|
+
editorInstance.selectFontCallback((fontNameList: string[]) => {
|
|
221
|
+
// fontNameList 是需要加载的字体名数组
|
|
168
222
|
})
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
{
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
223
|
+
|
|
224
|
+
// 加载字体 Blob 到编辑器
|
|
225
|
+
await editorInstance.loadFontFile({ fontName: 'HanSans', blob: fontBlob })
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### 激光配置
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
// 设置外部激光预设列表,详见「激光配置」章节
|
|
232
|
+
editorInstance.setLaserConfigList([...])
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 静态方法
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
// 从 JSON 数据直接导出图片(无 DOM 渲染)
|
|
239
|
+
const base64 = await LabelEditor.loadJsonToImageBase64(fileJson, {
|
|
240
|
+
cmds: [{ cmd: 'ReplaceContent', name: '姓名', content: '张三' }],
|
|
241
|
+
timeout: 5000,
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
// 静态导出方法,与实例 exportImage 相同但需要传入 data 字段
|
|
245
|
+
const result = await LabelEditor.exportImage({
|
|
246
|
+
data: fileJson,
|
|
247
|
+
mode: 'separate',
|
|
248
|
+
layout: 'doubleRibbons',
|
|
249
|
+
})
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### 类型定义
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
type ExportImageMode = 'merged' | 'separate'
|
|
256
|
+
type ExportImageLayout = 'auto' | 'doubleRibbons'
|
|
257
|
+
|
|
258
|
+
type ExportImageSeparateResult = {
|
|
259
|
+
images: string[]
|
|
260
|
+
composedImage: string
|
|
201
261
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
262
|
+
|
|
263
|
+
type ExportImageResult = string | ExportImageSeparateResult
|
|
264
|
+
|
|
265
|
+
type ExportImageOptions = {
|
|
266
|
+
/** 静态导出时必传,实例方法无需传入 */
|
|
267
|
+
data?: any
|
|
268
|
+
/** 导出前替换 canvas 内容的命令 */
|
|
269
|
+
cmds?: Array<{ cmd: string; name: string; content: string }>
|
|
270
|
+
/** 超时时间 (ms),默认 5000 */
|
|
271
|
+
timeout?: number
|
|
272
|
+
/** 是否返回完整 dataURL,默认 false(返回纯 base64) */
|
|
273
|
+
returnDataUrl?: boolean
|
|
274
|
+
/** 画布 DPI,不传则用文件内的 DPI */
|
|
275
|
+
dpi?: number
|
|
276
|
+
/** 标签宽度 (mm) */
|
|
277
|
+
width?: number
|
|
278
|
+
/** 标签高度 (mm) */
|
|
279
|
+
height?: number
|
|
280
|
+
/** 多图层导出模式 */
|
|
281
|
+
mode?: ExportImageMode
|
|
282
|
+
/** separate 时 composedImage 使用横向拼接 */
|
|
283
|
+
layout?: ExportImageLayout
|
|
284
|
+
/** 横向拼接间距,默认 50px */
|
|
285
|
+
gap?: number
|
|
210
286
|
}
|
|
211
287
|
```
|
|
212
288
|
|
|
213
|
-
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 二级菜单项 key 参考
|
|
214
292
|
|
|
215
293
|
通过 `enabledMenuItems`(白名单)或 `disabledMenuItems`(黑名单)控制二级菜单项的显示/隐藏,两者同时存在时白名单优先。工具(T) 菜单下的二级菜单项由 `enabledTools` / `disabledTools` 控制,无需在此重复配置。
|
|
216
294
|
|
|
@@ -231,37 +309,83 @@ async function exportJsonSeparateImages() {
|
|
|
231
309
|
|
|
232
310
|
---
|
|
233
311
|
|
|
234
|
-
##
|
|
312
|
+
## 激光配置(LaserConfig)
|
|
313
|
+
|
|
314
|
+
激光配置是**模板级共享数据**。画布元素只存 `laserConfigId` 引用,具体参数值由预设列表提供。修改某预设会影响所有引用它的元素。
|
|
315
|
+
|
|
316
|
+
### 开启与数量限制
|
|
317
|
+
|
|
318
|
+
初始化时通过 `showLaser` 控制:
|
|
235
319
|
|
|
236
|
-
|
|
320
|
+
```js
|
|
321
|
+
new LabelEditor(dom, {
|
|
322
|
+
showLaser: 15, // >0:开启且为最大可选预设数量;0 / false:不显示(默认 0)
|
|
323
|
+
})
|
|
324
|
+
```
|
|
237
325
|
|
|
238
|
-
###
|
|
326
|
+
### 设置预设列表(外部传入)
|
|
327
|
+
|
|
328
|
+
通过实例方法传入外部预设,编辑器按 `configId` 与模板预设做 diff(新增的并入模板,模板有而外部无的弹框警告):
|
|
239
329
|
|
|
240
330
|
```js
|
|
241
|
-
|
|
331
|
+
editorInstance.setLaserConfigList([
|
|
242
332
|
{
|
|
243
333
|
configId: 'preset_001',
|
|
244
334
|
configName: '默认参数',
|
|
245
335
|
params: [
|
|
246
|
-
{ key: 'repeatTimes', label: '打标次数', min: 0, max: 10000, unit: '', defaultValue: 1, status:
|
|
336
|
+
{ key: 'repeatTimes', label: '打标次数', min: 0, max: 10000, unit: '', defaultValue: 1, status: 0 },
|
|
247
337
|
{ key: 'scanSpeed', label: '激光速度', min: 0, max: 65535, unit: 'mm/s', defaultValue: 3000, status: 0 },
|
|
248
|
-
{ key: '
|
|
338
|
+
{ key: 'jumpSpeed', label: '跳转速度', min: 0, max: 65535, unit: 'mm/s', defaultValue: 3000, status: 0 },
|
|
339
|
+
{ key: 'power', label: '功率', min: 0, max: 100, unit: '%', defaultValue: 20, status: 1 },
|
|
340
|
+
{ key: 'frequence', label: '频率', min: 0, max: 4000, unit: 'khz', defaultValue: 200, status: 0 },
|
|
341
|
+
{ key: 'pulseWidth', label: '脉宽', min: 0, max: 500, unit: 'ns', defaultValue: 50, status: 0 },
|
|
342
|
+
{ key: 'openLightDelay', label: '开光延迟', min: -1000, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
|
|
343
|
+
{ key: 'closeLightDelay', label: '关光延迟', min: -1000, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
|
|
344
|
+
{ key: 'endDelay', label: '结束延迟', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
|
|
345
|
+
{ key: 'trunDelay', label: '转角延时', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
|
|
346
|
+
{ key: 'jumpDelay', label: '跳转延时', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
|
|
249
347
|
],
|
|
250
348
|
},
|
|
251
349
|
])
|
|
252
350
|
```
|
|
253
351
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
|
352
|
+
> 以上 11 个字段为编辑器内置字段(`builtInFields`)。`setLaserConfigList` 可只传入部分字段,未传入的字段不会显示;传入的字段若未带 `status`,会回退到内置默认值(见下表)。
|
|
353
|
+
|
|
354
|
+
### 内置字段默认值
|
|
355
|
+
|
|
356
|
+
`status`:`1` 表示可编辑,`0` 或缺失表示禁用(输入框置灰)。
|
|
357
|
+
|
|
358
|
+
| key | label | min | max | unit | defaultValue | status |
|
|
359
|
+
| --- | --- | --- | --- | --- | --- | --- |
|
|
360
|
+
| `repeatTimes` | 打标次数 | 0 | 10000 | - | 1 | 0 |
|
|
361
|
+
| `scanSpeed` | 激光速度 | 0 | 65535 | mm/s | 3000 | 0 |
|
|
362
|
+
| `jumpSpeed` | 跳转速度 | 0 | 65535 | mm/s | 3000 | 0 |
|
|
363
|
+
| `power` | 功率 | 0 | 100 | % | 20 | 1 |
|
|
364
|
+
| `frequence` | 频率 | 0 | 4000 | khz | 200 | 0 |
|
|
365
|
+
| `pulseWidth` | 脉宽 | 0 | 500 | ns | 50 | 0 |
|
|
366
|
+
| `openLightDelay` | 开光延迟 | -1000 | 2000 | us | 0 | 0 |
|
|
367
|
+
| `closeLightDelay` | 关光延迟 | -1000 | 2000 | us | 0 | 0 |
|
|
368
|
+
| `endDelay` | 结束延迟 | 0 | 2000 | us | 0 | 0 |
|
|
369
|
+
| `trunDelay` | 转角延时 | 0 | 2000 | us | 0 | 0 |
|
|
370
|
+
| `jumpDelay` | 跳转延时 | 0 | 2000 | us | 0 | 0 |
|
|
371
|
+
|
|
372
|
+
### 参数对象(FieldDef)字段说明
|
|
373
|
+
|
|
374
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
375
|
+
| --- | --- | --- | --- |
|
|
376
|
+
| `configId` | `string` | 是 | 预设唯一标识,用于外部与模板预设匹配 |
|
|
377
|
+
| `configName` | `string` | 是 | 预设显示名称 |
|
|
378
|
+
| `params` | `FieldDef[]` | 是 | 参数定义数组 |
|
|
379
|
+
| `key` | `string` | 是 | 字段标识,需与内置字段 key 对应(`power` 等)。非内置 key 也能显示,但不回退默认值 |
|
|
380
|
+
| `label` | `string` | 否 | 显示名称。若同时存在 `labelKey` 则优先走 i18n 翻译 |
|
|
381
|
+
| `min` / `max` | `number` | 是 | 数值范围,作用于输入框上下限 |
|
|
382
|
+
| `unit` | `string` | 否 | 单位后缀(`mm/s`、`%` 等),空则不显示 |
|
|
383
|
+
| `defaultValue` | `number` | 是 | 选中该预设时回填到输入框的初始值 |
|
|
384
|
+
| `status` | `number` | 否 | `1` 可编辑;`0` 或缺失则禁用,缺失时回退到内置 `status` |
|
|
261
385
|
|
|
262
386
|
### 数据流
|
|
263
387
|
|
|
264
|
-
- **外部传入** -- configId
|
|
265
|
-
- **保存** --
|
|
266
|
-
- **重新打开** -- loadJson
|
|
267
|
-
- **限制** -- showLaser
|
|
388
|
+
- **外部传入** -- `setLaserConfigList` 按 `configId` 与模板预设做 diff:外部有、模板无 → 并入模板;模板有、外部无 → 弹框警告
|
|
389
|
+
- **保存** -- 只导出画布实际引用的预设(`configId` 去重后的列表)
|
|
390
|
+
- **重新打开** -- `loadJson` 恢复模板预设,再执行 `syncExternalPresets` 做 diff
|
|
391
|
+
- **限制** -- `showLaser` 限制画布实际引用的预设**种类数**,超出弹框警告
|