fix
This commit is contained in:
@@ -9,6 +9,9 @@ export class FlowManager {
|
||||
this.stateManager.zoom.value = zoom
|
||||
this.vueFlow.value.zoomTo(zoom)
|
||||
}
|
||||
getNodeById(id: string) {
|
||||
return this.vueFlow.value.getNode(id)
|
||||
}
|
||||
getLastNode() {
|
||||
const lastNode = this.stateManager.getLastNode()
|
||||
if (lastNode?.id) {
|
||||
|
||||
@@ -28,13 +28,17 @@ export class NodeManager {
|
||||
|
||||
/** 创建节点 */
|
||||
createNode(options: NodeOptions) {
|
||||
const lastNode = this.stateManager.flowManager.getLastNode();
|
||||
const superiorID = options?.data?.superiorID
|
||||
const snode = superiorID ? this.stateManager.flowManager.getNodeById(superiorID) : this.stateManager.flowManager.getLastNode();
|
||||
const id = options.id || createId()
|
||||
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 }
|
||||
!snode ? { x: positionX, y: positionY } :
|
||||
{
|
||||
x: snode.position.x + snode.dimensions.width + 50 + positionX,
|
||||
y: snode.position.y + positionY
|
||||
}
|
||||
const data = options?.data || {}
|
||||
data['component'] = options.component
|
||||
const options_ = {
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface NodesItem {
|
||||
type: string
|
||||
class: string
|
||||
position: { x: number, y: number }
|
||||
data: { component: any, type: string }
|
||||
data: { component: any, type: string, superiorID?: string }
|
||||
}
|
||||
export class StateManager {
|
||||
vueFlow: any
|
||||
@@ -30,15 +30,25 @@ export class StateManager {
|
||||
this.nodes = ref<NodesItem[]>([]);
|
||||
this.nodes_ = computed(() => {
|
||||
return this.nodes.value.map((node, index) => {
|
||||
const obj = {
|
||||
...node,
|
||||
}
|
||||
if (index === 0) {
|
||||
const obj = node;
|
||||
// if (index === 0) {
|
||||
// obj.type = NODE_TYPE.INPUT;
|
||||
// } else if (index === this.nodes.value.length - 1) {
|
||||
// obj.type = NODE_TYPE.OUTPUT;
|
||||
// } else {
|
||||
// obj.type = NODE_TYPE.SECONDARY;
|
||||
// }
|
||||
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
|
||||
obj.type = NODE_TYPE.INPUT;
|
||||
} else if (index === this.nodes.value.length - 1) {
|
||||
obj.type = NODE_TYPE.OUTPUT;
|
||||
} else {
|
||||
} else if (isSuperior && isSubord) {// 有上级ID并找到下级
|
||||
obj.type = NODE_TYPE.SECONDARY;
|
||||
} else if (isSuperior && !isSubord) {// 有上级ID但未找到下级
|
||||
obj.type = NODE_TYPE.OUTPUT;
|
||||
} else {// 其他情况-有上级ID未找到上级
|
||||
obj.type = NODE_TYPE.INPUT;
|
||||
}
|
||||
return obj
|
||||
})
|
||||
@@ -47,12 +57,25 @@ export class StateManager {
|
||||
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
|
||||
// if (index < this.nodes.value.length - 1) {
|
||||
// const source = node.id
|
||||
// const target = this.nodes.value[index + 1].id
|
||||
// arr.push({
|
||||
// id: `el-${source}-${target}`,
|
||||
// source: source,
|
||||
// target: target,
|
||||
// selectable: false,
|
||||
// type: 'default'
|
||||
// })
|
||||
// }
|
||||
const superiorID = node.data.superiorID;
|
||||
const isSuperior = this.nodes.value.some((v) => v.id === superiorID)
|
||||
if (superiorID && isSuperior) {
|
||||
const source = node.data.superiorID
|
||||
const target = node.id
|
||||
arr.push({
|
||||
id: `el-${id}-${target}`,
|
||||
source: id,
|
||||
id: `el-${source}-${target}`,
|
||||
source: source,
|
||||
target: target,
|
||||
selectable: false,
|
||||
type: 'default'
|
||||
|
||||
Reference in New Issue
Block a user