@syhr/sy-graph 1.1.0-rc.2 → 1.1.0-rc.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/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @syhr/sy-three
1
+ # @syhr/sy-graph
2
2
 
3
- 一个基于 ThreeJs 的三维图形展示工具。
3
+ 一个基于 Meta2D 的平面图形配置工具 Vue 3 组件库。
4
4
 
5
5
  ## 特性
6
6
 
7
- - 🎨 基于 ThreeJs 的强大三维图形展示能力
8
- - 🔧 支持多种三维模型
7
+ - 🎨 基于 Meta2D 的强大图形编辑能力
8
+ - 🔧 支持多种图形类型和图表
9
9
  - 📱 响应式设计,支持移动端
10
10
  - 🎯 完整的 TypeScript 支持
11
11
  - 📦 多种模块格式支持(ES、UMD、CommonJS)
@@ -20,7 +20,7 @@
20
20
  ## 安装
21
21
 
22
22
  ```bash
23
- npm install @syhr/sy-three
23
+ npm install @syhr/sy-graph
24
24
  ```
25
25
 
26
26
  ### Peer Dependencies
@@ -29,7 +29,7 @@ npm install @syhr/sy-three
29
29
 
30
30
  ```bash
31
31
  # 必需依赖
32
- npm install vue@^3.0.0 element-plus@^2.0.0 lodash-es@^4.17.0 three@^0.184.0 three-edit-cores@^0.0.15
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
33
 
34
34
  # 可选依赖(根据需要安装)
35
35
  npm install pinia@^2.0.0 vue-router@^4.0.0
@@ -37,33 +37,26 @@ npm install pinia@^2.0.0 vue-router@^4.0.0
37
37
 
38
38
  ## 使用
39
39
 
40
- 设置 draco 解码器的资源路径。在库模式下使用时需要:
41
-
42
- 1. 将 `node_modules/@syhr/sy-threed-graph/lib-threed/draco` 文件夹拷贝到自己项目的 `public/` 目录下
43
- 2. 在注册组件之前调用此函数指定路径
44
-
45
40
  ### 全局注册(推荐)
46
41
 
47
42
  ```javascript
48
43
  import { createApp } from 'vue';
49
- import SyThreed, { setDracoPath } from '@syhr/sy-threed';
50
- import '@syhr/sy-threed/style';
51
- const dracoPath = `${import.meta.env.BASE_URL}draco/`;
52
- setDracoPath(dracoPath);
44
+ import SyGraph from '@syhr/sy-graph';
45
+ import '@syhr/sy-graph/style';
53
46
 
54
47
  const app = createApp(App);
55
- app.use(SyThreed);
48
+ app.use(SyGraph);
56
49
  app.mount('#app');
57
50
  ```
58
51
 
59
52
  ### 局部使用
60
53
 
61
54
  ```javascript
62
- import { SyThree } from '@syhr/sy-three';
55
+ import { SyGraph } from '@syhr/sy-graph';
63
56
 
64
57
  export default {
65
58
  components: {
66
- SyThree,
59
+ SyGraph,
67
60
  },
68
61
  };
69
62
  ```
@@ -73,15 +66,16 @@ export default {
73
66
  ```vue
74
67
  <template>
75
68
  <div>
76
- <SyThree
69
+ <SyGraph
77
70
  ref="graphRef"
78
- :id="sceneId"
79
- :data="sceneData"
80
71
  :url="graphUrl"
81
- :token="token"
82
- :socketUrl="socketUrl"
72
+ :local="false"
73
+ :show-map="true"
74
+ :config="graphConfig"
83
75
  @loaded="handleLoaded"
84
- @graph-event="handleGraphEvent"
76
+ @error="handleError"
77
+ @custom-msg="handleCustomMsg"
78
+ @socket-msg="handleSocketMsg"
85
79
  />
86
80
  </div>
87
81
  </template>
@@ -89,85 +83,217 @@ export default {
89
83
  <script setup>
90
84
  import { ref } from 'vue';
91
85
  import { SyGraph } from '@syhr/sy-graph';
92
- const sceneId = ref('');
93
- const sceneData = ref({});
94
86
  const graphRef = ref();
95
87
  const graphUrl = ref('path/to/your/graph.json');
96
- const token = ref('');
97
- const socketUrl = ref('');
88
+
89
+ // 自定义配置
90
+ const graphConfig = ref({
91
+ socketUrl: 'ws://localhost:8080',
92
+ stationIdKey: 'STATION_ID',
93
+ userTokenKey: 'USER_TOKEN',
94
+ messageDelay: 200,
95
+ debounceDelay: 100,
96
+ enableAutoFit: true,
97
+ enableWebSocket: true,
98
+ });
98
99
 
99
100
  const handleLoaded = (stage) => {
100
101
  console.log('Graph loaded:', stage);
101
102
  // 可以通过 stage 进行图纸操作
102
103
  };
103
104
 
104
- // 图纸事件, 点击等
105
- const handleGraphEvent = (errorInfo) => {
105
+ const handleError = (errorInfo) => {
106
106
  console.error('Graph error:', errorInfo);
107
107
  };
108
108
 
109
- // 获取实例
110
- const getEditorInstance = () => {
111
- graphRef.value?.getEditorInstance();
109
+ const handleCustomMsg = (msg) => {
110
+ console.log('Custom message:', msg);
111
+ };
112
+
113
+ const handleSocketMsg = (msg) => {
114
+ console.log('Socket message:', msg);
115
+ };
116
+
117
+ // 组件方法调用示例
118
+ const toggleLevel = () => {
119
+ graphRef.value?.changeVisibleByLevel(3, false);
120
+ };
121
+
122
+ const batchUpdate = (dataList) => {
123
+ graphRef.value?.batchUpdatePen(dataList);
112
124
  };
113
125
  </script>
114
126
  ```
115
127
 
116
128
  ## Props
117
129
 
118
- | 属性 | 类型 | 默认值 | 说明 |
119
- | --------- | ------ | ------ | ------------------------ |
120
- | data | Object | null | 场景数据,优先级最高 |
121
- | url | String | '' | 图纸数据 URL,优先级第二 |
122
- | id | String | '' | 图纸 ID,优先级第三 |
123
- | token | String | '' | socket token |
124
- | socketUrl | String | '' | socket 地址 |
130
+ | 属性 | 类型 | 默认值 | 说明 |
131
+ | --------------- | ------- | -------------- | -------------------- |
132
+ | url | String | '' | 图纸数据 URL |
133
+ | gid | String | '' | 图纸 ID |
134
+ | data | Object | null | 直接传入的图纸数据 |
135
+ | local | Boolean | false | 是否为本地数据 |
136
+ | config | Object | 默认配置对象 | WebSocket 和其他配置 |
137
+ | showMap | Boolean | false | 是否显示地图 |
138
+ | isFactory | Boolean | false | 是否为工厂模式 |
139
+ | apiInstance | Object | 内置 Api | 自定义 API 实例 |
140
+ | mittInstance | Object | 内置 mitt | 自定义事件总线实例 |
141
+ | customCallbacks | Object | {} | 自定义回调函数集合 |
142
+ | errorHandler | Object | 默认错误处理器 | 错误处理配置 |
143
+ | devConfig | Object | 默认配置对象 | 打包后开发环境配置 |
125
144
 
126
145
  ## Events
127
146
 
128
- | 事件名 | 说明 | 参数 |
129
- | ----------- | ---------------- | ------------------ |
130
- | loaded | 图纸加载完成 | stage: Meta2D 实例 |
131
- | graph-event | 图纸事件,点击等 | msg: 消息对象 |
147
+ | 事件名 | 说明 | 参数 |
148
+ | ---------- | -------------- | ----------------------- |
149
+ | error | 错误事件 | errorInfo: 错误信息对象 |
150
+ | loaded | 图纸加载完成 | stage: Meta2D 实例 |
151
+ | custom-msg | 自定义消息事件 | msg: 消息对象 |
152
+ | socket-msg | WebSocket 消息 | msg: WebSocket 消息 |
132
153
 
133
154
  ## 方法
134
155
 
135
156
  通过 ref 获取组件实例后可调用以下方法:
136
157
 
137
- - `getEditorInstance()` - 获取编辑器实例
158
+ - `setValue(pen, render = true)` - 设置图元属性
159
+ - `getStage()` - 获取 Meta2D 实例
160
+ - `getAllPens()` - 获取所有图元
161
+ - `getCustomPenType()` - 获取所有图元类型
162
+ - `batchUpdatePen(dataList)` - 批量更新图元
163
+ - `handleLineCross()` - 处理线条交叉
164
+ - `changeVisibleByLevel(level, isStrict = false)` - 切换显示层级
165
+
166
+ ## TypeScript 支持
167
+
168
+ 本包提供完整的 TypeScript 类型声明:
169
+
170
+ ```typescript
171
+ import { ref } from 'vue';
172
+ import type {
173
+ SyGraphProps,
174
+ SyGraphInstance,
175
+ GraphConfig,
176
+ CustomCallbacks,
177
+ ErrorHandler,
178
+ DataItem,
179
+ } from '@syhr/sy-graph';
180
+
181
+ // 组件 ref 类型
182
+ const graphRef = ref<SyGraphInstance>();
183
+
184
+ // Props 类型
185
+ const props: SyGraphProps = {
186
+ url: 'path/to/graph.json',
187
+ showMap: true,
188
+ config: {
189
+ socketUrl: 'ws://localhost:8080',
190
+ enableAutoFit: true,
191
+ enableWebSocket: true,
192
+ } as GraphConfig,
193
+ customCallbacks: {
194
+ onStageLoaded: (stage) => console.log('Stage loaded:', stage),
195
+ onBatchUpdate: (dataList: DataItem[]) => console.log('Batch update:', dataList),
196
+ } as CustomCallbacks,
197
+ errorHandler: {
198
+ showMessage: true,
199
+ callback: (errorInfo) => console.error('Custom error handler:', errorInfo),
200
+ } as ErrorHandler,
201
+ };
202
+
203
+ // 方法调用示例
204
+ const toggleLevel = (level: number, isStrict: boolean = false) => {
205
+ graphRef.value?.changeVisibleByLevel(level, isStrict);
206
+ };
207
+
208
+ const updateData = (dataList: DataItem[]) => {
209
+ graphRef.value?.batchUpdatePen(dataList);
210
+ };
211
+ ```
212
+
213
+ ## 配置选项详解
214
+
215
+ ### GraphConfig 配置
216
+
217
+ ```typescript
218
+ const config = {
219
+ socketUrl: 'ws://localhost:8080', // WebSocket服务器地址
220
+ stationIdKey: 'STATION_ID', // 站点ID存储键名
221
+ userTokenKey: 'USER_TOKEN', // 用户令牌存储键名
222
+ userToken: '123456789', // 用户令牌
223
+ messageDelay: 200, // 消息处理延迟(毫秒)
224
+ debounceDelay: 100, // 防抖延迟(毫秒)
225
+ enableAutoFit: true, // 是否自动适应视图
226
+ enableWebSocket: true, // 是否启用WebSocket
227
+ graphSocket: 'graph:socket', // 图纸Socket事件名
228
+ };
229
+ ```
230
+
231
+ ### CustomCallbacks 回调
232
+
233
+ ```typescript
234
+ const callbacks = {
235
+ onWebSocketMessage: (message) => {
236
+ // 处理WebSocket消息
237
+ },
238
+ onCustomMessage: (msg) => {
239
+ // 处理自定义消息
240
+ },
241
+ onStageLoaded: (stage) => {
242
+ // 图纸加载完成后的处理
243
+ },
244
+ onGraphLoaded: (url) => {
245
+ // 图纸URL加载完成
246
+ },
247
+ onBatchUpdate: (dataList) => {
248
+ // 批量数据更新后的处理
249
+ },
250
+ onLevelChange: (level, isStrict) => {
251
+ // 显示层级变更后的处理
252
+ },
253
+ };
254
+ ```
255
+
256
+ ### CustomCallbacks 回调
257
+
258
+ ```typescript
259
+ const devConfig = {
260
+ isDev: false, // 打包后是否是开发环境
261
+ devServerUrl: '', // 打包后的开发环境地址
262
+ devServerPort: 8443, // 打包后的开发环境端口
263
+ };
264
+ ```
138
265
 
139
266
  ## 使用场景
140
267
 
141
- ### 1. 基础三维图纸展示
268
+ ### 1. 基础图纸展示
142
269
 
143
270
  ```vue
144
- <SyThree :data="graphData" />
271
+ <SyGraph :url="'/api/graph/123'" />
145
272
  ```
146
273
 
147
- ### 2. 图纸id
274
+ ### 2. 本地图纸文件
148
275
 
149
276
  ```vue
150
- <SyThree :url="'https://ip:port/cockpit/threed/xxx.json'" />
277
+ <SyGraph :url="'/assets/graph.json'" :local="true" />
151
278
  ```
152
279
 
153
280
  ### 3. 直接传入数据
154
281
 
155
282
  ```vue
156
- <SyThree :id="'111111111'" />
283
+ <SyGraph :data="graphData" />
157
284
  ```
158
285
 
159
286
  ### 4. 完整配置示例
160
287
 
161
288
  ```vue
162
- <SyThree
163
- ref="graphRef"
164
- :id="sceneId"
165
- :data="sceneData"
166
- :url="graphUrl"
167
- :token="token"
168
- :socketUrl="socketUrl"
169
- @loaded="handleLoaded"
170
- @graph-event="handleGraphEvent"
289
+ <SyGraph
290
+ :gid="graphId"
291
+ :config="graphConfig"
292
+ :custom-callbacks="callbacks"
293
+ :error-handler="errorHandler"
294
+ :show-map="true"
295
+ @loaded="onGraphLoaded"
296
+ @error="onGraphError"
171
297
  />
172
298
  ```
173
299
 
@@ -217,7 +343,6 @@ npm run lint
217
343
 
218
344
  ## 相关链接
219
345
 
220
- - [ThreeJs 官方文档](https://threejs.org)
221
- - [ThreeEditor 官方文档](https://z2586300277.github.io/editor-docs/)
346
+ - [Meta2D 官方文档](https://meta2d.com)
222
347
  - [Vue 3 文档](https://vuejs.org)
223
348
  - [Element Plus 文档](https://element-plus.org)