@syhr/sy-graph 1.1.0-rc.12 → 1.1.0-rc.13

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,348 +1,17 @@
1
1
  # @syhr/sy-graph
2
2
 
3
- 一个基于 Meta2D 的平面图形配置工具 Vue 3 组件库。
3
+ 基于 @meta2d 的平面图形配置组件库。
4
4
 
5
- ## 特性
6
-
7
- - 🎨 基于 Meta2D 的强大图形编辑能力
8
- - 🔧 支持多种图形类型和图表
9
- - 📱 响应式设计,支持移动端
10
- - 🎯 完整的 TypeScript 支持
11
- - 📦 多种模块格式支持(ES、UMD、CommonJS)
12
- - 🔌 Vue 3 插件化架构
13
- - 🛡️ 安全的全局属性处理,避免变量冲突
14
- - 🔄 实时数据更新和 WebSocket 支持
15
- - 🎛️ 可定制的错误处理和回调机制
16
- - 🚀 高性能渲染和批量更新
17
- - 🎨 多层级显示控制
18
- - 📡 支持自定义 API 和事件总线注入
19
-
20
- ## 安装
5
+ ## 构建
21
6
 
22
7
  ```bash
23
- npm install @syhr/sy-graph
8
+ pnpm build
24
9
  ```
25
10
 
26
- ### Peer Dependencies
11
+ 产物输出到 `dist-graph/`。
27
12
 
28
- 确保你的项目已安装以下 peer dependencies:
13
+ ## 发布
29
14
 
30
15
  ```bash
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
16
+ pnpm release:publish
36
17
  ```
37
-
38
- ## 使用
39
-
40
- ### 全局注册(推荐)
41
-
42
- ```javascript
43
- import { createApp } from 'vue';
44
- import SyGraph from '@syhr/sy-graph';
45
- import '@syhr/sy-graph/style';
46
-
47
- const app = createApp(App);
48
- app.use(SyGraph);
49
- app.mount('#app');
50
- ```
51
-
52
- ### 局部使用
53
-
54
- ```javascript
55
- import { SyGraph } from '@syhr/sy-graph';
56
-
57
- export default {
58
- components: {
59
- SyGraph,
60
- },
61
- };
62
- ```
63
-
64
- ### 在模板中使用
65
-
66
- ```vue
67
- <template>
68
- <div>
69
- <SyGraph
70
- ref="graphRef"
71
- :url="graphUrl"
72
- :local="false"
73
- :show-map="true"
74
- :config="graphConfig"
75
- @loaded="handleLoaded"
76
- @error="handleError"
77
- @custom-msg="handleCustomMsg"
78
- @socket-msg="handleSocketMsg"
79
- />
80
- </div>
81
- </template>
82
-
83
- <script setup>
84
- import { ref } from 'vue';
85
- import { SyGraph } from '@syhr/sy-graph';
86
- const graphRef = ref();
87
- const graphUrl = ref('path/to/your/graph.json');
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
- });
99
-
100
- const handleLoaded = (stage) => {
101
- console.log('Graph loaded:', stage);
102
- // 可以通过 stage 进行图纸操作
103
- };
104
-
105
- const handleError = (errorInfo) => {
106
- console.error('Graph error:', errorInfo);
107
- };
108
-
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);
124
- };
125
- </script>
126
- ```
127
-
128
- ## Props
129
-
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 | 默认配置对象 | 打包后开发环境配置 |
144
-
145
- ## Events
146
-
147
- | 事件名 | 说明 | 参数 |
148
- | ---------- | -------------- | ----------------------- |
149
- | error | 错误事件 | errorInfo: 错误信息对象 |
150
- | loaded | 图纸加载完成 | stage: Meta2D 实例 |
151
- | custom-msg | 自定义消息事件 | msg: 消息对象 |
152
- | socket-msg | WebSocket 消息 | msg: WebSocket 消息 |
153
-
154
- ## 方法
155
-
156
- 通过 ref 获取组件实例后可调用以下方法:
157
-
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
- ```
265
-
266
- ## 使用场景
267
-
268
- ### 1. 基础图纸展示
269
-
270
- ```vue
271
- <SyGraph :url="'/api/graph/123'" />
272
- ```
273
-
274
- ### 2. 本地图纸文件
275
-
276
- ```vue
277
- <SyGraph :url="'/assets/graph.json'" :local="true" />
278
- ```
279
-
280
- ### 3. 直接传入数据
281
-
282
- ```vue
283
- <SyGraph :data="graphData" />
284
- ```
285
-
286
- ### 4. 完整配置示例
287
-
288
- ```vue
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"
297
- />
298
- ```
299
-
300
- ## 浏览器支持
301
-
302
- - Chrome >= 60
303
- - Firefox >= 60
304
- - Safari >= 12
305
- - Edge >= 79
306
-
307
- ## 开发
308
-
309
- ```bash
310
- # 安装依赖
311
- npm install
312
-
313
- # 开发模式
314
- npm run dev
315
-
316
- # 构建库
317
- npm run build:lib
318
-
319
- # 构建类型
320
- npm run build:types
321
-
322
- # 完整构建
323
- npm run build:all
324
-
325
- # 类型检查
326
- npm run type-check
327
-
328
- # 代码检查
329
- npm run lint
330
- ```
331
-
332
- ## 许可证
333
-
334
- [MIT](LICENSE)
335
-
336
- ## 更新日志
337
-
338
- 查看 [CHANGELOG.md](CHANGELOG.md) 了解详细的更新记录。
339
-
340
- ## 贡献
341
-
342
- 欢迎提交 Issue 和 Pull Request。
343
-
344
- ## 相关链接
345
-
346
- - [Meta2D 官方文档](https://meta2d.com)
347
- - [Vue 3 文档](https://vuejs.org)
348
- - [Element Plus 文档](https://element-plus.org)