dascom-le-editor 0.0.36 → 0.0.38

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 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,209 +30,348 @@ npm install dascom-le-editor
12
30
 
13
31
  ```js
14
32
  import 'dascom-le-editor/dist/editor.css'
15
- import editor from 'dascom-le-editor'
33
+ import LabelEditor from 'dascom-le-editor'
16
34
 
17
35
  // 实例化,传入 html dom + 可选配置参数
18
- const editorInstance = new editor(dom, {
19
- width: 85.6, // 标签宽度 (mm),默认 85.6
20
- height: 54, // 标签高度 (mm),默认 54
21
- dpi: 203, // 画布渲染默认 DPI
22
- maxSize: 0, // 导出画布数据的最大值(MB), 默认为0 不限制
23
- showVarnish: true, // 是否显示光油配置面板,默认 false
24
- showLaser: 15, // 是否显示激光配置,默认不开启
25
- locale: 'zh-CN', // 设置语言
26
- layerMaxCount: 1, // 最大图层数(大于1 才展示多图层编辑),默认 1;文件 JSON 内配置优先
27
- separateLayerMode: false, // 是否启用分联图层模式,默认 false
28
- separateLayerCount: 2, // 分联图层数,默认 2
29
- separateLayerNames: ['上联', '下联'], // 分联图层名称,按图层顺序配置
30
- visibleMenus: [ // 控制顶部菜单栏显示的分区,不传则全部显示
31
- 'edit', // 编辑
32
- 'view', // 视图
33
- 'tool', // 工具
34
- ],
35
- enabledTools: [ // 启用的工具栏组件(白名单),不传则全部启用
36
- 'rect', // 矩形
37
- 'circle', // 圆形
38
- 'line', // 线
39
- 'text', // 文字
40
- 'barcode', // 条码
41
- 'barcode2d', // 二维码
42
- 'image', // 图片
43
- 'counter', // 日期计数器
44
- 'json', // json
45
- 'table' // 表格
46
- // 'textname', // 名字
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
+ // messages: { // 自定义翻译文案,深度合并到内置翻译(详见「语言」章节)
48
+ // 'zh-CN': { editor: { shell: { print: '发送到打印机' } } },
49
+ // },
50
+ layerMaxCount: 2, // 最大图层数 (>1 才展示多图层编辑),默认 1;文件 JSON 内配置优先
51
+ separateLayerMode: false, // 是否启用分联图层模式,默认 false
52
+ separateLayerCount: 2, // 分联图层数,默认 2
53
+ separateLayerNames: ['上联', '下联'], // 分联图层名称,按图层顺序配置
54
+ layerStyleIndependent: false, // 图层背景和描边是否独立,默认 false
55
+
56
+ // --- 菜单 & 工具栏 ---
57
+ visibleMenus: ['edit', 'view', 'tool'], // 顶部菜单栏分区,不传则全部显示
58
+ enabledTools: [ // 启用的工具栏组件(白名单),不传则全部启用
59
+ 'rect', 'circle', 'line', 'text', 'barcode', 'barcode2d',
60
+ 'image', 'counter', 'json', 'table',
61
+ ],
62
+ disabledTools: ['textname'], // 禁用的工具栏组件(黑名单)
63
+ disabledMenuItems: ['edit:tagSettings'], // 隐藏指定二级菜单项(黑名单)
64
+ enabledMenuItems: [ // 启用的二级菜单项(白名单),白名单优先
65
+ 'edit:undo', 'edit:redo', 'edit:copy', 'edit:paste',
66
+ 'edit:cut', 'edit:delete', 'edit:exportImage', 'edit:tagSettings',
67
+ 'view:objectProps', 'view:zoom', 'view:ruler', 'view:grid',
68
+ ],
68
69
  })
69
- // 设置编辑器语言
70
- editorInstance.setLocale('en-US')
71
- // 获取当前编辑器语言
72
- editorInstance.getLocale()
70
+ ```
73
71
 
74
- // 获取当前编辑器模板数据大小,单位KB
75
- editorInstance.getFileJsonSize()
72
+ ## API 参考
73
+
74
+ ### 构造参数
75
+
76
+ `new LabelEditor(el: HTMLElement, options?: EditorConfigOptions)`
77
+
78
+ | 参数 | 类型 | 默认值 | 说明 |
79
+ | --- | --- | --- | --- |
80
+ | `width` | `number` | 85.6 | 标签宽度 (mm) |
81
+ | `height` | `number` | 54 | 标签高度 (mm) |
82
+ | `dpi` | `number` | 203 | 画布渲染 DPI |
83
+ | `maxSize` | `number` | 0 | 导出 JSON 最大大小 (MB), 0不限制 |
84
+ | `showVarnish` | `boolean` | false | 是否显示光油配置面板 |
85
+ | `showLaser` | `number \| boolean` | 0 | 激光配置最大预设数量。>0 开启,true → 16,0/false 不显示 |
86
+ | `locale` | `string` | 浏览器语言 | 编辑器语言。支持 `'zh-CN'` / `'en-US'`,其余降级为 `zh-CN` |
87
+ | `messages` | `Record<'zh-CN' \| 'en-US', MessageTree>` | - | 自定义翻译文案,深度合并到内置翻译中(仅需传入要覆盖的 key) |
88
+ | `layerMaxCount` | `number \| string` | 1 | 最大图层数,文件 JSON 内配置优先 |
89
+ | `separateLayerMode` | `boolean` | false | 分联图层模式 |
90
+ | `separateLayerCount` | `number \| string` | 2 | 分联图层数 |
91
+ | `separateLayerNames` | `string[]` | - | 分联图层名称 |
92
+ | `layerStyleIndependent` | `boolean` | false | 图层背景和描边是否独立 |
93
+ | `visibleMenus` | `string[]` | 全部 | 菜单栏分区白名单 |
94
+ | `enabledTools` | `string[]` | 全部 | 工具栏组件白名单 |
95
+ | `disabledTools` | `string[]` | [] | 工具栏组件黑名单 |
96
+ | `enabledMenuItems` | `string[]` | 全部 | 二级菜单项白名单,与黑名单同时存在时此优先 |
97
+ | `disabledMenuItems` | `string[]` | [] | 二级菜单项黑名单 |
98
+
99
+ ### 实例属性
76
100
 
77
- // 导出当前画布 JSON
78
- const toExportJson = async () => {
79
- const json = await editorInstance?.exportJson()
80
- }
101
+ ```js
102
+ // 当前已加载的自定义字体名 Set
103
+ editorInstance.loadedFonts // Set<string>
104
+ ```
81
105
 
82
- // 导入 JSON 数据,新开编辑 tab
83
- const toImportJson = async (fileJson: any) => {
84
- await editorInstance?.loadJson(fileJson)
85
- }
106
+ ### 实例方法
86
107
 
87
- // 插入当前文件的字段 JSON,供文本/条码/二维码绑定 JSON Key 使用
88
- // 支持传入对象或合法 JSON 字符串;写入成功或已排队等待写入返回 true,入参非法返回 false
89
- // 如果调用时当前 tab 还未初始化完成,编辑器会在 active tab 创建后自动写入最后一次传入的数据
90
- const toInsertFileFieldJson = () => {
91
- const success = editorInstance?.insertFileFieldJson({
92
- name: '张三',
93
- code: 'A001',
94
- license: 'ISC',
95
- })
96
- }
108
+ #### 生命周期
109
+
110
+ ```js
111
+ // 销毁编辑器实例。页面卸载 / 重新创建前必须调用,避免内存泄漏和幽灵回调。
112
+ editorInstance.destroy()
113
+ ```
114
+
115
+ #### 文件操作
116
+
117
+ ```js
118
+ // 加载标签 JSON 数据
119
+ // options.newFile: true 表示新建模板,将用外部激光预设重置(不保留模板历史)
120
+ // false / 不传 表示打开已有模板
121
+ editorInstance.loadJson(fileJson: object, { newFile: false })
122
+
123
+ // 导出画布 JSON
124
+ // type: 'checkFile' (默认) 会检查 maxSize;'noCheck' 跳过检查
125
+ const json = await editorInstance.exportJson(type?: 'checkFile' | 'noCheck'): Promise<string>
126
+
127
+ // 获取当前模板 JSON 大小 (KB)
128
+ const sizeKB = await editorInstance.getFileJsonSize(): Promise<number>
129
+
130
+ // 检查当前文件是否需要保存
131
+ const needSave = await editorInstance.checkFileSave(): Promise<boolean>
132
+
133
+ // 开启自动保存,每隔 time ms 检查一次,若文件未保存则通过回调送出 JSON
134
+ editorInstance.openAutoSave((json: string) => {
135
+ // 保存 json
136
+ }, 5000)
137
+ ```
138
+
139
+ #### JSON 字段数据
140
+
141
+ ```js
142
+ // 插入当前文件的字段 JSON,供文本/条码/二维码绑定 JSON Key 使用。
143
+ // 支持传入对象或合法 JSON 字符串。返回 true 表示写入成功或已排队。
144
+ const ok = editorInstance.insertFileFieldJson({ name: '张三', code: 'A001' })
145
+ ```
97
146
 
147
+ #### 图片导出
148
+
149
+ ```js
98
150
  // 导出当前画布图片
99
- const toExportImage = async () => {
100
- const data = await editorInstance?.getImage()
101
- }
151
+ const base64 = await editorInstance.getImage(options?: ExportImageOptions): Promise<string>
152
+
153
+ // 获取双联拼接图片(仅分联模式有效)
154
+ const composed = await editorInstance.getDoubleRibbonsImage(options?: ExportImageOptions): Promise<string>
155
+
156
+ // 获取缩略图,自动适配单图层 / 多行多列 / 双联多图层
157
+ const thumb = await editorInstance.getThumbnailImage(options?: ExportImageOptions): Promise<string>
102
158
 
103
- // 获取缩略图,支持单图层,多行多列,双联多图层
104
- const getThumbnailImage = async ()=>{
105
- let data = await editorInstance.getThumbnailImage()
106
- }
107
159
  // 统一导出入口:支持当前画布 / JSON、合并 / 独立图层、双联横向拼接
108
- // 默认返回 string;独立图层模式返回 { images: string[], composedImage: string }
109
- const exportMergedImage = async () => {
110
- const data = await editorInstance.exportImage({ mode: 'merged' })
111
- }
112
- const exportSeparateImages = async () => {
113
- const data = await editorInstance.exportImage({
114
- mode: 'separate',
115
- layout: 'doubleRibbons',
116
- gap: 50,
117
- })
118
- const layerImages = data.images
119
- const composedImage = data.composedImage
120
- }
121
- // 双联模式 获取双联拼接后的图片
122
- const getDoubleRibbonsImage = async ()=>{
123
- let data = await editorInstance.getDoubleRibbonsImage()
124
- }
160
+ const merged = await editorInstance.exportImage({ mode: 'merged' })
161
+ const separate = await editorInstance.exportImage({
162
+ mode: 'separate',
163
+ layout: 'doubleRibbons',
164
+ gap: 50,
165
+ })
166
+ // 独立图层模式返回 { images: string[], composedImage: string }
167
+ // 合并模式返回 string
168
+ ```
125
169
 
126
- // 销毁编辑器实例, 页面卸载 / 重新创建前必须调用
127
- editorInstance.destroy()
170
+ #### 语言
171
+
172
+ ```js
173
+ // 设置语言
174
+ editorInstance.setLocale('en-US')
175
+
176
+ // 获取当前语言
177
+ editorInstance.getLocale() // 'en-US'
178
+
179
+ // 动态注入或覆盖翻译文案
180
+ editorInstance.setMessages({
181
+ 'zh-CN': {
182
+ editor: {
183
+ label: '标签',
184
+ shell: { print: '打印' },
185
+ },
186
+ },
187
+ 'en-US': {
188
+ editor: {
189
+ label: 'Label',
190
+ },
191
+ },
192
+ })
193
+ ```
194
+
195
+ **支持的语言**: `'zh-CN'` | `'en-US'`。传入其他值会降级为 `'zh-CN'` 并在控制台给出 warning。
196
+
197
+ **翻译文案结构(MessageTree)** `Record<SupportedLocale, MessageTree>`
198
+
199
+ 翻译按命名空间组织,与内置 JSON 文件的层级一致。键名——即你在 UI 中看到的文案——可以通过 `setMessages` 覆盖或扩展。可用的命名空间:
200
+
201
+ | 命名空间 | 对应 JSON 文件 | 覆盖范围 |
202
+ | --- | --- | --- |
203
+ | `editor` | `packages/i18n/src/locales/{lang}/editor.json` | 画布、工具栏、属性面板、表格、图片、打印、激光等所有编辑器核心文案 |
204
+ | `menu` | `menu.json` | 顶部菜单栏(编辑、视图、工具) |
205
+ | `common` | `common.json` | 通用 UI 文案(按钮、提示) |
206
+ | `print` | `print.json` | 打印相关文案 |
207
+ | `database` | `database.json` | 数据库视图相关文案 |
208
+ | `rfid` | `rfid.json` | RFID 配置相关文案 |
209
+ | `errors` | `errors.json` | 错误信息文案 |
210
+
211
+ **三种传入时机:**
212
+
213
+ 1. **构造时静态传入** —— 适合在创建编辑器实例时就固定翻译:
128
214
 
129
- // 设置图层最大数量,非分联模式下生效
130
- editorInstance.setLayerMaxCount(count: number | string)
215
+ ```js
216
+ const editorInstance = new LabelEditor(dom, {
217
+ locale: 'zh-CN',
218
+ messages: {
219
+ 'zh-CN': {
220
+ editor: {
221
+ label: '我的标签',
222
+ shell: { print: '开始打印' },
223
+ },
224
+ },
225
+ 'en-US': {
226
+ editor: {
227
+ label: 'My Label',
228
+ shell: { print: 'Start Print' },
229
+ },
230
+ },
231
+ },
232
+ })
233
+ ```
234
+
235
+ 2. **运行时动态调用 `setMessages()`** —— 适合从服务端拉取翻译后注入:
236
+
237
+ ```js
238
+ fetch('/api/locales/editor-zh-CN.json')
239
+ .then(res => res.json())
240
+ .then(data => editorInstance.setMessages({ 'zh-CN': data }))
241
+ ```
242
+
243
+ 3. **`setMessages` 与内置文案的关系** —— **深度合并**,不会丢失未覆盖的 key:
131
244
 
132
- // 设置是否启用分联图层模式
133
- // 开启后会自动启用多图层,并使用初始化配置里的 separateLayerCount / separateLayerNames
134
- editorInstance.setSeparateLayerMode(isOpen: boolean)
245
+ 内置翻译是完整的后备值。你在 `messages` / `setMessages` 中只需填入需要覆盖的 key,其余 key 仍然使用内置文案。例如只覆盖编辑器的 "打印" 按钮文案,可以这样写:
246
+
247
+ ```js
248
+ editorInstance.setMessages({
249
+ 'zh-CN': {
250
+ editor: {
251
+ shell: { print: '发送到打印机' },
252
+ },
253
+ },
254
+ })
255
+ // "发送到打印机" 替换 "打印",其余内置文案不变
256
+ ```
135
257
 
136
258
 
259
+ #### 图层控制
137
260
 
138
- // 快速进入双联模式,图层名称默认为「上联」「下联」
261
+ ```js
262
+ // 启用/禁用多图层编辑
263
+ editorInstance.setMultiLayerEnabled(true)
264
+ editorInstance.toggleMultiLayer(true) // 别名,相同功能
265
+
266
+ // 设置图层最大数量(非分联模式下生效)
267
+ editorInstance.setLayerMaxCount(3)
268
+
269
+ // 设置分联图层模式
270
+ editorInstance.setSeparateLayerMode(true)
271
+
272
+ // 快速进入双联模式(图层名称默认为「上联」「下联」)
139
273
  editorInstance.enterDoubleRibbons()
140
274
 
141
275
  // 更新分联图层配置,仅在分联模式开启时同步到已打开的 tab
142
- editorInstance.setSeparateLayerConfig({
143
- count: 2,
144
- names: ['上联', '下联'],
145
- })
276
+ editorInstance.setSeparateLayerConfig({ count: 2, names: ['上联', '下联'] })
146
277
 
147
- // 是否展示打开文件栏
148
- editorInstance.toggleEditTabs(isShow: boolean)
278
+ // 开启/关闭独立图层样式(每个图层可单独设置背景色、背景图、描边)
279
+ await editorInstance.setLayerStyleIndependent(true)
280
+ ```
149
281
 
150
- // 开启自动保存
151
- editorInstance.openAutoSave((data) => {
282
+ #### UI 控制
152
283
 
153
- }, 10000)
284
+ ```js
285
+ // 显示/隐藏文件 Tab 栏
286
+ editorInstance.toggleEditTabs(false)
287
+ ```
154
288
 
155
- interface fontItem {
156
- name: string,
157
- url ? : string
158
- }
159
- // fontItem 里有 url,则会自动加载 load 对应url 字体到 页面document
160
- // 默认字体列表增加自定义字体
161
- editorInstance.addCustomFontList(fontItem[])
289
+ #### 字体
162
290
 
163
- // 替换整个字体列表
164
- editorInstance.replaceFontList(fontItem[])
291
+ ```js
292
+ // 添加自定义字体列表。fontItem 含 url 时自动加载到页面。
293
+ editorInstance.addCustomFontList([
294
+ { name: 'HanSans', url: 'https://example.com/HanSans.otf' },
295
+ ])
165
296
 
166
- // 编辑器切换使用字体回调
167
- editorInstance.selectFontCallback(fn(fontNameList: string[]))
297
+ // 替换整个字体列表(覆盖默认字体)
298
+ editorInstance.replaceFontList([
299
+ { name: 'HanSans' },
300
+ ])
168
301
 
169
- // 编辑器加载字体
170
- editorInstance.loadFontFile(data: {
171
- fontName: string;blob: Blob
302
+ // 编辑器检测到模板使用了未加载字体时,通过此回调通知宿主加载
303
+ editorInstance.selectFontCallback((fontNameList: string[]) => {
304
+ // fontNameList 是需要加载的字体名数组
172
305
  })
173
- // 替换cmd 格式
174
- type cdmsTemp = [
175
- {
176
- "cmd": "ReplaceContent",
177
- "name": "姓名",
178
- "content": "张三"
179
- }
180
- ]
181
- interface LoadJsonToImageBase64Options {
182
- /** 导出前用于替换 canvas json 内容的命令 */
183
- cmds ? : cdmsTemp[];
184
- /** 导出超时时间,默认 5000ms */
185
- timeout ? : number;
186
- /** 是否返回完整 dataURL;默认 true,返回完整 dataURL */
187
- returnDataUrl ? : boolean;
188
- /** 画布dpi,不传则用文件的 dpi */
189
- dpi ? : number;
190
- // 标签宽度 (mm)
191
- width ? : number;
192
- // 标签高度 (mm)
193
- height ? : number;
194
- /** 多图层导出模式,merged 合并,separate 独立 */
195
- mode ? : 'merged' | 'separate';
196
- /** separate 时 composedImage 使用横向拼接 */
197
- layout ? : 'auto' | 'doubleRibbons';
198
- /** 横向拼接间距,默认 50px */
199
- gap ? : number;
200
- }
201
- async function getImagePreview() {
202
- // 加载json导出 预览图, data为文件json
203
- let data = await editor.loadJsonToImageBase64(data: fileJson,
204
- config: LoadJsonToImageBase64Options)
306
+
307
+ // 加载字体 Blob 到编辑器
308
+ await editorInstance.loadFontFile({ fontName: 'HanSans', blob: fontBlob })
309
+ ```
310
+
311
+ #### 激光配置
312
+
313
+ ```js
314
+ // 设置外部激光预设列表,详见「激光配置」章节
315
+ editorInstance.setLaserConfigList([...])
316
+ ```
317
+
318
+ ### 静态方法
319
+
320
+ ```js
321
+ // 从 JSON 数据直接导出图片(无 DOM 渲染)
322
+ const base64 = await LabelEditor.loadJsonToImageBase64(fileJson, {
323
+ cmds: [{ cmd: 'ReplaceContent', name: '姓名', content: '张三' }],
324
+ timeout: 5000,
325
+ })
326
+
327
+ // 静态导出方法,与实例 exportImage 相同但需要传入 data 字段
328
+ const result = await LabelEditor.exportImage({
329
+ data: fileJson,
330
+ mode: 'separate',
331
+ layout: 'doubleRibbons',
332
+ })
333
+ ```
334
+
335
+ ### 类型定义
336
+
337
+ ```ts
338
+ type ExportImageMode = 'merged' | 'separate'
339
+ type ExportImageLayout = 'auto' | 'doubleRibbons'
340
+
341
+ type ExportImageSeparateResult = {
342
+ images: string[]
343
+ composedImage: string
205
344
  }
206
- async function exportJsonSeparateImages() {
207
- let data = await editor.exportImage({
208
- data: fileJson,
209
- mode: 'separate',
210
- layout: 'doubleRibbons',
211
- })
212
- const layerImages = data.images
213
- const composedImage = data.composedImage
345
+
346
+ type ExportImageResult = string | ExportImageSeparateResult
347
+
348
+ type ExportImageOptions = {
349
+ /** 静态导出时必传,实例方法无需传入 */
350
+ data?: any
351
+ /** 导出前替换 canvas 内容的命令 */
352
+ cmds?: Array<{ cmd: string; name: string; content: string }>
353
+ /** 超时时间 (ms),默认 5000 */
354
+ timeout?: number
355
+ /** 是否返回完整 dataURL,默认 false(返回纯 base64) */
356
+ returnDataUrl?: boolean
357
+ /** 画布 DPI,不传则用文件内的 DPI */
358
+ dpi?: number
359
+ /** 标签宽度 (mm) */
360
+ width?: number
361
+ /** 标签高度 (mm) */
362
+ height?: number
363
+ /** 多图层导出模式 */
364
+ mode?: ExportImageMode
365
+ /** separate 时 composedImage 使用横向拼接 */
366
+ layout?: ExportImageLayout
367
+ /** 横向拼接间距,默认 50px */
368
+ gap?: number
214
369
  }
215
370
  ```
216
371
 
217
- ### 二级菜单项 key 参考
372
+ ---
373
+
374
+ ## 二级菜单项 key 参考
218
375
 
219
376
  通过 `enabledMenuItems`(白名单)或 `disabledMenuItems`(黑名单)控制二级菜单项的显示/隐藏,两者同时存在时白名单优先。工具(T) 菜单下的二级菜单项由 `enabledTools` / `disabledTools` 控制,无需在此重复配置。
220
377
 
@@ -235,37 +392,83 @@ async function exportJsonSeparateImages() {
235
392
 
236
393
  ---
237
394
 
238
- ## 激光配置
395
+ ## 激光配置(LaserConfig)
396
+
397
+ 激光配置是**模板级共享数据**。画布元素只存 `laserConfigId` 引用,具体参数值由预设列表提供。修改某预设会影响所有引用它的元素。
239
398
 
240
- 激光配置是模板级共享数据。元素只存 `laserConfigId` 引用,参数值由预设列表提供。修改预设影响所有引用该预设的元素。
399
+ ### 开启与数量限制
241
400
 
242
- ### 设置预设列表
401
+ 初始化时通过 `showLaser` 控制:
243
402
 
244
403
  ```js
245
- instance.setLaserConfigList([
404
+ new LabelEditor(dom, {
405
+ showLaser: 15, // >0:开启且为最大可选预设数量;0 / false:不显示(默认 0)
406
+ })
407
+ ```
408
+
409
+ ### 设置预设列表(外部传入)
410
+
411
+ 通过实例方法传入外部预设,编辑器按 `configId` 与模板预设做 diff(新增的并入模板,模板有而外部无的弹框警告):
412
+
413
+ ```js
414
+ editorInstance.setLaserConfigList([
246
415
  {
247
416
  configId: 'preset_001',
248
417
  configName: '默认参数',
249
418
  params: [
250
- { key: 'repeatTimes', label: '打标次数', min: 0, max: 10000, unit: '', defaultValue: 1, status: 1 },
419
+ { key: 'repeatTimes', label: '打标次数', min: 0, max: 10000, unit: '', defaultValue: 1, status: 0 },
251
420
  { key: 'scanSpeed', label: '激光速度', min: 0, max: 65535, unit: 'mm/s', defaultValue: 3000, status: 0 },
252
- { key: 'power', label: '功率', min: 0, max: 100, unit: '%', defaultValue: 1, status: 1 },
421
+ { key: 'jumpSpeed', label: '跳转速度', min: 0, max: 65535, unit: 'mm/s', defaultValue: 3000, status: 0 },
422
+ { key: 'power', label: '功率', min: 0, max: 100, unit: '%', defaultValue: 20, status: 1 },
423
+ { key: 'frequence', label: '频率', min: 0, max: 4000, unit: 'khz', defaultValue: 200, status: 0 },
424
+ { key: 'pulseWidth', label: '脉宽', min: 0, max: 500, unit: 'ns', defaultValue: 50, status: 0 },
425
+ { key: 'openLightDelay', label: '开光延迟', min: -1000, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
426
+ { key: 'closeLightDelay', label: '关光延迟', min: -1000, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
427
+ { key: 'endDelay', label: '结束延迟', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
428
+ { key: 'trunDelay', label: '转角延时', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
429
+ { key: 'jumpDelay', label: '跳转延时', min: 0, max: 2000, unit: 'us', defaultValue: 0, status: 0 },
253
430
  ],
254
431
  },
255
432
  ])
256
433
  ```
257
434
 
258
- ### 字段
259
-
260
- | 字段 | 类型 | 说明 |
261
- |---|---|---|
262
- | `configId` | `string` | 唯一标识,用于外部与模板预设置匹配 |
263
- | `configName` | `string` | 显示名称 |
264
- | `params` | `FieldDef[]` | 参数定义数组,每项含 key/label/min/max/unit/defaultValue/status。`status: 1` 允许输入,`status: 0` 或缺失则禁用 |
435
+ > 以上 11 个字段为编辑器内置字段(`builtInFields`)。`setLaserConfigList` 可只传入部分字段,未传入的字段不会显示;传入的字段若未带 `status`,会回退到内置默认值(见下表)。
436
+
437
+ ### 内置字段默认值
438
+
439
+ `status`:`1` 表示可编辑,`0` 或缺失表示禁用(输入框置灰)。
440
+
441
+ | key | label | min | max | unit | defaultValue | status |
442
+ | --- | --- | --- | --- | --- | --- | --- |
443
+ | `repeatTimes` | 打标次数 | 0 | 10000 | - | 1 | 0 |
444
+ | `scanSpeed` | 激光速度 | 0 | 65535 | mm/s | 3000 | 0 |
445
+ | `jumpSpeed` | 跳转速度 | 0 | 65535 | mm/s | 3000 | 0 |
446
+ | `power` | 功率 | 0 | 100 | % | 20 | 1 |
447
+ | `frequence` | 频率 | 0 | 4000 | khz | 200 | 0 |
448
+ | `pulseWidth` | 脉宽 | 0 | 500 | ns | 50 | 0 |
449
+ | `openLightDelay` | 开光延迟 | -1000 | 2000 | us | 0 | 0 |
450
+ | `closeLightDelay` | 关光延迟 | -1000 | 2000 | us | 0 | 0 |
451
+ | `endDelay` | 结束延迟 | 0 | 2000 | us | 0 | 0 |
452
+ | `trunDelay` | 转角延时 | 0 | 2000 | us | 0 | 0 |
453
+ | `jumpDelay` | 跳转延时 | 0 | 2000 | us | 0 | 0 |
454
+
455
+ ### 参数对象(FieldDef)字段说明
456
+
457
+ | 字段 | 类型 | 必填 | 说明 |
458
+ | --- | --- | --- | --- |
459
+ | `configId` | `string` | 是 | 预设唯一标识,用于外部与模板预设匹配 |
460
+ | `configName` | `string` | 是 | 预设显示名称 |
461
+ | `params` | `FieldDef[]` | 是 | 参数定义数组 |
462
+ | `key` | `string` | 是 | 字段标识,需与内置字段 key 对应(`power` 等)。非内置 key 也能显示,但不回退默认值 |
463
+ | `label` | `string` | 否 | 显示名称。若同时存在 `labelKey` 则优先走 i18n 翻译 |
464
+ | `min` / `max` | `number` | 是 | 数值范围,作用于输入框上下限 |
465
+ | `unit` | `string` | 否 | 单位后缀(`mm/s`、`%` 等),空则不显示 |
466
+ | `defaultValue` | `number` | 是 | 选中该预设时回填到输入框的初始值 |
467
+ | `status` | `number` | 否 | `1` 可编辑;`0` 或缺失则禁用,缺失时回退到内置 `status` |
265
468
 
266
469
  ### 数据流
267
470
 
268
- - **外部传入** -- configId 匹配已存在的保留本地值不覆盖,不匹配的加入模板,模板有外部无的弹框警告
269
- - **保存** -- 只导出画布实际引用的预设(configId 去重)
270
- - **重新打开** -- loadJson 恢复模板预设, syncExternalPresets 做 diff
271
- - **限制** -- showLaser 限制画布实际引用的预设种类数,超出弹框警告
471
+ - **外部传入** -- `setLaserConfigList` 按 `configId` 与模板预设做 diff:外部有、模板无 → 并入模板;模板有、外部无 → 弹框警告
472
+ - **保存** -- 只导出画布实际引用的预设(`configId` 去重后的列表)
473
+ - **重新打开** -- `loadJson` 恢复模板预设,再执行 `syncExternalPresets` 做 diff
474
+ - **限制** -- `showLaser` 限制画布实际引用的预设**种类数**,超出弹框警告