File tree 3 files changed +69
-2
lines changed
3 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import Share from './component/Share';
5
5
import Setting from './component/Setting' ;
6
6
import Links from './component/Links' ;
7
7
import './index.less' ;
8
- import CustomNode from './lib/ utils/registerNode' ;
9
- import CustomListener from './lib/ utils/addListener' ;
8
+ import CustomNode from './utils/registerNode' ;
9
+ import CustomListener from './utils/addListener' ;
10
10
11
11
LogicFlow . use ( Snapshot ) ;
12
12
LogicFlow . use ( Dnd ) ;
Original file line number Diff line number Diff line change
1
+ import LogicFlow from '@logicflow/core' ;
2
+
3
+ class CustomListener {
4
+ lf : LogicFlow ;
5
+
6
+ constructor ( lf : LogicFlow ) {
7
+ this . lf = lf ;
8
+ }
9
+
10
+ addAll ( ) {
11
+ this . addNodeListener ( ) ;
12
+ // ...
13
+ }
14
+
15
+ addNodeListener ( ) {
16
+ const { lf } = this ;
17
+ lf . on ( 'node:click' , ( { data } ) => {
18
+ console . log ( '单击' , data ) ;
19
+ } ) ;
20
+ lf . on ( 'node:dbclick' , ( { data } ) => {
21
+ console . log ( '双击' , data ) ;
22
+ } ) ;
23
+ }
24
+ }
25
+
26
+ export default CustomListener ;
Original file line number Diff line number Diff line change
1
+ import LogicFlow from '@logicflow/core' ;
2
+
3
+ class CustomNode {
4
+ lf : LogicFlow ;
5
+
6
+ constructor ( lf : LogicFlow ) {
7
+ this . lf = lf ;
8
+ }
9
+
10
+ // 注册所有的自定义节点
11
+ registerAll ( ) {
12
+ this . registerRect ( ) ;
13
+ // ...
14
+ }
15
+
16
+ registerRect ( ) {
17
+ this . lf . register ( 'rect' , ( { RectNode, RectNodeModel } ) => {
18
+ class CustomRectModel extends RectNodeModel {
19
+ getConnectedSourceRules ( ) {
20
+ const rules = super . getConnectedSourceRules ( ) ;
21
+ const rule = {
22
+ message : '不满足连线的校验规则' ,
23
+ validate : ( source , target ) => {
24
+ console . log ( target ) ;
25
+ // 校验规则
26
+ return true ;
27
+ } ,
28
+ } ;
29
+ rules . push ( rule ) ;
30
+ return rules ;
31
+ }
32
+ }
33
+ return {
34
+ view : RectNode ,
35
+ model : CustomRectModel ,
36
+ } ;
37
+ } ) ;
38
+ }
39
+ }
40
+
41
+ export default CustomNode ;
You can’t perform that action at this time.
0 commit comments