@@ -10,17 +10,25 @@ import i18n from '@/locales'
1010import { WorkflowType } from '@/enums/workflow'
1111import { nodeDict } from '@/workflow/common/data'
1212import { isActive , connect , disconnect } from './teleport'
13+ import { t } from '@/locales'
14+ import { type Dict } from '@/api/type/common'
1315class AppNode extends HtmlResize . view {
1416 isMounted
1517 r ?: any
1618 component : any
1719 app : any
1820 root ?: any
1921 VueNode : any
22+ up_node_field_dict ?: Dict < Array < any > >
2023 constructor ( props : any , VueNode : any ) {
2124 super ( props )
2225 this . component = VueNode
2326 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+
2432 if ( props . model . properties . noRender ) {
2533 delete props . model . properties . noRender
2634 } else {
@@ -30,21 +38,74 @@ class AppNode extends HtmlResize.view {
3038 }
3139 }
3240 function getNodesName ( num : number ) {
33- let number = num
41+ const number = num
3442 const name = props . model . properties . stepName + number
3543 if ( ! props . graphModel . nodes ?. some ( ( node : any ) => node . properties . stepName === name . trim ( ) ) ) {
3644 props . model . properties . stepName = name
3745 } else {
38- number += 1
39- getNodesName ( number )
46+ getNodesName ( number + 1 )
4047 }
4148 }
4249 props . model . properties . config = nodeDict [ props . model . type ] . properties . config
4350 if ( props . model . properties . height ) {
4451 props . model . height = props . model . properties . height
4552 }
4653 }
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+ }
4799
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+ }
48109 getAnchorShape ( anchorData : any ) {
49110 const { x, y, type } = anchorData
50111 let isConnect = false
@@ -276,7 +337,7 @@ class AppNodeModel extends HtmlResize.model {
276337 }
277338
278339 setAttributes ( ) {
279- const { t } = i18n . global ;
340+ const { t } = i18n . global
280341 this . width = this . get_width ( )
281342 const isLoop = ( node_id : string , target_node_id : string ) => {
282343 const up_node_list = this . graphModel . getNodeIncomingNode ( node_id )
0 commit comments