From 8f772088061e5f65d520a9541172d737d1c2027f Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 5 Nov 2021 13:21:19 +0800 Subject: [PATCH] feat: tree add parent for event callback #4849 --- components/vc-tree/TreeNode.tsx | 5 ++++- components/vc-tree/interface.tsx | 1 + components/vc-tree/props.ts | 2 ++ components/vc-tree/utils/treeUtil.ts | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/vc-tree/TreeNode.tsx b/components/vc-tree/TreeNode.tsx index 3e07512c7..14c5deda0 100644 --- a/components/vc-tree/TreeNode.tsx +++ b/components/vc-tree/TreeNode.tsx @@ -119,7 +119,10 @@ export default defineComponent({ }); const instance = getCurrentInstance(); const eventData = computed(() => { - return convertNodePropsToEventData(props); + const { eventKey } = props; + const { keyEntities } = context.value; + const { parent } = keyEntities[eventKey] || {}; + return { ...convertNodePropsToEventData(props), parent }; }); const dragNodeEvent: DragNodeEvent = reactive({ eventData, diff --git a/components/vc-tree/interface.tsx b/components/vc-tree/interface.tsx index 62220a47f..473a00857 100644 --- a/components/vc-tree/interface.tsx +++ b/components/vc-tree/interface.tsx @@ -34,6 +34,7 @@ export interface EventDataNode extends DataNode { pos?: string; active?: boolean; dataRef?: DataNode; + parent?: DataNode; eventKey?: Key; // 兼容 v2, 推荐直接用 key } diff --git a/components/vc-tree/props.ts b/components/vc-tree/props.ts index f6bcd28ff..6caa7a1a4 100644 --- a/components/vc-tree/props.ts +++ b/components/vc-tree/props.ts @@ -45,6 +45,8 @@ export const treeNodeProps = { /** New added in Tree for easy data access */ data: { type: Object as PropType, default: undefined as DataNode }, + parent: { type: Object as PropType, default: undefined as DataNode }, + isStart: { type: Array as PropType }, isEnd: { type: Array as PropType }, active: { type: Boolean, default: undefined }, diff --git a/components/vc-tree/utils/treeUtil.ts b/components/vc-tree/utils/treeUtil.ts index c1379fa4e..025607669 100644 --- a/components/vc-tree/utils/treeUtil.ts +++ b/components/vc-tree/utils/treeUtil.ts @@ -375,7 +375,7 @@ export function getTreeNodeProps( checked: checkedKeys.indexOf(key) !== -1, halfChecked: halfCheckedKeys.indexOf(key) !== -1, pos: String(entity ? entity.pos : ''), - + parent: entity.parent, // [Legacy] Drag props // Since the interaction of drag is changed, the semantic of the props are // not accuracy, I think it should be finally removed