@syhr/sy-graph 1.0.0 → 1.0.2-beta.0
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/CHANGELOG.md +418 -0
- package/README.md +186 -23
- package/lib/graph.css +1 -0
- package/lib/sy-graph.cjs +25 -13
- package/lib/sy-graph.mjs +20023 -0
- package/lib/sy-graph.umd.js +26 -13
- package/package.json +49 -39
- package/lib/style.css +0 -1
- package/lib/sy-graph.es.js +0 -12815
package/README.md
CHANGED
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
- 🎨 基于 Meta2D 的强大图形编辑能力
|
|
8
8
|
- 🔧 支持多种图形类型和图表
|
|
9
9
|
- 📱 响应式设计,支持移动端
|
|
10
|
-
- 🎯 TypeScript 支持
|
|
10
|
+
- 🎯 完整的 TypeScript 支持
|
|
11
11
|
- 📦 多种模块格式支持(ES、UMD、CommonJS)
|
|
12
12
|
- 🔌 Vue 3 插件化架构
|
|
13
|
-
- 🛡️
|
|
13
|
+
- 🛡️ 安全的全局属性处理,避免变量冲突
|
|
14
|
+
- 🔄 实时数据更新和 WebSocket 支持
|
|
15
|
+
- 🎛️ 可定制的错误处理和回调机制
|
|
16
|
+
- 🚀 高性能渲染和批量更新
|
|
17
|
+
- 🎨 多层级显示控制
|
|
18
|
+
- 📡 支持自定义 API 和事件总线注入
|
|
14
19
|
|
|
15
20
|
## 安装
|
|
16
21
|
|
|
@@ -23,7 +28,11 @@ npm install @syhr/sy-graph
|
|
|
23
28
|
确保你的项目已安装以下 peer dependencies:
|
|
24
29
|
|
|
25
30
|
```bash
|
|
26
|
-
|
|
31
|
+
# 必需依赖
|
|
32
|
+
npm install vue@^3.0.0 element-plus@^2.0.0 @meta2d/core@^1.0.0 @meta2d/svg@^1.0.0 @meta2d/utils@^1.0.0 lodash-es@^4.17.0
|
|
33
|
+
|
|
34
|
+
# 可选依赖(根据需要安装)
|
|
35
|
+
npm install pinia@^2.0.0 vue-router@^4.0.0
|
|
27
36
|
```
|
|
28
37
|
|
|
29
38
|
## 使用
|
|
@@ -58,59 +67,115 @@ export default {
|
|
|
58
67
|
```vue
|
|
59
68
|
<template>
|
|
60
69
|
<div>
|
|
61
|
-
<SyGraph
|
|
70
|
+
<SyGraph
|
|
71
|
+
ref="graphRef"
|
|
72
|
+
:url="graphUrl"
|
|
73
|
+
:local="false"
|
|
74
|
+
:show-map="true"
|
|
75
|
+
:config="graphConfig"
|
|
76
|
+
@loaded="handleLoaded"
|
|
77
|
+
@error="handleError"
|
|
78
|
+
@custom-msg="handleCustomMsg"
|
|
79
|
+
@socket-msg="handleSocketMsg"
|
|
80
|
+
/>
|
|
62
81
|
</div>
|
|
63
82
|
</template>
|
|
64
83
|
|
|
65
84
|
<script setup>
|
|
66
85
|
import { ref } from 'vue';
|
|
67
86
|
|
|
87
|
+
const graphRef = ref();
|
|
68
88
|
const graphUrl = ref('path/to/your/graph.json');
|
|
69
89
|
|
|
90
|
+
// 自定义配置
|
|
91
|
+
const graphConfig = ref({
|
|
92
|
+
socketUrl: 'ws://localhost:8080',
|
|
93
|
+
stationIdKey: 'STATION_ID',
|
|
94
|
+
userTokenKey: 'USER_TOKEN',
|
|
95
|
+
messageDelay: 200,
|
|
96
|
+
debounceDelay: 100,
|
|
97
|
+
enableAutoFit: true,
|
|
98
|
+
enableWebSocket: true,
|
|
99
|
+
});
|
|
100
|
+
|
|
70
101
|
const handleLoaded = (stage) => {
|
|
71
102
|
console.log('Graph loaded:', stage);
|
|
103
|
+
// 可以通过 stage 进行图纸操作
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const handleError = (errorInfo) => {
|
|
107
|
+
console.error('Graph error:', errorInfo);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const handleCustomMsg = (msg) => {
|
|
111
|
+
console.log('Custom message:', msg);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleSocketMsg = (msg) => {
|
|
115
|
+
console.log('Socket message:', msg);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// 组件方法调用示例
|
|
119
|
+
const toggleLevel = () => {
|
|
120
|
+
graphRef.value?.changeVisibleByLevel(3, false);
|
|
72
121
|
};
|
|
73
122
|
|
|
74
|
-
const
|
|
75
|
-
|
|
123
|
+
const batchUpdate = (dataList) => {
|
|
124
|
+
graphRef.value?.batchUpdatePen(dataList);
|
|
76
125
|
};
|
|
77
126
|
</script>
|
|
78
127
|
```
|
|
79
128
|
|
|
80
129
|
## Props
|
|
81
130
|
|
|
82
|
-
| 属性
|
|
83
|
-
|
|
|
84
|
-
| url
|
|
85
|
-
|
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
131
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
132
|
+
| --------------- | ------- | -------------- | -------------------- |
|
|
133
|
+
| url | String | '' | 图纸数据 URL |
|
|
134
|
+
| gid | String | '' | 图纸 ID |
|
|
135
|
+
| data | Object | null | 直接传入的图纸数据 |
|
|
136
|
+
| local | Boolean | false | 是否为本地数据 |
|
|
137
|
+
| config | Object | 默认配置对象 | WebSocket 和其他配置 |
|
|
138
|
+
| showMap | Boolean | false | 是否显示地图 |
|
|
139
|
+
| isFactory | Boolean | false | 是否为工厂模式 |
|
|
140
|
+
| apiInstance | Object | 内置 Api | 自定义 API 实例 |
|
|
141
|
+
| mittInstance | Object | 内置 mitt | 自定义事件总线实例 |
|
|
142
|
+
| customCallbacks | Object | {} | 自定义回调函数集合 |
|
|
143
|
+
| errorHandler | Object | 默认错误处理器 | 错误处理配置 |
|
|
90
144
|
|
|
91
145
|
## Events
|
|
92
146
|
|
|
93
|
-
| 事件名
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
147
|
+
| 事件名 | 说明 | 参数 |
|
|
148
|
+
| ---------- | -------------- | ----------------------- |
|
|
149
|
+
| error | 错误事件 | errorInfo: 错误信息对象 |
|
|
150
|
+
| loaded | 图纸加载完成 | stage: Meta2D 实例 |
|
|
151
|
+
| custom-msg | 自定义消息事件 | msg: 消息对象 |
|
|
152
|
+
| socket-msg | WebSocket 消息 | msg: WebSocket 消息 |
|
|
97
153
|
|
|
98
154
|
## 方法
|
|
99
155
|
|
|
100
156
|
通过 ref 获取组件实例后可调用以下方法:
|
|
101
157
|
|
|
102
|
-
- `
|
|
103
|
-
- `batchUpdatePen(dataList)` - 批量更新图元
|
|
104
|
-
- `setValue(pen, render)` - 设置图元属性
|
|
105
|
-
- `getAllPens()` - 获取所有图元
|
|
158
|
+
- `setValue(pen, render = true)` - 设置图元属性
|
|
106
159
|
- `getStage()` - 获取 Meta2D 实例
|
|
160
|
+
- `getAllPens()` - 获取所有图元
|
|
161
|
+
- `batchUpdatePen(dataList)` - 批量更新图元
|
|
162
|
+
- `handleLineCross()` - 处理线条交叉
|
|
163
|
+
- `changeVisibleByLevel(level, isStrict = false)` - 切换显示层级
|
|
107
164
|
|
|
108
165
|
## TypeScript 支持
|
|
109
166
|
|
|
110
167
|
本包提供完整的 TypeScript 类型声明:
|
|
111
168
|
|
|
112
169
|
```typescript
|
|
113
|
-
import
|
|
170
|
+
import { ref } from 'vue';
|
|
171
|
+
import type {
|
|
172
|
+
SyGraphProps,
|
|
173
|
+
SyGraphInstance,
|
|
174
|
+
GraphConfig,
|
|
175
|
+
CustomCallbacks,
|
|
176
|
+
ErrorHandler,
|
|
177
|
+
DataItem,
|
|
178
|
+
} from '@syhr/sy-graph';
|
|
114
179
|
|
|
115
180
|
// 组件 ref 类型
|
|
116
181
|
const graphRef = ref<SyGraphInstance>();
|
|
@@ -119,7 +184,105 @@ const graphRef = ref<SyGraphInstance>();
|
|
|
119
184
|
const props: SyGraphProps = {
|
|
120
185
|
url: 'path/to/graph.json',
|
|
121
186
|
showMap: true,
|
|
187
|
+
config: {
|
|
188
|
+
socketUrl: 'ws://localhost:8080',
|
|
189
|
+
enableAutoFit: true,
|
|
190
|
+
enableWebSocket: true,
|
|
191
|
+
} as GraphConfig,
|
|
192
|
+
customCallbacks: {
|
|
193
|
+
onStageLoaded: (stage) => console.log('Stage loaded:', stage),
|
|
194
|
+
onBatchUpdate: (dataList: DataItem[]) => console.log('Batch update:', dataList),
|
|
195
|
+
} as CustomCallbacks,
|
|
196
|
+
errorHandler: {
|
|
197
|
+
showMessage: true,
|
|
198
|
+
callback: (errorInfo) => console.error('Custom error handler:', errorInfo),
|
|
199
|
+
} as ErrorHandler,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// 方法调用示例
|
|
203
|
+
const toggleLevel = (level: number, isStrict: boolean = false) => {
|
|
204
|
+
graphRef.value?.changeVisibleByLevel(level, isStrict);
|
|
122
205
|
};
|
|
206
|
+
|
|
207
|
+
const updateData = (dataList: DataItem[]) => {
|
|
208
|
+
graphRef.value?.batchUpdatePen(dataList);
|
|
209
|
+
};
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 配置选项详解
|
|
213
|
+
|
|
214
|
+
### GraphConfig 配置
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
const config = {
|
|
218
|
+
socketUrl: 'ws://localhost:8080', // WebSocket服务器地址
|
|
219
|
+
stationIdKey: 'STATION_ID', // 站点ID存储键名
|
|
220
|
+
userTokenKey: 'USER_TOKEN', // 用户令牌存储键名
|
|
221
|
+
messageDelay: 200, // 消息处理延迟(毫秒)
|
|
222
|
+
debounceDelay: 100, // 防抖延迟(毫秒)
|
|
223
|
+
enableAutoFit: true, // 是否自动适应视图
|
|
224
|
+
enableWebSocket: true, // 是否启用WebSocket
|
|
225
|
+
graphSocket: 'graph:socket', // 图纸Socket事件名
|
|
226
|
+
};
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### CustomCallbacks 回调
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
const callbacks = {
|
|
233
|
+
onWebSocketMessage: (message) => {
|
|
234
|
+
// 处理WebSocket消息
|
|
235
|
+
},
|
|
236
|
+
onCustomMessage: (msg) => {
|
|
237
|
+
// 处理自定义消息
|
|
238
|
+
},
|
|
239
|
+
onStageLoaded: (stage) => {
|
|
240
|
+
// 图纸加载完成后的处理
|
|
241
|
+
},
|
|
242
|
+
onGraphLoaded: (url) => {
|
|
243
|
+
// 图纸URL加载完成
|
|
244
|
+
},
|
|
245
|
+
onBatchUpdate: (dataList) => {
|
|
246
|
+
// 批量数据更新后的处理
|
|
247
|
+
},
|
|
248
|
+
onLevelChange: (level, isStrict) => {
|
|
249
|
+
// 显示层级变更后的处理
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 使用场景
|
|
255
|
+
|
|
256
|
+
### 1. 基础图纸展示
|
|
257
|
+
|
|
258
|
+
```vue
|
|
259
|
+
<SyGraph :url="'/api/graph/123'" />
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 2. 本地图纸文件
|
|
263
|
+
|
|
264
|
+
```vue
|
|
265
|
+
<SyGraph :url="'/assets/graph.json'" :local="true" />
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### 3. 直接传入数据
|
|
269
|
+
|
|
270
|
+
```vue
|
|
271
|
+
<SyGraph :data="graphData" />
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 4. 完整配置示例
|
|
275
|
+
|
|
276
|
+
```vue
|
|
277
|
+
<SyGraph
|
|
278
|
+
:gid="graphId"
|
|
279
|
+
:config="graphConfig"
|
|
280
|
+
:custom-callbacks="callbacks"
|
|
281
|
+
:error-handler="errorHandler"
|
|
282
|
+
:show-map="true"
|
|
283
|
+
@loaded="onGraphLoaded"
|
|
284
|
+
@error="onGraphError"
|
|
285
|
+
/>
|
|
123
286
|
```
|
|
124
287
|
|
|
125
288
|
## 浏览器支持
|
package/lib/graph.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.meta2d-editor[data-v-3657c9a7]{position:relative;width:100%;height:100%}.meta2d-editor[data-v-3657c9a7] .meta2d-map{z-index:1999}.meta2d-editor[data-v-3657c9a7] .stage.value-map{position:absolute;top:1.04vw;right:.52vw;z-index:200}.meta2d-editor .toolbox[data-v-3657c9a7]{position:absolute;display:none;width:5.21vw;height:1.56vw;background:red;z-index:1999}.preview-container[data-v-ca3fd052]{position:relative;width:100%;height:100%}.preview-container .back-btn[data-v-ca3fd052]{position:absolute;bottom:.52vw;right:.52vw;z-index:1000}
|