-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shinetingli
committed
Feb 16, 2023
1 parent
8e73d0c
commit 4a5f2e7
Showing
7 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ref } from "vue"; | ||
|
||
const treeData = ref<any[]>([]); | ||
|
||
export const useData = () => { | ||
return { | ||
treeData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { INodeItem } from "./type"; | ||
import { useData } from "./useData"; | ||
import { canAddChildNode } from "./useTool"; | ||
|
||
export const useMove = () => { | ||
const { treeData } = useData(); | ||
|
||
const checkChildren = (parent: any[], list: any[]): false | INodeItem => { | ||
let parentNode = null; | ||
parent.some((node) => { | ||
if (node.children === list) { | ||
parentNode = node; | ||
return true; | ||
} | ||
|
||
if (Array.isArray(node.children) && node.children.length > 0) { | ||
return checkChildren(node.children, list); | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
return parentNode || false; | ||
}; | ||
|
||
const handleMoveCallback = (evt: any): boolean => { | ||
const { draggedContext, relatedContext } = evt; | ||
|
||
if (!relatedContext.list) { | ||
return false; | ||
} | ||
const fromType = draggedContext.element?.type; | ||
const { list } = relatedContext; | ||
|
||
// 判断在root节点 | ||
if (treeData.value === list) { | ||
return canAddChildNode(fromType, "Single_Object"); | ||
} | ||
|
||
const node = checkChildren(treeData.value, list); | ||
if (node) { | ||
return canAddChildNode(fromType, node.type!); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
return { | ||
handleMoveCallback, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters