From f35ae0efae219edbd923175249f1d64d01170bf6 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Fri, 17 Jul 2020 16:50:22 +0800 Subject: [PATCH] feat: update tree --- antdv-demo | 2 +- components/tree/DirectoryTree.jsx | 5 +++-- components/tree/util.js | 6 +++--- components/vc-tree/src/Tree.jsx | 4 ++-- components/vc-tree/src/TreeNode.jsx | 4 +++- examples/App.vue | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/antdv-demo b/antdv-demo index 7713f7b97..fe4a4e29a 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit 7713f7b97f8ce3493094935d5fc1eaaf4ea501aa +Subproject commit fe4a4e29aebe7cc1a5bbacf43c2b34671b00c880 diff --git a/components/tree/DirectoryTree.jsx b/components/tree/DirectoryTree.jsx index 78f646278..57b21545e 100644 --- a/components/tree/DirectoryTree.jsx +++ b/components/tree/DirectoryTree.jsx @@ -57,7 +57,8 @@ export default { data() { const props = getOptionProps(this); const { defaultExpandAll, defaultExpandParent, expandedKeys, defaultExpandedKeys } = props; - const { keyEntities } = convertTreeToEntities(this.$slots.default); + const children = getSlot(this); + const { keyEntities } = convertTreeToEntities(children); const state = {}; // Selected keys state._selectedKeys = props.selectedKeys || props.defaultSelectedKeys || []; @@ -67,7 +68,7 @@ export default { if (props.treeData) { state._expandedKeys = getFullKeyListByTreeData(props.treeData); } else { - state._expandedKeys = getFullKeyList(this.$slots.default); + state._expandedKeys = getFullKeyList(children); } } else if (defaultExpandParent) { state._expandedKeys = conductExpandParent(expandedKeys || defaultExpandedKeys, keyEntities); diff --git a/components/tree/util.js b/components/tree/util.js index fcba30ba4..4244d7ae3 100644 --- a/components/tree/util.js +++ b/components/tree/util.js @@ -1,5 +1,5 @@ import { getNodeChildren, convertTreeToEntities } from '../vc-tree/src/util'; -import { getSlots } from '../_util/props-util'; +import { getSlot } from '../_util/props-util'; const Record = { None: 'node', @@ -13,9 +13,9 @@ function traverseNodesKey(rootChildren, callback) { function processNode(node) { const { key } = node; - const children = getSlots(node); + const children = getSlot(node); if (callback(key, node) !== false) { - traverseNodesKey(typeof children === 'function' ? children() : children, callback); + traverseNodesKey(children, callback); } } diff --git a/components/vc-tree/src/Tree.jsx b/components/vc-tree/src/Tree.jsx index 8c5b1e507..e0864b8f6 100644 --- a/components/vc-tree/src/Tree.jsx +++ b/components/vc-tree/src/Tree.jsx @@ -1,7 +1,7 @@ import PropTypes from '../../_util/vue-types'; import classNames from 'classnames'; import warning from 'warning'; -import { hasProp, initDefaultProps, getOptionProps, getSlots } from '../../_util/props-util'; +import { hasProp, initDefaultProps, getOptionProps, getSlot } from '../../_util/props-util'; import { cloneElement } from '../../_util/vnode'; import BaseMixin from '../../_util/BaseMixin'; import { @@ -237,7 +237,7 @@ const Tree = { onNodeDragStart(event, node) { const { _expandedKeys } = this.$data; const { eventKey } = node; - const children = getSlots(node); + const children = getSlot(node); this.dragNode = node; this.setState({ diff --git a/components/vc-tree/src/TreeNode.jsx b/components/vc-tree/src/TreeNode.jsx index 3e88282b8..d668a94c5 100644 --- a/components/vc-tree/src/TreeNode.jsx +++ b/components/vc-tree/src/TreeNode.jsx @@ -54,6 +54,7 @@ const TreeNode = { ), data() { + this.children = null; return { dragNodeHighlight: false, }; @@ -241,7 +242,7 @@ const TreeNode = { }, getNodeChildren() { - const originList = getSlot(this); + const originList = this.children; const targetList = getNodeChildren(originList); if (originList.length !== targetList.length) { @@ -521,6 +522,7 @@ const TreeNode = { }, render() { + this.children = getSlot(this); const { dragOver, dragOverGapTop, diff --git a/examples/App.vue b/examples/App.vue index b514e5106..e624a511b 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -4,7 +4,7 @@