2026-02-27 09:56:49 +08:00
|
|
|
import { createId } from '../../tools/tools'
|
|
|
|
|
interface NodeOptions {
|
|
|
|
|
id?: string
|
|
|
|
|
type: "InputNode" | "SecondaryNode"
|
|
|
|
|
class?: string
|
|
|
|
|
position?: { x: number, y: number }
|
|
|
|
|
component: any
|
|
|
|
|
data?: object
|
|
|
|
|
}
|
2026-02-26 16:55:25 +08:00
|
|
|
export class NodeManager {
|
|
|
|
|
stateManager: any
|
|
|
|
|
vueFlow: any
|
|
|
|
|
constructor(options) {
|
|
|
|
|
this.stateManager = options.stateManager;
|
|
|
|
|
this.vueFlow = options.vueFlow
|
|
|
|
|
}
|
|
|
|
|
nodes: [
|
2026-02-27 09:56:49 +08:00
|
|
|
|
2026-02-26 16:55:25 +08:00
|
|
|
]
|
2026-02-27 09:56:49 +08:00
|
|
|
createNode(options: NodeOptions) {
|
|
|
|
|
const id = options.id || createId()
|
|
|
|
|
const type = options.type || 'InputNode'
|
|
|
|
|
const class_ = options.class || 'custom-node'
|
|
|
|
|
const position = options.position || { x: 0, y: 0 }
|
|
|
|
|
const data = options.data || {}
|
|
|
|
|
data['component'] = options.component
|
|
|
|
|
this.stateManager.nodes.value.push({
|
|
|
|
|
id,
|
|
|
|
|
type,
|
|
|
|
|
class: class_,
|
|
|
|
|
position,
|
|
|
|
|
data
|
|
|
|
|
})
|
|
|
|
|
console.log(this.stateManager.nodes.value)
|
|
|
|
|
}
|
2026-02-26 16:55:25 +08:00
|
|
|
}
|