feat: update tree

pull/2682/head
tanjinzhou 2020-07-17 16:50:22 +08:00
parent 8ca8fbd453
commit f35ae0efae
6 changed files with 13 additions and 10 deletions

@ -1 +1 @@
Subproject commit 7713f7b97f8ce3493094935d5fc1eaaf4ea501aa Subproject commit fe4a4e29aebe7cc1a5bbacf43c2b34671b00c880

View File

@ -57,7 +57,8 @@ export default {
data() { data() {
const props = getOptionProps(this); const props = getOptionProps(this);
const { defaultExpandAll, defaultExpandParent, expandedKeys, defaultExpandedKeys } = props; const { defaultExpandAll, defaultExpandParent, expandedKeys, defaultExpandedKeys } = props;
const { keyEntities } = convertTreeToEntities(this.$slots.default); const children = getSlot(this);
const { keyEntities } = convertTreeToEntities(children);
const state = {}; const state = {};
// Selected keys // Selected keys
state._selectedKeys = props.selectedKeys || props.defaultSelectedKeys || []; state._selectedKeys = props.selectedKeys || props.defaultSelectedKeys || [];
@ -67,7 +68,7 @@ export default {
if (props.treeData) { if (props.treeData) {
state._expandedKeys = getFullKeyListByTreeData(props.treeData); state._expandedKeys = getFullKeyListByTreeData(props.treeData);
} else { } else {
state._expandedKeys = getFullKeyList(this.$slots.default); state._expandedKeys = getFullKeyList(children);
} }
} else if (defaultExpandParent) { } else if (defaultExpandParent) {
state._expandedKeys = conductExpandParent(expandedKeys || defaultExpandedKeys, keyEntities); state._expandedKeys = conductExpandParent(expandedKeys || defaultExpandedKeys, keyEntities);

View File

@ -1,5 +1,5 @@
import { getNodeChildren, convertTreeToEntities } from '../vc-tree/src/util'; import { getNodeChildren, convertTreeToEntities } from '../vc-tree/src/util';
import { getSlots } from '../_util/props-util'; import { getSlot } from '../_util/props-util';
const Record = { const Record = {
None: 'node', None: 'node',
@ -13,9 +13,9 @@ function traverseNodesKey(rootChildren, callback) {
function processNode(node) { function processNode(node) {
const { key } = node; const { key } = node;
const children = getSlots(node); const children = getSlot(node);
if (callback(key, node) !== false) { if (callback(key, node) !== false) {
traverseNodesKey(typeof children === 'function' ? children() : children, callback); traverseNodesKey(children, callback);
} }
} }

View File

@ -1,7 +1,7 @@
import PropTypes from '../../_util/vue-types'; import PropTypes from '../../_util/vue-types';
import classNames from 'classnames'; import classNames from 'classnames';
import warning from 'warning'; 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 { cloneElement } from '../../_util/vnode';
import BaseMixin from '../../_util/BaseMixin'; import BaseMixin from '../../_util/BaseMixin';
import { import {
@ -237,7 +237,7 @@ const Tree = {
onNodeDragStart(event, node) { onNodeDragStart(event, node) {
const { _expandedKeys } = this.$data; const { _expandedKeys } = this.$data;
const { eventKey } = node; const { eventKey } = node;
const children = getSlots(node); const children = getSlot(node);
this.dragNode = node; this.dragNode = node;
this.setState({ this.setState({

View File

@ -54,6 +54,7 @@ const TreeNode = {
), ),
data() { data() {
this.children = null;
return { return {
dragNodeHighlight: false, dragNodeHighlight: false,
}; };
@ -241,7 +242,7 @@ const TreeNode = {
}, },
getNodeChildren() { getNodeChildren() {
const originList = getSlot(this); const originList = this.children;
const targetList = getNodeChildren(originList); const targetList = getNodeChildren(originList);
if (originList.length !== targetList.length) { if (originList.length !== targetList.length) {
@ -521,6 +522,7 @@ const TreeNode = {
}, },
render() { render() {
this.children = getSlot(this);
const { const {
dragOver, dragOver,
dragOverGapTop, dragOverGapTop,

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/tree/demo/customized-icon'; import demo from '../antdv-demo/docs/tree/demo/directory';
export default { export default {
components: { components: {