Skip to content

Commit 3336f30

Browse files
authored
perf: Workflow Canvas Rendering (#2250)
1 parent 9705f6c commit 3336f30

File tree

4 files changed

+72
-53
lines changed

4 files changed

+72
-53
lines changed

ui/src/workflow/common/NodeCascader.vue

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,12 @@ const wheel = (e: any) => {
4949
5050
function visibleChange(bool: boolean) {
5151
if (bool) {
52-
options.value = getIncomingNode(props.nodeModel.id)
52+
options.value = props.nodeModel.get_up_node_field_list(false, true)
5353
}
5454
}
5555
56-
function _getIncomingNode(id: String, startId: String, value: Array<any>) {
57-
let list = props.nodeModel.graphModel.getNodeIncomingNode(id)
58-
list = list.filter((item: any) => item.id !== startId)
59-
let firstElement = null
60-
if (list.length > 0) {
61-
list.forEach((item: any) => {
62-
if (!value.some((obj: any) => obj.id === item.id)) {
63-
if (!value.some((value_item) => value_item.value === item.id)) {
64-
value.unshift({
65-
value: item.id,
66-
label: item.properties.stepName,
67-
type: item.type,
68-
children: item.properties?.config?.fields || []
69-
})
70-
if (item.properties?.globalFields && item.type === 'start-node') {
71-
firstElement = {
72-
value: 'global',
73-
label: t('views.applicationWorkflow.variable.global'),
74-
type: 'global',
75-
children: item.properties?.config?.globalFields || []
76-
}
77-
}
78-
}
79-
}
80-
})
81-
82-
list.forEach((item: any) => {
83-
_getIncomingNode(item.id, startId, value)
84-
})
85-
}
86-
if (firstElement) {
87-
value.unshift(firstElement)
88-
}
89-
return value
90-
}
91-
function getIncomingNode(id: string) {
92-
return _getIncomingNode(id, id, [])
93-
}
9456
const validate = () => {
95-
const incomingNodeValue = getIncomingNode(props.nodeModel.id)
96-
options.value = incomingNodeValue
57+
const incomingNodeValue = props.nodeModel.get_up_node_field_list(false, true)
9758
if (!data.value || data.value.length === 0) {
9859
return Promise.reject(t('views.applicationWorkflow.variable.ReferencingRequired'))
9960
}
@@ -113,15 +74,9 @@ const validate = () => {
11374
}
11475
return Promise.resolve('')
11576
}
116-
props.nodeModel.graphModel.eventCenter.on('refresh_incoming_node_field', () => {
117-
options.value = getIncomingNode(props.nodeModel.id)
118-
})
119-
props.nodeModel.graphModel.eventCenter.on('refreshFileUploadConfig', () => {
120-
options.value = getIncomingNode(props.nodeModel.id)
121-
})
12277
defineExpose({ validate })
12378
onMounted(() => {
124-
options.value = getIncomingNode(props.nodeModel.id)
79+
options.value = props.nodeModel.get_up_node_field_list(false, true)
12580
})
12681
</script>
12782
<style scoped></style>

ui/src/workflow/common/app-node.ts

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ import i18n from '@/locales'
1010
import { WorkflowType } from '@/enums/workflow'
1111
import { nodeDict } from '@/workflow/common/data'
1212
import { isActive, connect, disconnect } from './teleport'
13+
import { t } from '@/locales'
14+
import { type Dict } from '@/api/type/common'
1315
class 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)

ui/src/workflow/common/edge.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class CustomEdge2 extends BezierEdge {
6868
super.componentWillUnmount()
6969
}
7070
if (isActive()) {
71-
console.log('unmount')
7271
disconnect(this.targetId())
7372
}
7473
this.unmountVueComponent()

ui/src/workflow/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ const renderGraphData = (data?: any) => {
103103
lf.value.deleteEdge(id)
104104
})
105105
})
106+
lf.value.graphModel.eventCenter.on('anchor:drop', (data: any) => {
107+
// 清除当前节点下面的子节点的所有缓存
108+
data.nodeModel.clear_next_node_field(false)
109+
})
106110
107111
setTimeout(() => {
108112
lf.value?.fitView()

0 commit comments

Comments
 (0)