This commit is contained in:
lzp
2026-03-04 15:06:22 +08:00
parent 9817e5e0db
commit cee42d8b78
28 changed files with 340 additions and 84 deletions

View File

@@ -14,19 +14,30 @@ export class StateManager {
nodes_: any
edges: any
zoom: any
// 管理器
tool: any
cursor: any
nodesDraggable: any
panOnDrag: any
// 管理器
eventManager: any
flowManager: any
nodeManager: any
toolManager: any
// 设置管理器
setManager(options) {
options.eventManager && (this.eventManager = options.eventManager)
options.flowManager && (this.flowManager = options.flowManager)
options.nodeManager && (this.nodeManager = options.nodeManager)
options.toolManager && (this.toolManager = options.toolManager)
}
constructor(options) {
this.vueFlow = options.vueFlow
this.zoom = ref(1)
this.tool = ref("")
this.cursor = ref("")
this.nodesDraggable = ref(false)
this.panOnDrag = ref(false)
this.nodes = ref<NodesItem[]>([]);
this.nodes_ = computed(() => {
return this.nodes.value.map((node, index) => {
@@ -41,14 +52,14 @@ export class StateManager {
const superiorID = node.data.superiorID;
const isSuperior = this.nodes.value.some((v) => v.id === superiorID)
const isSubord = this.nodes.value.some((v) => v.data.superiorID === node.id)
if (!superiorID) {// 没有上级ID
if (!isSuperior && isSubord) {// 没有上级 有下级
obj.type = NODE_TYPE.INPUT;
} else if (isSuperior && isSubord) {// 有上级ID并找到下级
} else if (isSuperior && isSubord) {// 有上级下级
obj.type = NODE_TYPE.SECONDARY;
} else if (isSuperior && !isSubord) {// 有上级ID但未找到下级
} else if (isSuperior && !isSubord) {// 有上级 没有下级
obj.type = NODE_TYPE.OUTPUT;
} else {// 其他情况-有上级ID未找到上
obj.type = NODE_TYPE.INPUT;
} else {// 其他情况-有上级 没有下
obj.type = NODE_TYPE.ALONE;
}
return obj
})
@@ -105,4 +116,15 @@ export class StateManager {
getLastNode() {
return this.nodes.value[this.nodes.value.length - 1]
}
/** 设置工具 */
setTool(tool: string) {
this.tool.value = tool
}
/** 设置光标 */
setCursor(v: string) { this.cursor.value = v }
/** 设置节点是否可拖动 */
setNodesDraggable(v: boolean) { this.nodesDraggable.value = v }
/** 设置是否可以平移画布 */
setPanOnDrag(v: boolean) { this.panOnDrag.value = v }
}