@@ -93,6 +93,7 @@ function TreeProps() {
9393 * 替换treeNode中 title,key,children字段为treeData中对应的字段
9494 */
9595 replaceFields : PropTypes . object ,
96+ blockNode : PropTypes . bool ,
9697 } ;
9798}
9899
@@ -111,6 +112,7 @@ export default {
111112 on : animation ,
112113 props : { appear : null } ,
113114 } ,
115+ blockNode : false ,
114116 } ) ,
115117 inject : {
116118 configProvider : { default : ( ) => ConfigConsumerProps } ,
@@ -128,32 +130,27 @@ export default {
128130 if ( loading ) {
129131 return < Icon type = "loading" class = { `${ prefixCls } -switcher-loading-icon` } /> ;
130132 }
131- if ( showLine ) {
132- if ( isLeaf ) {
133- return < Icon type = "file" class = { `${ prefixCls } -switcher-line-icon` } /> ;
134- }
135- return (
136- < Icon
137- type = { expanded ? 'minus-square' : 'plus-square' }
138- class = { `${ prefixCls } -switcher-line-icon` }
139- theme = "outlined"
140- />
141- ) ;
142- } else {
143- const switcherCls = `${ prefixCls } -switcher-icon` ;
144- if ( isLeaf ) {
145- return null ;
146- } else if ( switcherIcon ) {
147- const switcherOriginCls = getClass ( switcherIcon [ 0 ] ) ;
148- return cloneElement ( switcherIcon , {
149- class : {
150- [ switcherCls ] : true ,
151- } ,
152- } ) ;
153- } else {
154- return < Icon type = "caret-down" class = { `${ prefixCls } -switcher-icon` } theme = "filled" /> ;
155- }
133+
134+ if ( isLeaf ) {
135+ return showLine ? < Icon type = "file" class = { `${ prefixCls } -switcher-line-icon` } /> : null ;
156136 }
137+ const switcherCls = `${ prefixCls } -switcher-icon` ;
138+ if ( switcherIcon ) {
139+ return cloneElement ( switcherIcon , {
140+ class : {
141+ [ switcherCls ] : true ,
142+ } ,
143+ } ) ;
144+ }
145+ return showLine ? (
146+ < Icon
147+ type = { expanded ? 'minus-square' : 'plus-square' }
148+ class = { `${ prefixCls } -switcher-line-icon` }
149+ theme = "outlined"
150+ />
151+ ) : (
152+ < Icon type = "caret-down" class = { switcherCls } theme = "filled" />
153+ ) ;
157154 } ,
158155 updateTreeData ( treeData ) {
159156 const { $slots, $scopedSlots } = this ;
@@ -166,12 +163,17 @@ export default {
166163 const treeNodeProps = {
167164 ...restProps ,
168165 icon :
169- $slots [ slots . icon ] ||
170166 ( $scopedSlots [ scopedSlots . icon ] && $scopedSlots [ scopedSlots . icon ] ( item ) ) ||
167+ $slots [ slots . icon ] ||
171168 restProps . icon ,
169+ switcherIcon :
170+ ( $scopedSlots [ scopedSlots . switcherIcon ] &&
171+ $scopedSlots [ scopedSlots . switcherIcon ] ( item ) ) ||
172+ $slots [ slots . switcherIcon ] ||
173+ restProps . switcherIcon ,
172174 title :
173- $slots [ slots . title ] ||
174175 ( $scopedSlots [ scopedSlots . title ] && $scopedSlots [ scopedSlots . title ] ( item ) ) ||
176+ $slots [ slots . title ] ||
175177 restProps [ replaceFields . title ] ,
176178 dataRef : item ,
177179 on,
@@ -188,7 +190,8 @@ export default {
188190 } ,
189191 render ( ) {
190192 const props = getOptionProps ( this ) ;
191- const { prefixCls : customizePrefixCls , showIcon, treeNodes } = props ;
193+ const { $slots, $scopedSlots } = this ;
194+ const { prefixCls : customizePrefixCls , showIcon, treeNodes, blockNode } = props ;
192195 const getPrefixCls = this . configProvider . getPrefixCls ;
193196 const prefixCls = getPrefixCls ( 'tree' , customizePrefixCls ) ;
194197 const switcherIcon = getComponentFromProp ( this , 'switcherIcon' ) ;
@@ -202,13 +205,16 @@ export default {
202205 ...props ,
203206 prefixCls,
204207 checkable : checkable ? < span class = { `${ prefixCls } -checkbox-inner` } /> : checkable ,
205- children : filterEmpty ( this . $slots . default || [ ] ) ,
208+ children : filterEmpty ( $scopedSlots . default ? $scopedSlots . default ( ) : $slots . default ) ,
206209 __propsSymbol__ : Symbol ( ) ,
207210 switcherIcon : nodeProps => this . renderSwitcherIcon ( prefixCls , switcherIcon , nodeProps ) ,
208211 } ,
209212 on : getListeners ( this ) ,
210213 ref : 'tree' ,
211- class : ! showIcon && `${ prefixCls } -icon-hide` ,
214+ class : {
215+ [ `${ prefixCls } -icon-hide` ] : ! showIcon ,
216+ [ `${ prefixCls } -block-node` ] : blockNode ,
217+ } ,
212218 } ;
213219 if ( treeData ) {
214220 vcTreeProps . props . treeData = treeData ;
0 commit comments