Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ui/src/workflow-canvas/nodes/loop-body-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,37 @@ const renderGraphData = (data?: LogicFlow.GraphConfigData) => {
lfInstance.render(data ?? {})
}

// 嵌套画布初始化时按 getBoundingClientRect 取尺寸,会受主画布缩放影响,折叠时还会取到 0;
// 且容器尺寸变化(展开、放大)不会触发 LogicFlow 自身的 resize。
// 这里监听容器布局尺寸(clientWidth/clientHeight 不受 transform 影响),同步画布尺寸并把内容居中。
let containerResizeObserver: ResizeObserver | null = null
let centerTimer: ReturnType<typeof setTimeout> | undefined

function centerLoopBody() {
const container = containerRef.value
const lfInstance = lf.value
if (!container || !lfInstance) return
const { clientWidth, clientHeight } = container
if (clientWidth <= 0 || clientHeight <= 0) return
lfInstance.resize(clientWidth, clientHeight)
lfInstance.translateCenter()
}

function scheduleCenterLoopBody() {
if (centerTimer) clearTimeout(centerTimer)
// 等待嵌套节点完成高度测量后再居中
centerTimer = setTimeout(() => {
centerTimer = undefined
centerLoopBody()
}, 200)
}

onMounted(() => {
renderGraphData(cloneDeep(model.properties.workflow as LogicFlow.GraphConfigData))
if (containerRef.value) {
containerResizeObserver = new ResizeObserver(scheduleCenterLoopBody)
containerResizeObserver.observe(containerRef.value)
}
set(model, 'setLoopBody', setLoopBody)
set(model, 'set_loop_body', setLoopBody)
set(model, 'validate', validate)
Expand All @@ -174,6 +203,9 @@ onMounted(() => {
})

onUnmounted(() => {
containerResizeObserver?.disconnect()
containerResizeObserver = null
if (centerTimer) clearTimeout(centerTimer)
disconnectByFlow(lf.value?.graphModel.flowId ?? '')
lf.value = null
})
Expand Down
Loading