@@ -2,6 +2,90 @@ import GroovyScript from "@/components/Flow/utils/script";
22
33const FlowUtils = {
44
5+ generateUUID ( ) {
6+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
7+ const r = ( Math . random ( ) * 16 ) | 0 ;
8+ const v = c === 'x' ? r : ( r & 0x3 ) | 0x8 ;
9+ return v . toString ( 16 ) ;
10+ } ) ;
11+ } ,
12+
13+ getNode ( nodeId :string ) {
14+ //@ts -ignore
15+ const data = window . lfRef ?. current . getGraphData ( ) ;
16+ const nodes = data . nodes ;
17+
18+ const getNode = ( nodeId : String ) => {
19+ for ( const node of nodes ) {
20+ if ( node . id === nodeId ) {
21+ return node ;
22+ }
23+ }
24+ }
25+ return getNode ( nodeId ) ;
26+ } ,
27+
28+ getButtons ( nodeId :string ) {
29+ const node = FlowUtils . getNode ( nodeId ) ;
30+ const buttons = node . properties . buttons || [ ] ;
31+ buttons . sort ( ( a :any , b :any ) => {
32+ return a . order - b . order ;
33+ } )
34+ return buttons ;
35+ } ,
36+
37+
38+ updateButton ( nodeId :string , button :any ) {
39+ //@ts -ignore
40+ const data = window . lfRef ?. current . getGraphData ( ) ;
41+ const nodes = data . nodes ;
42+ const getNode = ( nodeId : String ) => {
43+ for ( const node of nodes ) {
44+ if ( node . id === nodeId ) {
45+ return node ;
46+ }
47+ }
48+ }
49+ const node = getNode ( nodeId ) ;
50+ const buttons = node . properties . buttons || [ ] ;
51+
52+ let update = false ;
53+
54+ for ( const item of buttons ) {
55+ if ( item . id == button . id ) {
56+ item . name = button . name ;
57+ item . color = button . color ;
58+ item . event = button . event ;
59+ item . order = button . order ;
60+
61+ update = true ;
62+ }
63+ }
64+ if ( ! update ) {
65+ button . id = FlowUtils . generateUUID ( ) ;
66+ node . properties . buttons = [ ...buttons , button ] ;
67+ }
68+ this . render ( data ) ;
69+ } ,
70+
71+
72+ deleteButton ( nodeId :string , buttonId :string ) {
73+ //@ts -ignore
74+ const data = window . lfRef ?. current . getGraphData ( ) ;
75+ const nodes = data . nodes ;
76+ const getNode = ( nodeId : String ) => {
77+ for ( const node of nodes ) {
78+ if ( node . id === nodeId ) {
79+ return node ;
80+ }
81+ }
82+ }
83+ const node = getNode ( nodeId ) ;
84+ const buttons = node . properties . buttons || [ ] ;
85+ node . properties . buttons = buttons . filter ( ( item :any ) => item . id !== buttonId ) ;
86+ this . render ( data ) ;
87+ } ,
88+
589 getEdges ( nodeId : String ) {
690 //@ts -ignore
791 const data = window . lfRef ?. current . getGraphData ( ) ;
0 commit comments