Skip to content

Commit bbf2cab

Browse files
author
wb-zyx597643
committed
feat: 添加双击节点时间
1 parent aac1059 commit bbf2cab

File tree

6 files changed

+23
-36
lines changed

6 files changed

+23
-36
lines changed

README.en-US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ npm install react-visual-modeling
4646
| onFocusNode | focus node events | <font color="c41d7f">(node) => void</font> | - |
4747
| onFocusEdge | focus edge events | <font color="c41d7f">(edge) => void</font> | - |
4848
| onFocusCanvas | focus canvas blank events | <font color="c41d7f">() => void</font> | - |
49+
| onDblClickNode| double click node events | <font color="c41d7f">() => void</font> | - |
4950

5051
<br>
5152

@@ -141,6 +142,7 @@ import 'react-visual-modeling/dist/index.css';
141142
onFocusNode={() => {}}
142143
onFocusEdge={() => {}}
143144
onFocusCanvas={() => {}}
145+
onDblClickNode={() => {}}
144146
>
145147
</VisualModeling>
146148
```

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ $ npm install react-visual-modeling butterfly-dag -S
4747
|onFocusNode |聚焦节点事件 |`(node) => void`| - |
4848
|onFocusEdge |聚焦线段事件 |`(edge) => void`| - |
4949
|onFocusCanvas | 聚焦空白处事件 | `() => void` | |-|
50+
|onDblClickNode| 双击节点事件 |`(node) => void`| -
5051

5152
<br />
5253

@@ -144,6 +145,7 @@ import 'react-visual-modeling/dist/index.css';
144145
onFocusNode={() => {}}
145146
onFocusEdge={() => {}}
146147
onFocusCanvas={() => {}}
148+
onDblClickNode={(node) => {}} // Double Click Node Event
147149
/>
148150
```
149151

@@ -168,6 +170,7 @@ interface IProps {
168170
onFocusNode(node: any): void, // 聚焦节点事件
169171
onFocusEdge(edge: any): void, // 聚焦线段事件
170172
onFocusCanvas(): void, // 聚焦空白处事件
173+
onDblClickNode ? (node: any) : void, // 双击节点事件
171174
};
172175

173176
// 节点字段每列的属性设置

example/index.jsx

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import ReactDOM from 'react-dom';
44
import {Layout, Tooltip} from 'antd';
55
import {BrowserRouter as Router} from 'react-router-dom';
66

7-
import TableBuilding from '../src/index.tsx';
87
import {nodeMenu, edgeMenu, actionMenu} from './menu';
8+
import TableBuilding from '../src/index.tsx';
99
import * as MockData from './mock_data/data.jsx';
1010

1111
import 'antd/dist/antd.css';
@@ -89,31 +89,6 @@ class Component extends React.Component {
8989
});
9090
}
9191

92-
onAddEdge = () => {
93-
const data = this.state.data;
94-
95-
data.edges.push({
96-
"id": 1,
97-
"sourceNode": "aaa",
98-
"targetNode": "bbb",
99-
"source": "field_1",
100-
"target": "field_2"
101-
});
102-
103-
this.setState({
104-
data: {...data}
105-
});
106-
}
107-
108-
onDelEdge = () => {
109-
const data = this.state.data;
110-
data.edges.pop();
111-
112-
this.setState({
113-
data: {...data}
114-
});
115-
}
116-
11792
render() {
11893
return (
11994
<TableBuilding
@@ -137,6 +112,7 @@ class Component extends React.Component {
137112
// =========== 节点Table相关属性 ===========
138113
columns={this.state.columns}
139114
data={this.state.data}
115+
onDblClickNode={(node) => {}}
140116
emptyContent={
141117
<div className="empty-content">
142118
<p className="desc">暂无数据</p>
@@ -146,16 +122,14 @@ class Component extends React.Component {
146122
e.stopPropagation();
147123
console.log('自定义空状态');
148124
}}
149-
>
150-
+ 添加字段
151-
</p>
125+
>+ 添加字段</p>
152126
</div>
153127
}
154128

155129
// =========== 菜单相关属性 ===========
156130
nodeMenu={nodeMenu}
157131
edgeMenu={edgeMenu}
158-
actionMenu={actionMenu({onAddEdge: this.onAddEdge, onDelEdge: this.onDelEdge})}
132+
actionMenu={actionMenu}
159133

160134
// =========== 画布配置 ===========
161135
config={config}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-visual-modeling",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "一个基于React的数据可视化建模的DAG图,适用于UML,数据库建模,数据仓库建设等业务",
55
"main": "dist/index.js",
66
"pack": "pack/index.js",

src/canvas/node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export default class TableNode extends Node {
5050
} else {
5151
$(this.dom).find('.title').css('width', this.options._emptyWidth || 150);
5252
}
53+
54+
$(this.dom).on('dblclick', (e) => {
55+
this.emit('system.node.dblClick', {
56+
node: this
57+
});
58+
});
5359
// 生成右键菜单
5460
this._createRightMenu();
5561
}

src/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ interface ComProps {
7474
onFocusNode(node: any): void, // 聚焦节点事件
7575
onFocusEdge(edge: any): void, // 聚焦线段事件
7676
onFocusCanvas(): void, // 聚焦空白处事件
77+
onDblClickNode?(node: any): void, // 双击节点事件
7778

7879
// TODO: 展开/收缩节点
7980
// onDeteleNodes(nodeInfo: any): void,
@@ -236,6 +237,10 @@ export default class TableBuilding extends React.Component<ComProps, any> {
236237
this._focusNode(data.node);
237238
});
238239

240+
this.canvas.on('system.node.dblClick', (data: any) => {
241+
this.props.onDblClickNode && this.props.onDblClickNode(data.node);
242+
});
243+
239244
this.canvas.on('system.link.click', (data: any) => {
240245
this._focusLink(data.edge);
241246
});
@@ -272,7 +277,6 @@ export default class TableBuilding extends React.Component<ComProps, any> {
272277
});
273278

274279
let diffInfo = diffPropsData(result, this.canvasData, this.props.columns);
275-
276280
if (diffInfo.addNodes.length > 0) {
277281
this.canvas.addNodes(diffInfo.addNodes);
278282
}
@@ -282,9 +286,8 @@ export default class TableBuilding extends React.Component<ComProps, any> {
282286
if (diffInfo.addEdges.length > 0) {
283287
this.canvas.addEdges(diffInfo.addEdges);
284288
}
285-
286289
if (diffInfo.rmEdges.length > 0) {
287-
this.canvas.removeEdges(diffInfo.rmEdges.map(edge => edge.id));
290+
this.canvas.removeEdges(diffInfo.rmEdges);
288291
}
289292

290293
// 更新节点中的字段
@@ -300,7 +303,7 @@ export default class TableBuilding extends React.Component<ComProps, any> {
300303
}
301304

302305
this.canvasData = result;
303-
return true;
306+
return false;
304307
}
305308

306309
componentWillUnmount() {
@@ -358,7 +361,6 @@ export default class TableBuilding extends React.Component<ComProps, any> {
358361
let linksInfo = links.map((item) => {
359362
return item.options;
360363
});
361-
362364
this.props.onChange && this.props.onChange({
363365
type: 'system.link.delete',
364366
links: linksInfo

0 commit comments

Comments
 (0)