feat: update tree
parent
0b03957ebe
commit
3da747eadc
|
@ -1,6 +1,6 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { filterEmpty } from '../_util/props-util';
|
import { filterEmpty, getComponentFromProp } from '../_util/props-util';
|
||||||
import defaultRenderEmpty from './renderEmpty';
|
import defaultRenderEmpty from './renderEmpty';
|
||||||
|
|
||||||
function getWatch(keys = []) {
|
function getWatch(keys = []) {
|
||||||
|
@ -46,7 +46,7 @@ const ConfigProvider = {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderEmptyComponent() {
|
renderEmptyComponent() {
|
||||||
const customRender = (this.$scopedSlots && this.$scopedSlots['renderEmpty']) || this.$slots['renderEmpty'];
|
const customRender = getComponentFromProp(this,'renderEmpty');
|
||||||
return this.$props.renderEmpty || customRender || defaultRenderEmpty;
|
return this.$props.renderEmpty || customRender || defaultRenderEmpty;
|
||||||
},
|
},
|
||||||
getPrefixCls(suffixCls, customizePrefixCls) {
|
getPrefixCls(suffixCls, customizePrefixCls) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { calcRangeKeys, getFullKeyList } from './util';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { initDefaultProps, getOptionProps } from '../_util/props-util';
|
import { initDefaultProps, getOptionProps } from '../_util/props-util';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
// export type ExpandAction = false | 'click' | 'doubleClick';
|
// export type ExpandAction = false | 'click' | 'doubleClick';
|
||||||
|
|
||||||
|
@ -37,7 +38,6 @@ export default {
|
||||||
props: initDefaultProps(
|
props: initDefaultProps(
|
||||||
{ ...TreeProps(), expandAction: PropTypes.oneOf([false, 'click', 'doubleclick']) },
|
{ ...TreeProps(), expandAction: PropTypes.oneOf([false, 'click', 'doubleclick']) },
|
||||||
{
|
{
|
||||||
prefixCls: 'ant-tree',
|
|
||||||
showIcon: true,
|
showIcon: true,
|
||||||
expandAction: 'click',
|
expandAction: 'click',
|
||||||
},
|
},
|
||||||
|
@ -49,7 +49,9 @@ export default {
|
||||||
// // Shift click usage
|
// // Shift click usage
|
||||||
// lastSelectedKey?: string;
|
// lastSelectedKey?: string;
|
||||||
// cachedSelectedKeys?: string[];
|
// cachedSelectedKeys?: string[];
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const { defaultExpandAll, defaultExpandParent, expandedKeys, defaultExpandedKeys } = props;
|
const { defaultExpandAll, defaultExpandParent, expandedKeys, defaultExpandedKeys } = props;
|
||||||
|
@ -181,7 +183,9 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls, ...props } = getOptionProps(this);
|
const { prefixCls: customizePrefixCls, ...props } = getOptionProps(this);
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('tree', customizePrefixCls);
|
||||||
const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data;
|
const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data;
|
||||||
const treeProps = {
|
const treeProps = {
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -2,7 +2,9 @@ import warning from 'warning';
|
||||||
import { Tree as VcTree, TreeNode } from '../vc-tree';
|
import { Tree as VcTree, TreeNode } from '../vc-tree';
|
||||||
import animation from '../_util/openAnimation';
|
import animation from '../_util/openAnimation';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { initDefaultProps, getOptionProps, filterEmpty } from '../_util/props-util';
|
import { initDefaultProps, getOptionProps, filterEmpty, getComponentFromProp, getClass } from '../_util/props-util';
|
||||||
|
import { cloneElement } from '../_util/vnode';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
function TreeProps() {
|
function TreeProps() {
|
||||||
|
@ -73,6 +75,7 @@ function TreeProps() {
|
||||||
// onDrop: (options: AntTreeNodeMouseEvent) => void,
|
// onDrop: (options: AntTreeNodeMouseEvent) => void,
|
||||||
showIcon: PropTypes.bool,
|
showIcon: PropTypes.bool,
|
||||||
icon: PropTypes.func,
|
icon: PropTypes.func,
|
||||||
|
switcherIcon: PropTypes.any,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
filterTreeNode: PropTypes.func,
|
filterTreeNode: PropTypes.func,
|
||||||
openAnimation: PropTypes.any,
|
openAnimation: PropTypes.any,
|
||||||
|
@ -90,7 +93,6 @@ export default {
|
||||||
event: 'check',
|
event: 'check',
|
||||||
},
|
},
|
||||||
props: initDefaultProps(TreeProps(), {
|
props: initDefaultProps(TreeProps(), {
|
||||||
prefixCls: 'ant-tree',
|
|
||||||
checkable: false,
|
checkable: false,
|
||||||
showIcon: false,
|
showIcon: false,
|
||||||
openAnimation: {
|
openAnimation: {
|
||||||
|
@ -98,6 +100,9 @@ export default {
|
||||||
props: { appear: null },
|
props: { appear: null },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
created() {
|
created() {
|
||||||
warning(
|
warning(
|
||||||
!('treeNodes' in getOptionProps(this)),
|
!('treeNodes' in getOptionProps(this)),
|
||||||
|
@ -106,8 +111,8 @@ export default {
|
||||||
},
|
},
|
||||||
TreeNode,
|
TreeNode,
|
||||||
methods: {
|
methods: {
|
||||||
renderSwitcherIcon({ isLeaf, expanded, loading }) {
|
renderSwitcherIcon(prefixCls, switcherIcon, { isLeaf, expanded, loading }) {
|
||||||
const { prefixCls, showLine } = this.$props;
|
const { showLine } = this.$props;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Icon type="loading" class={`${prefixCls}-switcher-loading-icon`} />;
|
return <Icon type="loading" class={`${prefixCls}-switcher-loading-icon`} />;
|
||||||
}
|
}
|
||||||
|
@ -123,10 +128,20 @@ export default {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
const switcherCls = `${prefixCls}-switcher-icon`;
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
return null;
|
return null;
|
||||||
|
}else if (switcherIcon) {
|
||||||
|
const switcherOriginCls = getClass(switcherIcon[0]);
|
||||||
|
return cloneElement(switcherIcon, {
|
||||||
|
class: {
|
||||||
|
...switcherOriginCls,
|
||||||
|
[switcherCls]: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return <Icon type="caret-down" class={`${prefixCls}-switcher-icon`} theme="filled" />;
|
||||||
}
|
}
|
||||||
return <Icon type="caret-down" class={`${prefixCls}-switcher-icon`} theme="filled" />;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateTreeData(treeData) {
|
updateTreeData(treeData) {
|
||||||
|
@ -167,7 +182,10 @@ export default {
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const { prefixCls, showIcon, treeNodes } = props;
|
const { prefixCls: customizePrefixCls, showIcon, treeNodes } = props;
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('tree', customizePrefixCls);
|
||||||
|
const switcherIcon = getComponentFromProp(this, 'switcherIcon');
|
||||||
const checkable = props.checkable;
|
const checkable = props.checkable;
|
||||||
let treeData = props.treeData || treeNodes;
|
let treeData = props.treeData || treeNodes;
|
||||||
if (treeData) {
|
if (treeData) {
|
||||||
|
@ -176,10 +194,11 @@ export default {
|
||||||
const vcTreeProps = {
|
const vcTreeProps = {
|
||||||
props: {
|
props: {
|
||||||
...props,
|
...props,
|
||||||
|
prefixCls,
|
||||||
checkable: checkable ? <span class={`${prefixCls}-checkbox-inner`} /> : checkable,
|
checkable: checkable ? <span class={`${prefixCls}-checkbox-inner`} /> : checkable,
|
||||||
children: filterEmpty(this.$slots.default || []),
|
children: filterEmpty(this.$slots.default || []),
|
||||||
__propsSymbol__: Symbol(),
|
__propsSymbol__: Symbol(),
|
||||||
switcherIcon: this.renderSwitcherIcon,
|
switcherIcon: (nodeProps) => this.renderSwitcherIcon(prefixCls, switcherIcon, nodeProps),
|
||||||
},
|
},
|
||||||
on: this.$listeners,
|
on: this.$listeners,
|
||||||
ref: 'tree',
|
ref: 'tree',
|
||||||
|
|
|
@ -16,6 +16,7 @@ You can customize icons for different nodes.
|
||||||
defaultExpandAll
|
defaultExpandAll
|
||||||
:defaultSelectedKeys="['0-0-0']"
|
:defaultSelectedKeys="['0-0-0']"
|
||||||
>
|
>
|
||||||
|
<a-icon type="down" slot="switcherIcon" />
|
||||||
<a-icon slot="smile" type="smile-o" />
|
<a-icon slot="smile" type="smile-o" />
|
||||||
<a-icon slot="meh" type="smile-o" />
|
<a-icon slot="meh" type="smile-o" />
|
||||||
<template slot="custom" slot-scope="{selected}">
|
<template slot="custom" slot-scope="{selected}">
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
| multiple | Allows selecting multiple treeNodes | boolean | false |
|
| multiple | Allows selecting multiple treeNodes | boolean | false |
|
||||||
| selectedKeys(.sync) | (Controlled) Specifies the keys of the selected treeNodes | string\[] \| number\[] | - |
|
| selectedKeys(.sync) | (Controlled) Specifies the keys of the selected treeNodes | string\[] \| number\[] | - |
|
||||||
| showIcon | Shows the icon before a TreeNode's title. There is no default style; you must set a custom style for it if set to `true` | boolean | false |
|
| showIcon | Shows the icon before a TreeNode's title. There is no default style; you must set a custom style for it if set to `true` | boolean | false |
|
||||||
|
| switcherIcon | customize collapse/expand icon of tree node | slot(vnode) | - |
|
||||||
| showLine | Shows a connecting line | boolean | false |
|
| showLine | Shows a connecting line | boolean | false |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
@ -66,3 +67,9 @@ One of the Tree `treeNode` prop for describing the tree's node, TreeNode has the
|
||||||
| Property | Description | Type | Default |
|
| Property | Description | Type | Default |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| expandAction | Directory open logic, optional `false` `'click'` `'doubleclick'` | string | click |
|
| expandAction | Directory open logic, optional `false` `'click'` `'doubleclick'` | string | click |
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
### How to hide file icon when use showLine?
|
||||||
|
|
||||||
|
File icon realize by using switcherIcon. You can overwrite the style to hide it
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
| multiple | 支持点选多个节点(节点本身) | boolean | false |
|
| multiple | 支持点选多个节点(节点本身) | boolean | false |
|
||||||
| selectedKeys(.sync) | (受控)设置选中的树节点 | string\[] \| number\[] | - |
|
| selectedKeys(.sync) | (受控)设置选中的树节点 | string\[] \| number\[] | - |
|
||||||
| showIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true,需要自行定义图标相关样式 | boolean | false |
|
| showIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true,需要自行定义图标相关样式 | boolean | false |
|
||||||
|
| switcherIcon | 自定义树节点的展开/折叠图标 | slot(vnode) | - |
|
||||||
| showLine | 是否展示连接线 | boolean | false |
|
| showLine | 是否展示连接线 | boolean | false |
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,5 +69,11 @@
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| expandAction | 目录展开逻辑,可选 `false` `'click'` `'doubleclick'` | string | click |
|
| expandAction | 目录展开逻辑,可选 `false` `'click'` `'doubleclick'` | string | click |
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
### 在 showLine 时,如何隐藏子节点图标?
|
||||||
|
|
||||||
|
文件图标通过 switcherIcon 来实现,如果不需要你可以覆盖对应的样式
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue