2026-02-27 09:56:49 +08:00
|
|
|
import { createId } from '../../tools/tools'
|
2026-02-27 11:43:27 +08:00
|
|
|
import card from '../components/cards/index.vue'
|
|
|
|
|
import resultImage from '../components/result/result-image.vue'
|
|
|
|
|
import { NODE_DATATYPE } from '../tools/index.d'
|
2026-02-27 09:56:49 +08:00
|
|
|
interface NodeOptions {
|
|
|
|
|
id?: string
|
|
|
|
|
position?: { x: number, y: number }
|
2026-02-27 11:43:27 +08:00
|
|
|
positionX?: number
|
|
|
|
|
positionY?: number
|
|
|
|
|
component?: any
|
2026-02-27 09:56:49 +08:00
|
|
|
data?: object
|
2026-02-27 11:43:27 +08:00
|
|
|
}// 不可传入type class (内部使用)
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2026-02-27 09:56:49 +08:00
|
|
|
|
2026-02-27 11:43:27 +08:00
|
|
|
/** 删除节点 */
|
|
|
|
|
deleteNode(id: string) {
|
2026-02-27 14:58:36 +08:00
|
|
|
this.stateManager.deleteNode(id)
|
|
|
|
|
}
|
|
|
|
|
/** 添加节点 */
|
|
|
|
|
addNode(node: any) {
|
|
|
|
|
this.stateManager.addNode(node)
|
2026-02-27 11:43:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 创建节点 */
|
2026-02-27 09:56:49 +08:00
|
|
|
createNode(options: NodeOptions) {
|
2026-02-27 11:43:27 +08:00
|
|
|
const lastNode = this.stateManager.flowManager.getLastNode();
|
2026-02-27 09:56:49 +08:00
|
|
|
const id = options.id || createId()
|
2026-02-27 11:43:27 +08:00
|
|
|
const positionX = options.positionX || 0
|
|
|
|
|
const positionY = options.positionY || 0
|
|
|
|
|
const position = options.position ||
|
|
|
|
|
!lastNode ? { x: positionX, y: positionY } :
|
|
|
|
|
{ x: lastNode.position.x + lastNode.dimensions.width + 50 + positionX, y: lastNode.position.y + positionY }
|
2026-02-27 14:58:36 +08:00
|
|
|
const data = options?.data || {}
|
2026-02-27 09:56:49 +08:00
|
|
|
data['component'] = options.component
|
2026-02-27 11:43:27 +08:00
|
|
|
const options_ = {
|
2026-02-27 09:56:49 +08:00
|
|
|
id,
|
|
|
|
|
position,
|
|
|
|
|
data
|
2026-02-27 11:43:27 +08:00
|
|
|
}
|
2026-02-27 14:58:36 +08:00
|
|
|
this.addNode(options_)
|
2026-02-27 11:43:27 +08:00
|
|
|
return options_;
|
|
|
|
|
}
|
|
|
|
|
/** 创建结果节点 */
|
|
|
|
|
createResultNode(options?: NodeOptions) {
|
|
|
|
|
const options_ = {
|
2026-02-27 14:58:36 +08:00
|
|
|
...(options ? options : {}),
|
2026-02-27 11:43:27 +08:00
|
|
|
component: resultImage,
|
|
|
|
|
data: {
|
|
|
|
|
type: NODE_DATATYPE.RESULT_IMAGE,
|
2026-02-27 14:58:36 +08:00
|
|
|
isHeader: true,
|
2026-02-27 11:49:08 +08:00
|
|
|
...(options?.data || {}),
|
2026-02-27 11:43:27 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return this.createNode(options_)
|
|
|
|
|
}
|
|
|
|
|
/** 创建卡片选择节点 */
|
|
|
|
|
createCardsSelect(options?: NodeOptions) {
|
|
|
|
|
const options_ = {
|
2026-02-27 14:58:36 +08:00
|
|
|
...(options ? options : {}),
|
2026-02-27 11:43:27 +08:00
|
|
|
component: card,
|
|
|
|
|
positionY: 50,
|
|
|
|
|
data: {
|
|
|
|
|
type: NODE_DATATYPE.CARDS_SELECT,
|
2026-02-27 11:49:08 +08:00
|
|
|
...(options?.data || {}),
|
2026-02-27 11:43:27 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return this.createNode(options_)
|
|
|
|
|
}
|
|
|
|
|
/** 创建卡片节点 */
|
|
|
|
|
createCardNode(options?: NodeOptions) {
|
|
|
|
|
const options_ = {
|
|
|
|
|
...(options ? options : {}),
|
2026-02-27 14:58:36 +08:00
|
|
|
component: card,
|
2026-02-27 11:43:27 +08:00
|
|
|
}
|
|
|
|
|
return this.createNode(options_)
|
2026-02-27 09:56:49 +08:00
|
|
|
}
|
2026-02-26 16:55:25 +08:00
|
|
|
}
|