Skip to content

Commit 027c2aa

Browse files
committed
feat: 整体UI美化,并丰富可配置的UI项
1 parent 4507500 commit 027c2aa

File tree

63 files changed

+4589
-1497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4589
-1497
lines changed

examples/feature-examples/src/pages/extensions/dynamic-group/index.tsx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default function DynamicGroupDemo() {
203203
text: 'dynamic-group_2',
204204
resizable: true,
205205
properties: {
206-
transformWithContainer: false,
206+
transformWithContainer: true,
207207
width: 520,
208208
height: 350,
209209
radius: 5,
@@ -310,6 +310,62 @@ export default function DynamicGroupDemo() {
310310

311311
const rerender = () => {}
312312

313+
// 导出当前图数据为 JSON 文件
314+
const handleExportGraph = () => {
315+
const lf = lfRef.current
316+
if (!lf) return
317+
const data = lf.getGraphRawData() as GraphConfigData
318+
try {
319+
const json = JSON.stringify(data, null, 2)
320+
const blob = new Blob([json], { type: 'application/json;charset=utf-8' })
321+
const url = URL.createObjectURL(blob)
322+
const a = document.createElement('a')
323+
a.href = url
324+
a.download = 'dynamic-group-graph.json'
325+
document.body.appendChild(a)
326+
a.click()
327+
document.body.removeChild(a)
328+
URL.revokeObjectURL(url)
329+
message.success('导出成功')
330+
} catch (err) {
331+
console.error('导出失败:', err)
332+
message.error('导出失败,请查看控制台日志')
333+
}
334+
}
335+
336+
// 从本地 JSON 文件导入图数据
337+
const handleImportGraph = () => {
338+
const lf = lfRef.current
339+
if (!lf) return
340+
const input = document.createElement('input')
341+
input.type = 'file'
342+
input.accept = '.json,application/json'
343+
input.onchange = () => {
344+
const file = input.files?.[0]
345+
if (!file) return
346+
const reader = new FileReader()
347+
reader.onload = () => {
348+
try {
349+
const text = String(reader.result || '')
350+
const parsed = JSON.parse(text) as GraphConfigData
351+
// 简单校验结构
352+
if (!parsed || typeof parsed !== 'object') {
353+
throw new Error('无效的图数据')
354+
}
355+
// 渲染导入数据
356+
lf.clearData()
357+
lf.render(parsed)
358+
message.success('导入成功')
359+
} catch (err) {
360+
console.error('导入失败:', err)
361+
message.error('导入失败:JSON 格式不合法或数据结构错误')
362+
}
363+
}
364+
reader.readAsText(file)
365+
}
366+
input.click()
367+
}
368+
313369
return (
314370
<Card
315371
title="LogicFlow Extension - DynamicGroup"
@@ -322,6 +378,12 @@ export default function DynamicGroupDemo() {
322378
<Button type="primary" key="rerender" onClick={rerender}>
323379
重新渲染
324380
</Button>
381+
<Button type="primary" key="export" onClick={handleExportGraph}>
382+
导出 JSON
383+
</Button>
384+
<Button type="primary" key="import" onClick={handleImportGraph}>
385+
导入 JSON
386+
</Button>
325387
</Flex>
326388
<Divider />
327389
<div ref={containerRef} id="graph" className="viewport"></div>

examples/feature-examples/src/pages/graph/index.less

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.viewport {
22
position: relative;
3+
width: 80vw;
34
height: 80vh;
45
overflow: hidden;
56
}
@@ -9,6 +10,34 @@
910
outline: none;
1011
}
1112

13+
.react-algo-node {
14+
display: flex;
15+
align-items: center;
16+
width: 100%;
17+
height: 100%;
18+
border: 1px solid #e59b68;
19+
border-radius: 14px;
20+
21+
img {
22+
width: 24px;
23+
height: 24px;
24+
}
25+
26+
span {
27+
margin-left: 4px;
28+
color: #000000a6;
29+
font-size: 12px;
30+
}
31+
32+
&.dark {
33+
background-color: #141414;
34+
35+
span {
36+
color: #fff;
37+
}
38+
}
39+
}
40+
1241
.dnd-item {
1342
display: flex;
1443
align-items: center;

0 commit comments

Comments
 (0)