This commit is contained in:
lzp
2026-03-05 11:52:06 +08:00
parent 4de16d7277
commit b45a79dd5c
4 changed files with 45 additions and 24 deletions

View File

@@ -30,7 +30,7 @@
<script setup lang="ts"> <script setup lang="ts">
import flowCanvas from './FlowCanvas/flow-canvas.vue' import flowCanvas from './FlowCanvas/flow-canvas.vue'
import card from './FlowCanvas/components/cards/index.vue' import card from './FlowCanvas/components/nodes/cards/index.vue'
import { computed, ref, markRaw, onMounted, reactive, nextTick } from 'vue' import { computed, ref, markRaw, onMounted, reactive, nextTick } from 'vue'
const data = reactive({ const data = reactive({
x: 100, x: 100,

View File

@@ -127,7 +127,11 @@
stateManager.nodes.value = layout( stateManager.nodes.value = layout(
stateManager.nodes.value, stateManager.nodes.value,
stateManager.edges.value, stateManager.edges.value,
direction direction,
{
nodesep: nodeManager.nodesep,
ranksep: nodeManager.ranksep
}
) )
nextTick(() => { nextTick(() => {
fitView({ maxZoom: 1 }) fitView({ maxZoom: 1 })
@@ -187,6 +191,15 @@
} }
} }
}) })
nodeManager.createResultNode({
data: {
disableDelete: true,
isHeader: false,
data: {
url: props.config.url
}
}
})
}) })
</script> </script>
<style lang="less"> <style lang="less">

View File

@@ -12,6 +12,8 @@ interface NodeOptions {
export class NodeManager { export class NodeManager {
stateManager: any stateManager: any
vueFlow: any vueFlow: any
nodesep = 100 // 节点间距
ranksep = 100 // 层级间距
constructor(options) { constructor(options) {
this.stateManager = options.stateManager; this.stateManager = options.stateManager;
this.vueFlow = options.vueFlow this.vueFlow = options.vueFlow
@@ -37,7 +39,7 @@ export class NodeManager {
(!snode ? (!snode ?
{ x: positionX, y: positionY } : { x: positionX, y: positionY } :
{ {
x: snode.position.x + snode.dimensions.width + 50 + positionX, x: snode.position.x + snode.dimensions.width + this.nodesep + positionX,
y: snode.position.y + positionY y: snode.position.y + positionY
}) })
const data = options?.data || {} const data = options?.data || {}
@@ -104,14 +106,14 @@ export class NodeManager {
copyNodeById(id: string) { copyNodeById(id: string) {
const node = this.stateManager.getNodeById(id) const node = this.stateManager.getNodeById(id)
const flowNode = this.stateManager.flowManager.getNodeById(id) const flowNode = this.stateManager.flowManager.getNodeById(id)
console.log(node,this.stateManager.flowManager.getNodeById(id)) console.log(node, this.stateManager.flowManager.getNodeById(id))
if (!node) return console.warn(`copyNodeById: ${id}找不到对应节点`) if (!node) return console.warn(`copyNodeById: ${id}找不到对应节点`)
const node_ = { const node_ = {
...JSON.parse(JSON.stringify(node)), ...JSON.parse(JSON.stringify(node)),
id: createId(), id: createId(),
position: { position: {
x: node.position.x, x: node.position.x,
y: node.position.y + (flowNode?.dimensions?.height || 0) + 50, y: node.position.y + (flowNode?.dimensions?.height || 0) + this.ranksep,
} }
} }
delete node_.data?.superiorID delete node_.data?.superiorID

View File

@@ -14,7 +14,9 @@ export function useLayout() {
const previousDirection = ref('LR') const previousDirection = ref('LR')
function layout(nodes, edges, direction = 'LR') { function layout(nodes, edges, direction = 'LR', options) {
const nodesep = options?.nodesep || 50 // 节点间距
const ranksep = options?.ranksep || 50 // 层级间距
// 验证和规范化方向参数 // 验证和规范化方向参数
const validDirections = ['TB', 'BT', 'LR', 'RL'] const validDirections = ['TB', 'BT', 'LR', 'RL']
const layoutDirection = validDirections.includes(direction) ? direction : 'LR' const layoutDirection = validDirections.includes(direction) ? direction : 'LR'
@@ -28,7 +30,11 @@ export function useLayout() {
// 根据方向判断是否为水平布局 // 根据方向判断是否为水平布局
const isHorizontal = layoutDirection === 'LR' || layoutDirection === 'RL' const isHorizontal = layoutDirection === 'LR' || layoutDirection === 'RL'
dagreGraph.setGraph({ rankdir: layoutDirection }) dagreGraph.setGraph({
rankdir: layoutDirection,
nodesep,
ranksep,
})
previousDirection.value = layoutDirection previousDirection.value = layoutDirection
@@ -125,20 +131,20 @@ export function findAndAddChild(items, targetId, newChild) {
*/ */
export function findAndRemoveChild(items, targetId) { export function findAndRemoveChild(items, targetId) {
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
const item = items[i] const item = items[i]
// 如果找到目标节点,从当前数组中删除 // 如果找到目标节点,从当前数组中删除
if (item.id === targetId) { if (item.id === targetId) {
items.splice(i, 1) items.splice(i, 1)
return true return true
} }
// 递归搜索子节点 // 递归搜索子节点
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
const found = findAndRemoveChild(item.children, targetId) const found = findAndRemoveChild(item.children, targetId)
if (found) return true if (found) return true
} }
} }
return false return false
} }