Files
FiDA_Front/src/components/Canvas/FlowCanvas/manager/StateManager.ts

69 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-02-26 11:45:32 +08:00
import { ref, computed } from "vue";
export class StateManager {
vueFlow: any
nodes: any
2026-02-27 11:43:27 +08:00
nodes_: any
2026-02-26 11:45:32 +08:00
edges: any
zoom: any
2026-02-27 09:56:49 +08:00
// 管理器
eventManager: any
flowManager: any
nodeManager: any
// 设置管理器
setManager(options) {
options.eventManager && (this.eventManager = options.eventManager)
options.flowManager && (this.flowManager = options.flowManager)
options.nodeManager && (this.nodeManager = options.nodeManager)
}
2026-02-26 11:45:32 +08:00
constructor(options) {
this.vueFlow = options.vueFlow
this.nodes = ref<any[]>([
2026-02-26 13:47:26 +08:00
// {
// id: '8',
// type: 'SecondaryNode',
// class: 'custom-node',
// position: { x: 0, y: 0 },
// data: { component: card, type: 'edit-material' }
// }
2026-02-26 11:45:32 +08:00
]);
2026-02-27 11:43:27 +08:00
this.nodes_ = computed(() => {
return this.nodes.value.map((node, index) => {
const obj = {
...node,
}
if (index === 0) {
obj.class = 'custom-node start';
obj.type = 'InputNode';
} else {
obj.class = 'custom-node';
obj.type = 'SecondaryNode';
}
return obj
})
})
2026-02-26 11:45:32 +08:00
this.edges = computed(() => {
const arr = []
this.nodes.value.forEach((node, index) => {
if (index < this.nodes.value.length - 1) {
const id = node.id
const target = this.nodes.value[index + 1].id
arr.push({
id: `el-${id}-${target}`,
source: id,
target: target,
type: 'smoothstep'
})
}
})
return arr
})
this.zoom = ref(1)
}
2026-02-27 11:43:27 +08:00
getLastNode() {
return this.nodes.value[this.nodes.value.length - 1]
}
2026-02-26 11:45:32 +08:00
}