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

This commit is contained in:
invalid w 2023-10-21 11:48:38 +08:00
parent 7b87d6d29e
commit a0b2a9e949
2 changed files with 16 additions and 4 deletions

View File

@ -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)}

View File

@ -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' });