Browse Source

fix(BasicTree): not inherit slot and not show icon slot. close #1902

invalid w 1 năm trước cách đây
mục cha
commit
a0b2a9e949
2 tập tin đã thay đổi với 16 bổ sung4 xóa
  1. 15 3
      src/components/Tree/src/BasicTree.vue
  2. 1 1
      src/components/Tree/src/TreeIcon.ts

+ 15 - 3
src/components/Tree/src/BasicTree.vue

@@ -393,16 +393,26 @@
           ) : (
             title
           );
+
+          const iconDom = icon ? (
+            <TreeIcon icon={icon} />
+          ) : slots.icon ? (
+            <span class="mr-1">{getSlot(slots, 'icon')}</span>
+          ) : null;
+
           item[titleField] = (
             <span
               class={`${bem('title')} pl-2`}
               onClick={handleClickNode.bind(null, item[keyField], item[childrenField])}
             >
               {slots?.title ? (
-                getSlot(slots, 'title', item)
+                <>
+                  {iconDom}
+                  {getSlot(slots, 'title', item)}
+                </>
               ) : (
                 <>
-                  {icon && <TreeIcon icon={icon} />}
+                  {iconDom}
                   {titleDom}
                   <span class={bem('actions')}>{renderAction(item)}</span>
                 </>
@@ -444,7 +454,9 @@
               tip="加载中..."
             >
               <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
-                <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
+                <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value}>
+                  {extendSlots(slots, ['title'])}
+                </Tree>
               </ScrollContainer>
               <Empty
                 v-show={unref(getNotFound)}

+ 1 - 1
src/components/Tree/src/TreeIcon.ts

@@ -3,7 +3,7 @@ import { h } from 'vue';
 import { isString } from 'lodash-es';
 import Icon from '@/components/Icon/Icon.vue';
 
-export const TreeIcon = ({ icon }: { icon: VNode | string }) => {
+export const TreeIcon = ({ icon }: { icon: VNode | string | undefined }) => {
   if (!icon) return null;
   if (isString(icon)) {
     return h(Icon, { icon, class: 'mr-1' });