@@ -10,17 +10,25 @@ import i18n from '@/locales'
10
10
import { WorkflowType } from '@/enums/workflow'
11
11
import { nodeDict } from '@/workflow/common/data'
12
12
import { isActive , connect , disconnect } from './teleport'
13
+ import { t } from '@/locales'
14
+ import { type Dict } from '@/api/type/common'
13
15
class AppNode extends HtmlResize . view {
14
16
isMounted
15
17
r ?: any
16
18
component : any
17
19
app : any
18
20
root ?: any
19
21
VueNode : any
22
+ up_node_field_dict ?: Dict < Array < any > >
20
23
constructor ( props : any , VueNode : any ) {
21
24
super ( props )
22
25
this . component = VueNode
23
26
this . isMounted = false
27
+ props . model . clear_next_node_field = this . clear_next_node_field . bind ( this )
28
+ props . model . get_up_node_field_dict = this . get_up_node_field_dict . bind ( this )
29
+ props . model . get_node_field_list = this . get_node_field_list . bind ( this )
30
+ props . model . get_up_node_field_list = this . get_up_node_field_list . bind ( this )
31
+
24
32
if ( props . model . properties . noRender ) {
25
33
delete props . model . properties . noRender
26
34
} else {
@@ -30,21 +38,74 @@ class AppNode extends HtmlResize.view {
30
38
}
31
39
}
32
40
function getNodesName ( num : number ) {
33
- let number = num
41
+ const number = num
34
42
const name = props . model . properties . stepName + number
35
43
if ( ! props . graphModel . nodes ?. some ( ( node : any ) => node . properties . stepName === name . trim ( ) ) ) {
36
44
props . model . properties . stepName = name
37
45
} else {
38
- number += 1
39
- getNodesName ( number )
46
+ getNodesName ( number + 1 )
40
47
}
41
48
}
42
49
props . model . properties . config = nodeDict [ props . model . type ] . properties . config
43
50
if ( props . model . properties . height ) {
44
51
props . model . height = props . model . properties . height
45
52
}
46
53
}
54
+ get_node_field_list ( ) {
55
+ const result = [ ]
56
+ if ( this . props . model . type === 'start-node' ) {
57
+ result . push ( {
58
+ value : 'global' ,
59
+ label : t ( 'views.applicationWorkflow.variable.global' ) ,
60
+ type : 'global' ,
61
+ children : this . props . model . properties ?. config ?. globalFields || [ ]
62
+ } )
63
+ }
64
+ result . push ( {
65
+ value : this . props . model . id ,
66
+ label : this . props . model . properties . stepName ,
67
+ type : this . props . model . type ,
68
+ children : this . props . model . properties ?. config ?. fields || [ ]
69
+ } )
70
+ return result
71
+ }
72
+ get_up_node_field_dict ( contain_self : boolean , use_cache : boolean ) {
73
+ if ( ! this . up_node_field_dict || ! use_cache ) {
74
+ const up_node_list = this . props . graphModel . getNodeIncomingNode ( this . props . model . id )
75
+ this . up_node_field_dict = up_node_list
76
+ . filter ( ( node ) => node . id != 'start-node' )
77
+ . map ( ( node ) => node . get_up_node_field_dict ( true , use_cache ) )
78
+ . reduce ( ( pre , next ) => ( { ...pre , ...next } ) , { } )
79
+ }
80
+ if ( contain_self ) {
81
+ return {
82
+ ...this . up_node_field_dict ,
83
+ [ this . props . model . id ] : this . get_node_field_list ( )
84
+ }
85
+ }
86
+ return this . up_node_field_dict ? this . up_node_field_dict : { }
87
+ }
88
+
89
+ get_up_node_field_list ( contain_self : boolean , use_cache : boolean ) {
90
+ const result = Object . values ( this . get_up_node_field_dict ( contain_self , use_cache ) ) . reduce (
91
+ ( pre , next ) => [ ...pre , ...next ] ,
92
+ [ ]
93
+ )
94
+ const start_node_field_list = this . props . graphModel
95
+ . getNodeModelById ( 'start-node' )
96
+ . get_node_field_list ( )
97
+ return [ ...start_node_field_list , ...result ]
98
+ }
47
99
100
+ clear_next_node_field ( contain_self : boolean ) {
101
+ const next_node_list = this . props . graphModel . getNodeOutgoingNode ( this . props . model . id )
102
+ next_node_list . forEach ( ( node ) => {
103
+ node . clear_next_node_field ( true )
104
+ } )
105
+ if ( contain_self ) {
106
+ this . up_node_field_dict = undefined
107
+ }
108
+ }
48
109
getAnchorShape ( anchorData : any ) {
49
110
const { x, y, type } = anchorData
50
111
let isConnect = false
@@ -276,7 +337,7 @@ class AppNodeModel extends HtmlResize.model {
276
337
}
277
338
278
339
setAttributes ( ) {
279
- const { t } = i18n . global ;
340
+ const { t } = i18n . global
280
341
this . width = this . get_width ( )
281
342
const isLoop = ( node_id : string , target_node_id : string ) => {
282
343
const up_node_list = this . graphModel . getNodeIncomingNode ( node_id )
0 commit comments