@syhr/sy-threed-graph 1.0.0-bate4

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 ADDED
@@ -0,0 +1,226 @@
1
+ # @syhr/sy-threed-graph
2
+
3
+ 一个基于 ThreeJs 的三维图形展示工具。
4
+
5
+ ## 特性
6
+
7
+ - 🎨 基于 ThreeJs 的强大三维图形展示能力
8
+ - 🔧 支持多种三维模型
9
+ - 📱 响应式设计,支持移动端
10
+ - 🎯 完整的 TypeScript 支持
11
+ - 📦 多种模块格式支持(ES、UMD、CommonJS)
12
+ - 🔌 Vue 3 插件化架构
13
+ - 🛡️ 安全的全局属性处理,避免变量冲突
14
+ - 🔄 实时数据更新和 WebSocket 支持
15
+ - 🎛️ 可定制的错误处理和回调机制
16
+ - 🚀 高性能渲染和批量更新
17
+ - 🎨 多层级显示控制
18
+ - 📡 支持自定义 API 和事件总线注入
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ npm install @syhr/sy-threed-graph
24
+ ```
25
+
26
+ ### Peer Dependencies
27
+
28
+ 确保你的项目已安装以下 peer dependencies:
29
+
30
+ ```bash
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
33
+
34
+ # 可选依赖(根据需要安装)
35
+ npm install pinia@^2.0.0 vue-router@^4.0.0
36
+ ```
37
+
38
+ ## 使用
39
+
40
+ ### 全局注册(推荐)
41
+
42
+ ```javascript
43
+ import { createApp } from 'vue';
44
+ import SyGraph from '@syhr/sy-threed-graph';
45
+ import '@syhr/sy-threed-graph/style';
46
+
47
+ const app = createApp(App);
48
+ app.use(SyGraph);
49
+ app.mount('#app');
50
+ ```
51
+
52
+ ### 局部使用
53
+
54
+ ```javascript
55
+ import { SyThreedGraph } from '@syhr/sy-threed-graph';
56
+
57
+ export default {
58
+ components: {
59
+ SyThreedGraph,
60
+ },
61
+ };
62
+ ```
63
+
64
+ ### 在模板中使用
65
+
66
+ ```vue
67
+ <template>
68
+ <div>
69
+ <SyThreedGraph
70
+ ref="graphRef"
71
+ :id="sceneId"
72
+ :data="sceneData"
73
+ :url="graphUrl"
74
+ :token="token"
75
+ :socketUrl="socketUrl"
76
+ @loaded="handleLoaded"
77
+ @graph-event="handleGraphEvent"
78
+ />
79
+ </div>
80
+ </template>
81
+
82
+ <script setup>
83
+ import { ref } from 'vue';
84
+ import { SyGraph } from '@syhr/sy-graph';
85
+ const sceneId = ref('');
86
+ const sceneData = ref({});
87
+ const graphRef = ref();
88
+ const graphUrl = ref('path/to/your/graph.json');
89
+ const token = ref('');
90
+ const socketUrl = ref('');
91
+
92
+ const handleLoaded = (stage) => {
93
+ console.log('Graph loaded:', stage);
94
+ // 可以通过 stage 进行图纸操作
95
+ };
96
+
97
+ // 图纸事件, 点击等
98
+ const handleGraphEvent = (errorInfo) => {
99
+ console.error('Graph error:', errorInfo);
100
+ };
101
+
102
+ // 组件方法调用示例
103
+ const toggleLevel = () => {
104
+ graphRef.value?.changeVisibleByLevel(3, false);
105
+ };
106
+
107
+ const batchUpdate = (dataList) => {
108
+ graphRef.value?.batchUpdatePen(dataList);
109
+ };
110
+ </script>
111
+ ```
112
+
113
+ ## Props
114
+
115
+ | 属性 | 类型 | 默认值 | 说明 |
116
+ | --------- | ------ | ------ | ------------------------ |
117
+ | data | Object | null | 场景数据,优先级最高 |
118
+ | url | String | '' | 图纸数据 URL,优先级第二 |
119
+ | id | String | '' | 图纸 ID,优先级第三 |
120
+ | token | String | '' | socket token |
121
+ | socketUrl | String | '' | socket 地址 |
122
+
123
+ ## Events
124
+
125
+ | 事件名 | 说明 | 参数 |
126
+ | ----------- | ---------------- | ------------------ |
127
+ | loaded | 图纸加载完成 | stage: Meta2D 实例 |
128
+ | graph-event | 图纸事件,点击等 | msg: 消息对象 |
129
+
130
+ ## 方法
131
+
132
+ 通过 ref 获取组件实例后可调用以下方法:
133
+
134
+ - `setValue(pen, render = true)` - 设置图元属性
135
+ - `getStage()` - 获取 Meta2D 实例
136
+ - `getAllPens()` - 获取所有图元
137
+ - `getCustomPenType()` - 获取所有图元类型
138
+ - `batchUpdatePen(dataList)` - 批量更新图元
139
+ - `handleLineCross()` - 处理线条交叉
140
+ - `changeVisibleByLevel(level, isStrict = false)` - 切换显示层级
141
+
142
+ ## 使用场景
143
+
144
+ ### 1. 基础三维图纸展示
145
+
146
+ ```vue
147
+ <SyThreedGraph :url="'/api/graph/123'" />
148
+ ```
149
+
150
+ ### 2. 图纸id
151
+
152
+ ```vue
153
+ <SyThreedGraph :id="'111111111'" />
154
+ ```
155
+
156
+ ### 3. 直接传入数据
157
+
158
+ ```vue
159
+ <SyThreedGraph :data="graphData" />
160
+ ```
161
+
162
+ ### 4. 完整配置示例
163
+
164
+ ```vue
165
+ <SyThreedGraph
166
+ ref="graphRef"
167
+ :id="sceneId"
168
+ :data="sceneData"
169
+ :url="graphUrl"
170
+ :token="token"
171
+ :socketUrl="socketUrl"
172
+ @loaded="handleLoaded"
173
+ @graph-event="handleGraphEvent"
174
+ />
175
+ ```
176
+
177
+ ## 浏览器支持
178
+
179
+ - Chrome >= 60
180
+ - Firefox >= 60
181
+ - Safari >= 12
182
+ - Edge >= 79
183
+
184
+ ## 开发
185
+
186
+ ```bash
187
+ # 安装依赖
188
+ npm install
189
+
190
+ # 开发模式
191
+ npm run dev
192
+
193
+ # 构建库
194
+ npm run build:lib
195
+
196
+ # 构建类型
197
+ npm run build:types
198
+
199
+ # 完整构建
200
+ npm run build:all
201
+
202
+ # 类型检查
203
+ npm run type-check
204
+
205
+ # 代码检查
206
+ npm run lint
207
+ ```
208
+
209
+ ## 许可证
210
+
211
+ [MIT](LICENSE)
212
+
213
+ ## 更新日志
214
+
215
+ 查看 [CHANGELOG.md](CHANGELOG.md) 了解详细的更新记录。
216
+
217
+ ## 贡献
218
+
219
+ 欢迎提交 Issue 和 Pull Request。
220
+
221
+ ## 相关链接
222
+
223
+ - [ThreeJs 官方文档](https://threejs.org)
224
+ - [ThreeEditor 官方文档](https://z2586300277.github.io/editor-docs/)
225
+ - [Vue 3 文档](https://vuejs.org)
226
+ - [Element Plus 文档](https://element-plus.org)