@jnrs/lingshu-smart 2.2.25 → 2.2.28
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/AGENTS.md +689 -0
- package/README.md +4 -40
- package/dist/components/index.js +4 -4
- package/dist/controller/AppController.d.ts +4 -0
- package/dist/{index-32uj9JyT.js → index-tpebqVjC.js} +6960 -6222
- package/dist/index.js +1 -1
- package/dist/json/cases.json +553 -449
- package/dist/playground/mockWebSocketData.d.ts +0 -4
- package/dist/types/components/config.types.d.ts +1 -0
- package/dist/types/enums.d.ts +0 -5
- package/dist/types/models/config.types.d.ts +14 -1
- package/dist/types/models/operating.types.d.ts +12 -1
- package/dist/ui/abstract/ModelAbs.d.ts +2 -0
- package/dist/ui/components/Entrance.d.ts +4 -12
- package/dist/ui/models/DoubleJointRobot.d.ts +6 -3
- package/dist/ui/models/Rgv.d.ts +32 -0
- package/dist/ui/models/SingleJointRobot.d.ts +4 -1
- package/dist/ui/utils/attr.d.ts +5 -0
- package/package.json +2 -2
- package/AGENTIC.md +0 -1048
package/AGENTIC.md
DELETED
|
@@ -1,1048 +0,0 @@
|
|
|
1
|
-
# @jnrs/lingshu-smart API 文档
|
|
2
|
-
|
|
3
|
-
## ✨ 介绍
|
|
4
|
-
|
|
5
|
-
巨能前端 2D 数字孪生库,灵枢智造。提供 2D 数字孪生编辑器和运行看板功能,基于 LeaferJS 引擎构建。
|
|
6
|
-
|
|
7
|
-
## 📦 模块总览
|
|
8
|
-
|
|
9
|
-
| 模块路径 | 说明 |
|
|
10
|
-
| --------------------------------- | ------------------------------ |
|
|
11
|
-
| `@jnrs/lingshu-smart` | 主模块,包含类型定义和工具函数 |
|
|
12
|
-
| `@jnrs/lingshu-smart/components` | Vue 组件库(编辑器、预览器) |
|
|
13
|
-
| `@jnrs/lingshu-smart/stores` | Pinia 状态管理 |
|
|
14
|
-
| `@jnrs/lingshu-smart/composables` | Vue 组合式 API |
|
|
15
|
-
| `@jnrs/lingshu-smart/controller` | 控制器类 |
|
|
16
|
-
| `@jnrs/lingshu-smart/types` | TypeScript 类型定义 |
|
|
17
|
-
| `@jnrs/lingshu-smart/utils` | 工具函数 |
|
|
18
|
-
| `@jnrs/lingshu-smart/constants` | 常量配置 |
|
|
19
|
-
| `@jnrs/lingshu-smart/ui` | UI 模型和工厂 |
|
|
20
|
-
| `@jnrs/lingshu-smart/locales` | 国际化配置 |
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 📋 API 详情
|
|
25
|
-
|
|
26
|
-
### @jnrs/lingshu-smart 主模块
|
|
27
|
-
|
|
28
|
-
#### 类型导出
|
|
29
|
-
|
|
30
|
-
从主模块导出的所有类型:
|
|
31
|
-
|
|
32
|
-
##### 枚举 (Enums)
|
|
33
|
-
|
|
34
|
-
###### EnumStepType
|
|
35
|
-
|
|
36
|
-
步骤操作类型
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
enum EnumStepType {
|
|
40
|
-
UNDO = 'Undo', // 撤销
|
|
41
|
-
REDO = 'Redo' // 重做
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
###### EnumTag
|
|
46
|
-
|
|
47
|
-
设备标签枚举
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
enum EnumTag {
|
|
51
|
-
TRANSPORT = '搬运设备',
|
|
52
|
-
MACHINE = '机床',
|
|
53
|
-
CLEANING = '清洗机',
|
|
54
|
-
STATION = '装载站',
|
|
55
|
-
STORAGE = '库',
|
|
56
|
-
OTHER = '其他'
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
###### EnumModel
|
|
61
|
-
|
|
62
|
-
设备类型枚举
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
enum EnumModel {
|
|
66
|
-
SINGLE_JOINT_ROBOT = 'SingleJointRobot', // 单关节机器人
|
|
67
|
-
DOUBLE_JOINT_ROBOT = 'DoubleJointRobot', // 双关节机器人
|
|
68
|
-
RGV = 'Rgv', // RGV
|
|
69
|
-
MACHINE_TOOL = 'MachineTool', // 机床
|
|
70
|
-
MARKING_MACHINE = 'MarkingMachine', // 打标机
|
|
71
|
-
CLEANING_MACHINE = 'CleaningMachine', // 清洗机
|
|
72
|
-
LOADING_STATION = 'LoadingStation', // 上料站
|
|
73
|
-
PALLET_STORAGE = 'PalletStorage', // 托盘库
|
|
74
|
-
TOOL_STORAGE = 'ToolStorage', // 刀具库
|
|
75
|
-
BUFFER_DOCK = 'BufferDock', // 缓冲站
|
|
76
|
-
GROUND_RAIL = 'GroundRail', // 地轨
|
|
77
|
-
FOLLOWING_TUGGER = 'FollowingTugger', // 跟随牵引车
|
|
78
|
-
RAIL = 'Rail', // 轨道
|
|
79
|
-
RESOURCE_STORE = 'ResourceStore' // 资源库
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
###### EnumComponent
|
|
84
|
-
|
|
85
|
-
组件类型枚举
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
enum EnumComponent {
|
|
89
|
-
STATION_SLOT = 'StationSlot', // 工位槽
|
|
90
|
-
RESOURCE = 'Resource' // 资源
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
###### EnumResourceType
|
|
95
|
-
|
|
96
|
-
资源类型枚举
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
enum EnumResourceType {
|
|
100
|
-
PALLET = 'Pallet', // 托盘
|
|
101
|
-
TOOL = 'Tool' // 刀具
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
###### EnumInteractiveUi
|
|
106
|
-
|
|
107
|
-
可交互设备类型
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
type EnumInteractiveUi = EnumModel | EnumComponent
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
##### 核心类型 (Core Types)
|
|
114
|
-
|
|
115
|
-
###### IScene
|
|
116
|
-
|
|
117
|
-
场景配置
|
|
118
|
-
|
|
119
|
-
| 属性名 | 类型 | 必填 | 说明 |
|
|
120
|
-
| -------------- | ----------------- | ---- | -------------------------------- |
|
|
121
|
-
| width | `number` | ✓ | 场景宽度 |
|
|
122
|
-
| height | `number` | ✓ | 场景高度 |
|
|
123
|
-
| runtime_width | `number` | - | 运行时宽度(业务数据) |
|
|
124
|
-
| runtime_height | `number` | - | 运行时高度(业务数据) |
|
|
125
|
-
| zoomType | `'fit' \| number` | ✓ | 缩放类型:'fit' 自适应或具体数值 |
|
|
126
|
-
| fill | `FillConfig` | - | 背景填充配置 |
|
|
127
|
-
| texture | `string` | - | 纹理图片 URL |
|
|
128
|
-
|
|
129
|
-
**FillConfig 类型:**
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
interface FillConfig {
|
|
133
|
-
type: 'solid' | 'linear' | 'radial' | 'image'
|
|
134
|
-
color: string
|
|
135
|
-
opacity: number
|
|
136
|
-
stops: { offset: number; color: string }[]
|
|
137
|
-
url?: string
|
|
138
|
-
from?: string
|
|
139
|
-
to?: string
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
###### ICase
|
|
144
|
-
|
|
145
|
-
方案(案例)
|
|
146
|
-
|
|
147
|
-
| 属性名 | 类型 | 必填 | 说明 |
|
|
148
|
-
| -------- | ---------- | ---- | ------------------ |
|
|
149
|
-
| uuid | `string` | ✓ | 唯一标识 |
|
|
150
|
-
| isActive | `boolean` | ✓ | 是否为当前激活方案 |
|
|
151
|
-
| title | `string` | ✓ | 方案标题 |
|
|
152
|
-
| scene | `IScene` | ✓ | 场景配置 |
|
|
153
|
-
| layers | `ILayer[]` | ✓ | 图层列表 |
|
|
154
|
-
|
|
155
|
-
###### ILayer
|
|
156
|
-
|
|
157
|
-
图层基类
|
|
158
|
-
|
|
159
|
-
**说明:** ILayer 是图层的基类,具体实现包括 IModel(设备模型)、IStationSlotConfig(工位槽配置)、IResourceConfig(资源配置)等。
|
|
160
|
-
|
|
161
|
-
###### InteractiveUi
|
|
162
|
-
|
|
163
|
-
可交互设备类型
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
type InteractiveUi = ILayer | IStationSlotConfig | IResourceConfig
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
###### IEventHandler
|
|
170
|
-
|
|
171
|
-
事件处理器
|
|
172
|
-
|
|
173
|
-
| 属性名 | 类型 | 说明 |
|
|
174
|
-
| --------- | ---------------------------------------------- | ------------------------- |
|
|
175
|
-
| onTap | `(layer: ILayer, data: InteractiveUi) => void` | 快速点击事件(左键单击) |
|
|
176
|
-
| onMenuTap | `(layer: ILayer, data: InteractiveUi) => void` | 右键 tap 事件(右键单击) |
|
|
177
|
-
| onDragEnd | `(layer: ILayer, data: InteractiveUi) => void` | 拖动结束事件 |
|
|
178
|
-
|
|
179
|
-
###### IContainer
|
|
180
|
-
|
|
181
|
-
容器配置
|
|
182
|
-
|
|
183
|
-
| 属性名 | 类型 | 默认值 | 说明 |
|
|
184
|
-
| ------------- | ----------------------- | --------- | ---------------------- |
|
|
185
|
-
| appDomId | `string \| HTMLElement` | — | APP 容器 DOM ID 或元素 |
|
|
186
|
-
| autoStart | `boolean` | `true` | 是否自动启动引擎 |
|
|
187
|
-
| appHittable | `boolean` | `true` | APP 是否可交互 |
|
|
188
|
-
| appEditable | `boolean` | `false` | APP 是否可编辑状态 |
|
|
189
|
-
| appFill | `string` | `#424242` | APP 背景填充颜色 |
|
|
190
|
-
| hideSceneFill | `boolean` | `false` | 隐藏场景背景填充 |
|
|
191
|
-
| actions | `IEventHandler` | — | 事件处理配置 |
|
|
192
|
-
|
|
193
|
-
##### 工具函数 (Utils)
|
|
194
|
-
|
|
195
|
-
###### numberLoopGenerator
|
|
196
|
-
|
|
197
|
-
数字生成器
|
|
198
|
-
|
|
199
|
-
**参数:**
|
|
200
|
-
|
|
201
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
202
|
-
| ---------- | --------- | ------- | ------------ |
|
|
203
|
-
| start | `number` | — | 起始值 |
|
|
204
|
-
| end | `number` | — | 结束值 |
|
|
205
|
-
| shouldLoop | `boolean` | `false` | 是否无限循环 |
|
|
206
|
-
|
|
207
|
-
**返回值:** `Generator<number>` - 数字生成器
|
|
208
|
-
|
|
209
|
-
**使用示例:**
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
import { numberLoopGenerator } from '@jnrs/lingshu-smart'
|
|
213
|
-
|
|
214
|
-
const gen = numberLoopGenerator(1, 10, false)
|
|
215
|
-
for (const num of gen) {
|
|
216
|
-
console.log(num) // 1, 2, 3, ..., 10
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
###### linearIncrease
|
|
221
|
-
|
|
222
|
-
在 n 秒内把变量从值 x 线性递增到 y
|
|
223
|
-
|
|
224
|
-
**参数:**
|
|
225
|
-
|
|
226
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
227
|
-
| -------- | --------------------------------- | ------ | -------------- |
|
|
228
|
-
| x | `number` | `0` | 初始值 |
|
|
229
|
-
| y | `number` | `100` | 结束值 |
|
|
230
|
-
| n | `number` | `3` | 递增时长(秒) |
|
|
231
|
-
| rate | `number` | `300` | 帧率(ms) |
|
|
232
|
-
| callback | `(val: number \| string) => void` | — | 回调函数 |
|
|
233
|
-
|
|
234
|
-
**返回值:** `Promise<void>`
|
|
235
|
-
|
|
236
|
-
**使用示例:**
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
import { linearIncrease } from '@jnrs/lingshu-smart'
|
|
240
|
-
|
|
241
|
-
await linearIncrease(0, 100, 3, 300, (val) => {
|
|
242
|
-
console.log('当前值:', val)
|
|
243
|
-
})
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
###### transPercentAndPixel
|
|
247
|
-
|
|
248
|
-
根据百分比数字转换为像素,或者根据像素转换为百分比
|
|
249
|
-
|
|
250
|
-
**参数:**
|
|
251
|
-
|
|
252
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
253
|
-
| ---------- | --------- | ------- | --------------------------- |
|
|
254
|
-
| val | `number` | — | 百分比数字(0~1)或像素数字 |
|
|
255
|
-
| size | `number` | — | 尺寸,用于计算百分比 |
|
|
256
|
-
| precision | `number` | `3` | 保留的小数位数 |
|
|
257
|
-
| getPercent | `boolean` | `false` | 是否返回百分比 |
|
|
258
|
-
|
|
259
|
-
**返回值:** `number` - 转换后的值
|
|
260
|
-
|
|
261
|
-
**使用示例:**
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
import { transPercentAndPixel } from '@jnrs/lingshu-smart'
|
|
265
|
-
|
|
266
|
-
// 百分比转像素
|
|
267
|
-
const pixel = transPercentAndPixel(0.5, 1920, 0, false) // 960
|
|
268
|
-
|
|
269
|
-
// 像素转百分比
|
|
270
|
-
const percent = transPercentAndPixel(960, 1920, 3, true) // 0.5
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
###### transFraction
|
|
274
|
-
|
|
275
|
-
百分比转换小数
|
|
276
|
-
|
|
277
|
-
**参数:**
|
|
278
|
-
|
|
279
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
280
|
-
| ------ | -------- | ------ | ---- |
|
|
281
|
-
| val | `number` | — | 值 |
|
|
282
|
-
| size | `number` | — | 尺寸 |
|
|
283
|
-
|
|
284
|
-
**返回值:** `number` - 转换后的小数
|
|
285
|
-
|
|
286
|
-
###### transRuntimeToPixel
|
|
287
|
-
|
|
288
|
-
运行时数值转换为像素数值
|
|
289
|
-
|
|
290
|
-
**参数:**
|
|
291
|
-
|
|
292
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
293
|
-
| --------- | --------------------- | --------- | ---------- |
|
|
294
|
-
| val | `number` | — | 运行时数值 |
|
|
295
|
-
| precision | `number` | `0` | 精度 |
|
|
296
|
-
| type | `'width' \| 'height'` | `'width'` | 类型 |
|
|
297
|
-
|
|
298
|
-
**返回值:** `number` - 像素数值
|
|
299
|
-
|
|
300
|
-
**注意:** 此函数依赖 `useEditorStore`,仅在编辑器环境中可用。
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
### @jnrs/lingshu-smart/components 模块
|
|
305
|
-
|
|
306
|
-
#### LingshuSmartEditor
|
|
307
|
-
|
|
308
|
-
编辑器组件,提供 2D 数字孪生方案的可视化编辑功能。
|
|
309
|
-
|
|
310
|
-
**Props:**
|
|
311
|
-
|
|
312
|
-
| 属性名 | 类型 | 默认值 | 说明 |
|
|
313
|
-
| ------- | --------------- | ------ | ------------ |
|
|
314
|
-
| actions | `EditorActions` | `{}` | 事件处理配置 |
|
|
315
|
-
|
|
316
|
-
**EditorActions 接口:**
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
interface EditorActions {
|
|
320
|
-
/**
|
|
321
|
-
* 加载案例列表
|
|
322
|
-
* @param id - 可选的案例 ID
|
|
323
|
-
* @returns Promise<ICase[]>
|
|
324
|
-
*/
|
|
325
|
-
loadCases?: (id?: string) => Promise<ICase[]>
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* 保存方案列表
|
|
329
|
-
* @param cases - 方案列表
|
|
330
|
-
*/
|
|
331
|
-
saveCases?: (cases?: ICase[]) => void
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* 跳转到预览页面
|
|
335
|
-
* @param currentCase - 当前方案
|
|
336
|
-
*/
|
|
337
|
-
handlePreview?: (currentCase?: ICase) => void
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* 退出当前页面
|
|
341
|
-
*/
|
|
342
|
-
handleExit?: () => void
|
|
343
|
-
}
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
**使用示例:**
|
|
347
|
-
|
|
348
|
-
```vue
|
|
349
|
-
<template>
|
|
350
|
-
<LingshuSmartEditor :actions="editorActions" />
|
|
351
|
-
</template>
|
|
352
|
-
|
|
353
|
-
<script setup>
|
|
354
|
-
import { LingshuSmartEditor } from '@jnrs/lingshu-smart/components'
|
|
355
|
-
|
|
356
|
-
const editorActions = {
|
|
357
|
-
async loadCases(id) {
|
|
358
|
-
const res = await fetch(`/api/cases/${id || ''}`)
|
|
359
|
-
return res.json()
|
|
360
|
-
},
|
|
361
|
-
saveCases(cases) {
|
|
362
|
-
fetch('/api/cases', {
|
|
363
|
-
method: 'POST',
|
|
364
|
-
body: JSON.stringify(cases)
|
|
365
|
-
})
|
|
366
|
-
},
|
|
367
|
-
handlePreview(currentCase) {
|
|
368
|
-
window.open(`/preview/${currentCase.uuid}`)
|
|
369
|
-
},
|
|
370
|
-
handleExit() {
|
|
371
|
-
window.history.back()
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
</script>
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
**功能特性:**
|
|
378
|
-
|
|
379
|
-
- 左侧菜单卡片:设备库、图层管理
|
|
380
|
-
- 中间画布:可视化编辑区域
|
|
381
|
-
- 右侧选项卡片:属性配置面板
|
|
382
|
-
- 顶部控制栏:方案标题编辑、方案管理、步骤记录(撤销/重做)
|
|
383
|
-
- 支持拖拽、缩放、旋转等操作
|
|
384
|
-
- 自动保存和版本管理
|
|
385
|
-
|
|
386
|
-
---
|
|
387
|
-
|
|
388
|
-
#### LingshuSmartPreview
|
|
389
|
-
|
|
390
|
-
预览组件,用于运行和展示 2D 数字孪生方案。
|
|
391
|
-
|
|
392
|
-
**Props:**
|
|
393
|
-
|
|
394
|
-
| 属性名 | 类型 | 默认值 | 说明 |
|
|
395
|
-
| ------------- | ---------------- | --------- | --------------------- |
|
|
396
|
-
| caseUuid | `string` | — | 案例 UUID(Required) |
|
|
397
|
-
| actions | `PreviewActions` | `{}` | 事件处理配置 |
|
|
398
|
-
| appHittable | `boolean` | `true` | app 是否可交互 |
|
|
399
|
-
| appFill | `string` | `#424242` | app 容器填充色 |
|
|
400
|
-
| hideSceneFill | `boolean` | `false` | 隐藏场景填充色 |
|
|
401
|
-
|
|
402
|
-
**PreviewActions 接口:**
|
|
403
|
-
|
|
404
|
-
```typescript
|
|
405
|
-
interface PreviewActions {
|
|
406
|
-
/**
|
|
407
|
-
* 加载案例列表
|
|
408
|
-
* @param id - 可选的案例 ID
|
|
409
|
-
* @returns Promise<ICase[]>
|
|
410
|
-
*/
|
|
411
|
-
loadCases?: (id?: string) => Promise<ICase[]>
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 点击事件
|
|
415
|
-
* @param layer - 图层
|
|
416
|
-
* @param data - 设备信息
|
|
417
|
-
*/
|
|
418
|
-
onTap?: (layer: ILayer, data: InteractiveUi) => void
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* 右键点击事件
|
|
422
|
-
* @param layer - 图层
|
|
423
|
-
* @param data - 设备信息
|
|
424
|
-
*/
|
|
425
|
-
onMenuTap?: (layer: ILayer, data: InteractiveUi) => void
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* 拖拽结束事件
|
|
429
|
-
* @param layer - 图层
|
|
430
|
-
* @param data - 设备信息
|
|
431
|
-
*/
|
|
432
|
-
onDragEnd?: (layer: ILayer, data: InteractiveUi) => void
|
|
433
|
-
}
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
**使用示例:**
|
|
437
|
-
|
|
438
|
-
```vue
|
|
439
|
-
<template>
|
|
440
|
-
<LingshuSmartPreview :case-uuid="caseUuid" :actions="previewActions" />
|
|
441
|
-
</template>
|
|
442
|
-
|
|
443
|
-
<script setup>
|
|
444
|
-
import { ref } from 'vue'
|
|
445
|
-
import { LingshuSmartPreview } from '@jnrs/lingshu-smart/components'
|
|
446
|
-
|
|
447
|
-
const caseUuid = ref('abc-123-def')
|
|
448
|
-
|
|
449
|
-
const previewActions = {
|
|
450
|
-
async loadCases() {
|
|
451
|
-
const res = await fetch('/api/cases')
|
|
452
|
-
return res.json()
|
|
453
|
-
},
|
|
454
|
-
onTap(layer, data) {
|
|
455
|
-
console.log('点击设备:', data)
|
|
456
|
-
},
|
|
457
|
-
onMenuTap(layer, data) {
|
|
458
|
-
console.log('右键点击:', data)
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
</script>
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
**功能特性:**
|
|
465
|
-
|
|
466
|
-
- 只读模式,不支持编辑
|
|
467
|
-
- 支持设备点击、右键菜单交互
|
|
468
|
-
- 自适应窗口大小
|
|
469
|
-
- 自动加载指定案例
|
|
470
|
-
- 支持自定义事件回调
|
|
471
|
-
|
|
472
|
-
---
|
|
473
|
-
|
|
474
|
-
### @jnrs/lingshu-smart/stores 模块
|
|
475
|
-
|
|
476
|
-
#### useDataStore
|
|
477
|
-
|
|
478
|
-
数据仓库,管理设备菜单、方案列表等全局数据。
|
|
479
|
-
|
|
480
|
-
**返回值:**
|
|
481
|
-
|
|
482
|
-
| 属性/方法 | 类型 | 说明 |
|
|
483
|
-
| -------------- | ---------------------------------------------- | ---------------- |
|
|
484
|
-
| equipmentsMenu | `Ref<IEquipmentsMenu[]>` | 设备菜单(预设) |
|
|
485
|
-
| cases | `Ref<ICase[] \| undefined>` | 方案列表 |
|
|
486
|
-
| casesLoading | `Ref<boolean>` | 方案加载状态 |
|
|
487
|
-
| updateCases | `(data?: ICase[]) => void` | 更新方案列表 |
|
|
488
|
-
| selectCase | `(uuid: string) => void` | 切换当前方案 |
|
|
489
|
-
| addCase | `(data?: ICase) => void` | 添加方案 |
|
|
490
|
-
| removeCase | `(uuid: string) => void` | 删除方案 |
|
|
491
|
-
| updateCase | `(uuid: string, data: Partial<ICase>) => void` | 更新方案 |
|
|
492
|
-
|
|
493
|
-
**使用示例:**
|
|
494
|
-
|
|
495
|
-
```typescript
|
|
496
|
-
import { useDataStore } from '@jnrs/lingshu-smart/stores'
|
|
497
|
-
|
|
498
|
-
const dataStore = useDataStore()
|
|
499
|
-
|
|
500
|
-
// 更新方案列表
|
|
501
|
-
dataStore.updateCases([
|
|
502
|
-
{
|
|
503
|
-
uuid: 'case-1',
|
|
504
|
-
title: '方案1',
|
|
505
|
-
isActive: true,
|
|
506
|
-
scene: {
|
|
507
|
-
/* ... */
|
|
508
|
-
},
|
|
509
|
-
layers: []
|
|
510
|
-
}
|
|
511
|
-
])
|
|
512
|
-
|
|
513
|
-
// 切换方案
|
|
514
|
-
dataStore.selectCase('case-1')
|
|
515
|
-
|
|
516
|
-
// 添加新方案
|
|
517
|
-
dataStore.addCase({
|
|
518
|
-
uuid: '',
|
|
519
|
-
title: '新方案',
|
|
520
|
-
isActive: false,
|
|
521
|
-
scene: {
|
|
522
|
-
/* ... */
|
|
523
|
-
},
|
|
524
|
-
layers: []
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
// 访问方案列表
|
|
528
|
-
console.log(dataStore.cases.value)
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
---
|
|
532
|
-
|
|
533
|
-
#### useEditorStore
|
|
534
|
-
|
|
535
|
-
编辑器仓库,管理编辑器实例、当前方案、场景、图层等状态。
|
|
536
|
-
|
|
537
|
-
**返回值:**
|
|
538
|
-
|
|
539
|
-
| 属性/方法 | 类型 | 说明 |
|
|
540
|
-
| ---------------- | ----------------------------------------------- | ---------------------- |
|
|
541
|
-
| currentCase | `ComputedRef<ICase \| null>` | 当前选择的方案 |
|
|
542
|
-
| scene | `ComputedRef<IScene \| null>` | 当前方案场景 |
|
|
543
|
-
| layers | `ComputedRef<ILayer[]>` | 当前方案图层列表 |
|
|
544
|
-
| currentLayer | `ComputedRef<ILayer \| null>` | 当前选择的图层 |
|
|
545
|
-
| initContainer | `(options: IContainer) => void` | 初始化容器(引擎实例) |
|
|
546
|
-
| updateScene | `() => void` | 修改场景(防抖) |
|
|
547
|
-
| addLayer | `(layer: ILayer) => void` | 添加图层 |
|
|
548
|
-
| removeLayer | `(uuid: string) => void` | 删除图层 |
|
|
549
|
-
| updateLayer | `(uuid: string, data: Partial<ILayer>) => void` | 更新图层 |
|
|
550
|
-
| selectLayer | `(uuid: string) => void` | 选择图层 |
|
|
551
|
-
| resizeContainer | `() => void` | 重置容器大小 |
|
|
552
|
-
| destroyContainer | `() => void` | 销毁容器 |
|
|
553
|
-
| operating | `Ref<ILayerOperating \| null>` | 当前操作状态 |
|
|
554
|
-
|
|
555
|
-
**使用示例:**
|
|
556
|
-
|
|
557
|
-
```typescript
|
|
558
|
-
import { useEditorStore } from '@jnrs/lingshu-smart/stores'
|
|
559
|
-
|
|
560
|
-
const editorStore = useEditorStore()
|
|
561
|
-
|
|
562
|
-
// 初始化容器
|
|
563
|
-
editorStore.initContainer({
|
|
564
|
-
appDomId: 'editor-app',
|
|
565
|
-
appEditable: true,
|
|
566
|
-
actions: {
|
|
567
|
-
onTap: (layer, data) => {
|
|
568
|
-
console.log('点击图层', layer)
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
})
|
|
572
|
-
|
|
573
|
-
// 添加图层
|
|
574
|
-
editorStore.addLayer({
|
|
575
|
-
uuid: 'layer-1',
|
|
576
|
-
equipmentName: '机器人',
|
|
577
|
-
x: 100,
|
|
578
|
-
y: 100,
|
|
579
|
-
width: 200,
|
|
580
|
-
height: 200
|
|
581
|
-
// ... 其他属性
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
// 选择图层
|
|
585
|
-
editorStore.selectLayer('layer-1')
|
|
586
|
-
|
|
587
|
-
// 访问当前方案
|
|
588
|
-
console.log(editorStore.currentCase.value)
|
|
589
|
-
console.log(editorStore.scene.value)
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
---
|
|
593
|
-
|
|
594
|
-
#### useAppStore
|
|
595
|
-
|
|
596
|
-
应用仓库,用于预览模式的容器管理。
|
|
597
|
-
|
|
598
|
-
**返回值:**
|
|
599
|
-
|
|
600
|
-
| 属性/方法 | 类型 | 说明 |
|
|
601
|
-
| ---------------- | ------------------------------------------------- | ------------------------ |
|
|
602
|
-
| currentCase | `ComputedRef<ICase \| null>` | 当前方案 |
|
|
603
|
-
| initContainer | `(options: IContainer, caseUuid: string) => void` | 初始化容器并加载指定案例 |
|
|
604
|
-
| resizeContainer | `() => void` | 重置容器大小 |
|
|
605
|
-
| destroyContainer | `() => void` | 销毁容器 |
|
|
606
|
-
| operating | `Ref<ILayerOperating \| null>` | 当前操作状态 |
|
|
607
|
-
|
|
608
|
-
**使用示例:**
|
|
609
|
-
|
|
610
|
-
```typescript
|
|
611
|
-
import { useAppStore } from '@jnrs/lingshu-smart/stores'
|
|
612
|
-
|
|
613
|
-
const appStore = useAppStore()
|
|
614
|
-
|
|
615
|
-
// 初始化预览容器
|
|
616
|
-
appStore.initContainer(
|
|
617
|
-
{
|
|
618
|
-
appDomId: 'preview-app',
|
|
619
|
-
appEditable: false,
|
|
620
|
-
actions: {
|
|
621
|
-
onTap: (layer, data) => {
|
|
622
|
-
console.log('点击设备', data)
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
'case-uuid-123'
|
|
627
|
-
)
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
---
|
|
631
|
-
|
|
632
|
-
### @jnrs/lingshu-smart/composables 模块
|
|
633
|
-
|
|
634
|
-
#### useStepRecord
|
|
635
|
-
|
|
636
|
-
编辑操作记录 Hook,提供撤销/重做功能。
|
|
637
|
-
|
|
638
|
-
**返回值:**
|
|
639
|
-
|
|
640
|
-
| 返回值 | 类型 | 说明 |
|
|
641
|
-
| --------------------- | ----------------------------------------------------------------------------------------------- | ---------------------- |
|
|
642
|
-
| operationRecordStatus | `ComputedRef<{ canUndo: boolean; canRedo: boolean; totalSteps: number; currentIndex: number }>` | 操作记录状态 |
|
|
643
|
-
| recordOperation | `(caseData: ICase[], hash: string) => void` | 记录操作(防抖 300ms) |
|
|
644
|
-
| undo | `() => void` | 撤销操作 |
|
|
645
|
-
| redo | `() => void` | 重做操作 |
|
|
646
|
-
| jumpToStep | `(index: number) => void` | 跳转到任意历史点 |
|
|
647
|
-
| clearRecord | `() => void` | 清空记录 |
|
|
648
|
-
|
|
649
|
-
**使用示例:**
|
|
650
|
-
|
|
651
|
-
```typescript
|
|
652
|
-
import { useStepRecord } from '@jnrs/lingshu-smart/composables'
|
|
653
|
-
|
|
654
|
-
const { operationRecordStatus, recordOperation, undo, redo, jumpToStep } = useStepRecord()
|
|
655
|
-
|
|
656
|
-
// 检查是否可以撤销/重做
|
|
657
|
-
console.log(operationRecordStatus.value.canUndo)
|
|
658
|
-
console.log(operationRecordStatus.value.canRedo)
|
|
659
|
-
|
|
660
|
-
// 记录操作(通常在数据变更后调用)
|
|
661
|
-
import objectHash from 'object-hash'
|
|
662
|
-
const hash = objectHash(cases.value)
|
|
663
|
-
recordOperation(cases.value, hash)
|
|
664
|
-
|
|
665
|
-
// 撤销
|
|
666
|
-
undo()
|
|
667
|
-
|
|
668
|
-
// 重做
|
|
669
|
-
redo()
|
|
670
|
-
|
|
671
|
-
// 跳转到第 5 步
|
|
672
|
-
jumpToStep(5)
|
|
673
|
-
```
|
|
674
|
-
|
|
675
|
-
**特性:**
|
|
676
|
-
|
|
677
|
-
- 最多保存 10 条操作记录
|
|
678
|
-
- 防抖处理(300ms),避免频繁记录
|
|
679
|
-
- 支持跳转到任意历史点
|
|
680
|
-
- 自动检测数据变化,避免重复记录
|
|
681
|
-
- TODO: 未来可迁移至 IndexedDB 以支持持久化
|
|
682
|
-
|
|
683
|
-
---
|
|
684
|
-
|
|
685
|
-
### @jnrs/lingshu-smart/controller 模块
|
|
686
|
-
|
|
687
|
-
#### AppController
|
|
688
|
-
|
|
689
|
-
主画布、模型容器控制器,基于 LeaferJS 引擎。
|
|
690
|
-
|
|
691
|
-
**构造函数:**
|
|
692
|
-
|
|
693
|
-
```typescript
|
|
694
|
-
constructor(options: IContainer = {})
|
|
695
|
-
```
|
|
696
|
-
|
|
697
|
-
**参数:**
|
|
698
|
-
|
|
699
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
700
|
-
| ------- | ------------ | ------ | -------- |
|
|
701
|
-
| options | `IContainer` | `{}` | 容器配置 |
|
|
702
|
-
|
|
703
|
-
**方法:**
|
|
704
|
-
|
|
705
|
-
###### start
|
|
706
|
-
|
|
707
|
-
启动/重启引擎
|
|
708
|
-
|
|
709
|
-
**返回值:** `void`
|
|
710
|
-
|
|
711
|
-
###### destroy
|
|
712
|
-
|
|
713
|
-
销毁引擎(异步销毁,不会立即执行)
|
|
714
|
-
|
|
715
|
-
**返回值:** `void`
|
|
716
|
-
|
|
717
|
-
###### setZoom
|
|
718
|
-
|
|
719
|
-
控制视图的缩放
|
|
720
|
-
|
|
721
|
-
**参数:**
|
|
722
|
-
|
|
723
|
-
| 参数名 | 类型 | 默认值 | 说明 |
|
|
724
|
-
| -------- | ----------------- | ------- | -------------- |
|
|
725
|
-
| zoomType | `'fit' \| number` | `'fit'` | 缩放类型 |
|
|
726
|
-
| duration | `number` | `0.5` | 动画时长(秒) |
|
|
727
|
-
|
|
728
|
-
**返回值:** `void`
|
|
729
|
-
|
|
730
|
-
###### setTree
|
|
731
|
-
|
|
732
|
-
修改 tree 配置
|
|
733
|
-
|
|
734
|
-
**参数:**
|
|
735
|
-
|
|
736
|
-
| 参数名 | 类型 | 说明 |
|
|
737
|
-
| ------ | -------- | ------------------------------ |
|
|
738
|
-
| data | `IScene` | 场景配置,不传则重置为默认配置 |
|
|
739
|
-
|
|
740
|
-
**返回值:** `void`
|
|
741
|
-
|
|
742
|
-
###### getTreeElements
|
|
743
|
-
|
|
744
|
-
tree 层查找元素
|
|
745
|
-
|
|
746
|
-
**返回值:** `Array` - 元素数组
|
|
747
|
-
|
|
748
|
-
###### addModel
|
|
749
|
-
|
|
750
|
-
添加模型到画布
|
|
751
|
-
|
|
752
|
-
**参数:**
|
|
753
|
-
|
|
754
|
-
| 参数名 | 类型 | 说明 |
|
|
755
|
-
| ------ | -------- | -------- |
|
|
756
|
-
| layer | `ILayer` | 图层数据 |
|
|
757
|
-
|
|
758
|
-
**返回值:** `ModelAbs` - 模型实例
|
|
759
|
-
|
|
760
|
-
###### removeModel
|
|
761
|
-
|
|
762
|
-
从画布移除模型
|
|
763
|
-
|
|
764
|
-
**参数:**
|
|
765
|
-
|
|
766
|
-
| 参数名 | 类型 | 说明 |
|
|
767
|
-
| ------ | -------- | --------- |
|
|
768
|
-
| uuid | `string` | 图层 UUID |
|
|
769
|
-
|
|
770
|
-
**返回值:** `void`
|
|
771
|
-
|
|
772
|
-
###### updateModel
|
|
773
|
-
|
|
774
|
-
更新模型属性
|
|
775
|
-
|
|
776
|
-
**参数:**
|
|
777
|
-
|
|
778
|
-
| 参数名 | 类型 | 说明 |
|
|
779
|
-
| ------ | ----------------- | ---------- |
|
|
780
|
-
| uuid | `string` | 图层 UUID |
|
|
781
|
-
| data | `Partial<ILayer>` | 更新的属性 |
|
|
782
|
-
|
|
783
|
-
**返回值:** `void`
|
|
784
|
-
|
|
785
|
-
###### clearAll
|
|
786
|
-
|
|
787
|
-
清空所有模型
|
|
788
|
-
|
|
789
|
-
**返回值:** `void`
|
|
790
|
-
|
|
791
|
-
**使用示例:**
|
|
792
|
-
|
|
793
|
-
```typescript
|
|
794
|
-
import { AppController } from '@jnrs/lingshu-smart/controller'
|
|
795
|
-
|
|
796
|
-
const controller = new AppController({
|
|
797
|
-
appDomId: 'app-container',
|
|
798
|
-
appEditable: true,
|
|
799
|
-
autoStart: true,
|
|
800
|
-
actions: {
|
|
801
|
-
onTap: (layer, data) => {
|
|
802
|
-
console.log('点击', data)
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
})
|
|
806
|
-
|
|
807
|
-
// 启动引擎
|
|
808
|
-
controller.start()
|
|
809
|
-
|
|
810
|
-
// 设置场景
|
|
811
|
-
controller.setTree({
|
|
812
|
-
width: 1920,
|
|
813
|
-
height: 1080,
|
|
814
|
-
zoomType: 'fit',
|
|
815
|
-
fill: { type: 'solid', color: '#fff', opacity: 1, stops: [] }
|
|
816
|
-
})
|
|
817
|
-
|
|
818
|
-
// 添加模型
|
|
819
|
-
const model = controller.addModel(layerData)
|
|
820
|
-
|
|
821
|
-
// 更新模型
|
|
822
|
-
controller.updateModel('layer-uuid', { x: 100, y: 100 })
|
|
823
|
-
|
|
824
|
-
// 移除模型
|
|
825
|
-
controller.removeModel('layer-uuid')
|
|
826
|
-
|
|
827
|
-
// 销毁
|
|
828
|
-
controller.destroy()
|
|
829
|
-
```
|
|
830
|
-
|
|
831
|
-
---
|
|
832
|
-
|
|
833
|
-
#### EditorController
|
|
834
|
-
|
|
835
|
-
编辑器控制器,提供编辑相关的功能。
|
|
836
|
-
|
|
837
|
-
**说明:** EditorController 继承自 AppController,额外提供编辑器特有的功能,如选中框、辅助线、网格等。
|
|
838
|
-
|
|
839
|
-
**主要功能:**
|
|
840
|
-
|
|
841
|
-
- 图层选中高亮
|
|
842
|
-
- 拖拽移动
|
|
843
|
-
- 旋转、缩放
|
|
844
|
-
- 对齐辅助线
|
|
845
|
-
- 网格显示
|
|
846
|
-
- 层级管理(zIndex)
|
|
847
|
-
|
|
848
|
-
---
|
|
849
|
-
|
|
850
|
-
### @jnrs/lingshu-smart/types 模块
|
|
851
|
-
|
|
852
|
-
详细的类型定义请参考上述"核心类型"部分,包括:
|
|
853
|
-
|
|
854
|
-
- **场景相关:** IScene, ICase
|
|
855
|
-
- **图层相关:** ILayer, IModel, IStationSlotConfig, IResourceConfig
|
|
856
|
-
- **交互相关:** IEventHandler, IContainer, InteractiveUi
|
|
857
|
-
- **枚举类型:** EnumStepType, EnumTag, EnumModel, EnumComponent, EnumResourceType
|
|
858
|
-
|
|
859
|
-
所有类型均从 `@jnrs/lingshu-smart` 主模块导出。
|
|
860
|
-
|
|
861
|
-
---
|
|
862
|
-
|
|
863
|
-
### @jnrs/lingshu-smart/constants 模块
|
|
864
|
-
|
|
865
|
-
#### CASE_INIT
|
|
866
|
-
|
|
867
|
-
新方案默认值
|
|
868
|
-
|
|
869
|
-
```typescript
|
|
870
|
-
const CASE_INIT: ICase = {
|
|
871
|
-
uuid: '',
|
|
872
|
-
title: '',
|
|
873
|
-
isActive: false,
|
|
874
|
-
layers: [],
|
|
875
|
-
scene: {
|
|
876
|
-
width: 1920,
|
|
877
|
-
height: 1080,
|
|
878
|
-
zoomType: 'fit',
|
|
879
|
-
fill: {
|
|
880
|
-
type: 'solid',
|
|
881
|
-
color: '#000',
|
|
882
|
-
opacity: 1,
|
|
883
|
-
stops: []
|
|
884
|
-
},
|
|
885
|
-
texture: ''
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
```
|
|
889
|
-
|
|
890
|
-
#### DEFAULT_LAYER
|
|
891
|
-
|
|
892
|
-
新图层默认值
|
|
893
|
-
|
|
894
|
-
```typescript
|
|
895
|
-
const DEFAULT_LAYER: IModel = {
|
|
896
|
-
rawData: { id: '' },
|
|
897
|
-
uuid: '',
|
|
898
|
-
equipmentName: '',
|
|
899
|
-
width: 0,
|
|
900
|
-
height: 0,
|
|
901
|
-
x: 0,
|
|
902
|
-
y: 0,
|
|
903
|
-
percentX: 0,
|
|
904
|
-
percentY: 0,
|
|
905
|
-
rotation: 0,
|
|
906
|
-
scale: 1,
|
|
907
|
-
zIndex: 1,
|
|
908
|
-
visible: true,
|
|
909
|
-
clickable: true,
|
|
910
|
-
menuClickable: true,
|
|
911
|
-
draggable: false,
|
|
912
|
-
editable: true,
|
|
913
|
-
selected: false
|
|
914
|
-
}
|
|
915
|
-
```
|
|
916
|
-
|
|
917
|
-
---
|
|
918
|
-
|
|
919
|
-
## 🔍 完整使用示例
|
|
920
|
-
|
|
921
|
-
### 编辑器模式
|
|
922
|
-
|
|
923
|
-
```vue
|
|
924
|
-
<template>
|
|
925
|
-
<LingshuSmartEditor :actions="editorActions" />
|
|
926
|
-
</template>
|
|
927
|
-
|
|
928
|
-
<script setup>
|
|
929
|
-
import { LingshuSmartEditor } from '@jnrs/lingshu-smart/components'
|
|
930
|
-
import { useDataStore } from '@jnrs/lingshu-smart/stores'
|
|
931
|
-
|
|
932
|
-
const dataStore = useDataStore()
|
|
933
|
-
|
|
934
|
-
const editorActions = {
|
|
935
|
-
async loadCases(id) {
|
|
936
|
-
const res = await fetch(`/api/cases/${id || ''}`)
|
|
937
|
-
const data = await res.json()
|
|
938
|
-
dataStore.updateCases(data)
|
|
939
|
-
return data
|
|
940
|
-
},
|
|
941
|
-
saveCases(cases) {
|
|
942
|
-
fetch('/api/cases', {
|
|
943
|
-
method: 'POST',
|
|
944
|
-
headers: { 'Content-Type': 'application/json' },
|
|
945
|
-
body: JSON.stringify(cases)
|
|
946
|
-
})
|
|
947
|
-
},
|
|
948
|
-
handlePreview(currentCase) {
|
|
949
|
-
window.open(`/preview/${currentCase?.uuid}`)
|
|
950
|
-
},
|
|
951
|
-
handleExit() {
|
|
952
|
-
if (confirm('确定要退出吗?')) {
|
|
953
|
-
window.history.back()
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
</script>
|
|
958
|
-
```
|
|
959
|
-
|
|
960
|
-
### 预览模式
|
|
961
|
-
|
|
962
|
-
```vue
|
|
963
|
-
<template>
|
|
964
|
-
<LingshuSmartPreview :case-uuid="caseUuid" :actions="previewActions" />
|
|
965
|
-
</template>
|
|
966
|
-
|
|
967
|
-
<script setup>
|
|
968
|
-
import { ref } from 'vue'
|
|
969
|
-
import { LingshuSmartPreview } from '@jnrs/lingshu-smart/components'
|
|
970
|
-
|
|
971
|
-
const caseUuid = ref('abc-123-def')
|
|
972
|
-
|
|
973
|
-
const previewActions = {
|
|
974
|
-
async loadCases() {
|
|
975
|
-
const res = await fetch('/api/cases')
|
|
976
|
-
return res.json()
|
|
977
|
-
},
|
|
978
|
-
onTap(layer, data) {
|
|
979
|
-
console.log('点击设备:', data)
|
|
980
|
-
// 显示设备详情
|
|
981
|
-
},
|
|
982
|
-
onMenuTap(layer, data) {
|
|
983
|
-
console.log('右键菜单:', data)
|
|
984
|
-
// 显示右键菜单
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
</script>
|
|
988
|
-
```
|
|
989
|
-
|
|
990
|
-
### 使用 Store
|
|
991
|
-
|
|
992
|
-
```typescript
|
|
993
|
-
import { useDataStore, useEditorStore, useStepRecord } from '@jnrs/lingshu-smart/stores'
|
|
994
|
-
|
|
995
|
-
// 数据管理
|
|
996
|
-
const dataStore = useDataStore()
|
|
997
|
-
dataStore.updateCases(cases)
|
|
998
|
-
dataStore.selectCase('case-uuid')
|
|
999
|
-
|
|
1000
|
-
// 编辑器管理
|
|
1001
|
-
const editorStore = useEditorStore()
|
|
1002
|
-
editorStore.initContainer({
|
|
1003
|
-
appDomId: 'editor',
|
|
1004
|
-
appEditable: true
|
|
1005
|
-
})
|
|
1006
|
-
editorStore.addLayer(layerData)
|
|
1007
|
-
editorStore.selectLayer('layer-uuid')
|
|
1008
|
-
|
|
1009
|
-
// 撤销/重做
|
|
1010
|
-
const stepRecord = useStepRecord()
|
|
1011
|
-
stepRecord.undo()
|
|
1012
|
-
stepRecord.redo()
|
|
1013
|
-
```
|
|
1014
|
-
|
|
1015
|
-
---
|
|
1016
|
-
|
|
1017
|
-
## 📝 注意事项
|
|
1018
|
-
|
|
1019
|
-
1. **引擎初始化**:使用前必须调用 `initContainer` 初始化 LeaferJS 引擎
|
|
1020
|
-
2. **方案管理**:方案数据通过 `useDataStore` 统一管理,确保数据一致性
|
|
1021
|
-
3. **编辑器 vs 预览器**:
|
|
1022
|
-
- 编辑器模式(`appEditable: true`)支持拖拽、旋转、缩放等编辑操作
|
|
1023
|
-
- 预览模式(`appEditable: false`)为只读模式,仅支持交互事件
|
|
1024
|
-
4. **性能优化**:
|
|
1025
|
-
- `updateScene` 和 `recordOperation` 均使用防抖处理
|
|
1026
|
-
- 大量图层时建议启用虚拟化渲染
|
|
1027
|
-
5. **类型安全**:所有 API 均提供完整的 TypeScript 类型定义
|
|
1028
|
-
6. **事件处理**:通过 `actions` 配置自定义事件回调,实现业务逻辑解耦
|
|
1029
|
-
7. **资源管理**:组件卸载时记得调用 `destroyContainer` 清理引擎资源
|
|
1030
|
-
8. **版本兼容**:基于 LeaferJS 构建,请确保版本兼容性
|
|
1031
|
-
|
|
1032
|
-
---
|
|
1033
|
-
|
|
1034
|
-
## 🛠 技术栈
|
|
1035
|
-
|
|
1036
|
-
- **Vue 3** - 前端框架
|
|
1037
|
-
- **TypeScript** - 类型系统
|
|
1038
|
-
- **Pinia** - 状态管理
|
|
1039
|
-
- **LeaferJS** - 2D 图形引擎
|
|
1040
|
-
- **Element Plus** - UI 组件库
|
|
1041
|
-
- **object-hash** - 对象哈希计算(用于撤销/重做)
|
|
1042
|
-
- **lodash-es** - 工具函数库
|
|
1043
|
-
|
|
1044
|
-
---
|
|
1045
|
-
|
|
1046
|
-
## 📄 License
|
|
1047
|
-
|
|
1048
|
-
UNLICENSED
|