@@ -93,6 +93,7 @@ function TreeProps() {
93
93
* 替换treeNode中 title,key,children字段为treeData中对应的字段
94
94
*/
95
95
replaceFields : PropTypes . object ,
96
+ blockNode : PropTypes . bool ,
96
97
} ;
97
98
}
98
99
@@ -111,6 +112,7 @@ export default {
111
112
on : animation ,
112
113
props : { appear : null } ,
113
114
} ,
115
+ blockNode : false ,
114
116
} ) ,
115
117
inject : {
116
118
configProvider : { default : ( ) => ConfigConsumerProps } ,
@@ -128,32 +130,27 @@ export default {
128
130
if ( loading ) {
129
131
return < Icon type = "loading" class = { `${ prefixCls } -switcher-loading-icon` } /> ;
130
132
}
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 ;
156
136
}
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
+ ) ;
157
154
} ,
158
155
updateTreeData ( treeData ) {
159
156
const { $slots, $scopedSlots } = this ;
@@ -166,12 +163,17 @@ export default {
166
163
const treeNodeProps = {
167
164
...restProps ,
168
165
icon :
169
- $slots [ slots . icon ] ||
170
166
( $scopedSlots [ scopedSlots . icon ] && $scopedSlots [ scopedSlots . icon ] ( item ) ) ||
167
+ $slots [ slots . icon ] ||
171
168
restProps . icon ,
169
+ switcherIcon :
170
+ ( $scopedSlots [ scopedSlots . switcherIcon ] &&
171
+ $scopedSlots [ scopedSlots . switcherIcon ] ( item ) ) ||
172
+ $slots [ slots . switcherIcon ] ||
173
+ restProps . switcherIcon ,
172
174
title :
173
- $slots [ slots . title ] ||
174
175
( $scopedSlots [ scopedSlots . title ] && $scopedSlots [ scopedSlots . title ] ( item ) ) ||
176
+ $slots [ slots . title ] ||
175
177
restProps [ replaceFields . title ] ,
176
178
dataRef : item ,
177
179
on,
@@ -188,7 +190,8 @@ export default {
188
190
} ,
189
191
render ( ) {
190
192
const props = getOptionProps ( this ) ;
191
- const { prefixCls : customizePrefixCls , showIcon, treeNodes } = props ;
193
+ const { $slots, $scopedSlots } = this ;
194
+ const { prefixCls : customizePrefixCls , showIcon, treeNodes, blockNode } = props ;
192
195
const getPrefixCls = this . configProvider . getPrefixCls ;
193
196
const prefixCls = getPrefixCls ( 'tree' , customizePrefixCls ) ;
194
197
const switcherIcon = getComponentFromProp ( this , 'switcherIcon' ) ;
@@ -202,13 +205,16 @@ export default {
202
205
...props ,
203
206
prefixCls,
204
207
checkable : checkable ? < span class = { `${ prefixCls } -checkbox-inner` } /> : checkable ,
205
- children : filterEmpty ( this . $slots . default || [ ] ) ,
208
+ children : filterEmpty ( $scopedSlots . default ? $scopedSlots . default ( ) : $slots . default ) ,
206
209
__propsSymbol__ : Symbol ( ) ,
207
210
switcherIcon : nodeProps => this . renderSwitcherIcon ( prefixCls , switcherIcon , nodeProps ) ,
208
211
} ,
209
212
on : getListeners ( this ) ,
210
213
ref : 'tree' ,
211
- class : ! showIcon && `${ prefixCls } -icon-hide` ,
214
+ class : {
215
+ [ `${ prefixCls } -icon-hide` ] : ! showIcon ,
216
+ [ `${ prefixCls } -block-node` ] : blockNode ,
217
+ } ,
212
218
} ;
213
219
if ( treeData ) {
214
220
vcTreeProps . props . treeData = treeData ;
0 commit comments