|
|
@ -5,6 +5,7 @@ import { convertNodePropsToEventData } from './utils/treeUtil';
|
|
|
|
import { computed, defineComponent, getCurrentInstance, onMounted, onUpdated, ref } from 'vue';
|
|
|
|
import { computed, defineComponent, getCurrentInstance, onMounted, onUpdated, ref } from 'vue';
|
|
|
|
import { treeNodeProps } from './props';
|
|
|
|
import { treeNodeProps } from './props';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
|
|
|
|
import { warning } from '../vc-util/warning';
|
|
|
|
|
|
|
|
|
|
|
|
const ICON_OPEN = 'open';
|
|
|
|
const ICON_OPEN = 'open';
|
|
|
|
const ICON_CLOSE = 'close';
|
|
|
|
const ICON_CLOSE = 'close';
|
|
|
@ -17,7 +18,11 @@ export default defineComponent({
|
|
|
|
props: treeNodeProps,
|
|
|
|
props: treeNodeProps,
|
|
|
|
isTreeNode: 1,
|
|
|
|
isTreeNode: 1,
|
|
|
|
slots: ['title', 'icon', 'switcherIcon', 'checkable'],
|
|
|
|
slots: ['title', 'icon', 'switcherIcon', 'checkable'],
|
|
|
|
setup(props, { attrs, expose, slots }) {
|
|
|
|
setup(props, { attrs, slots }) {
|
|
|
|
|
|
|
|
warning(
|
|
|
|
|
|
|
|
!('slots' in props.data),
|
|
|
|
|
|
|
|
'treeData slots is deprecated, please use `v-slot:icon` or `v-slot:title`, `v-slot:switcherIcon` instead',
|
|
|
|
|
|
|
|
);
|
|
|
|
const dragNodeHighlight = ref(false);
|
|
|
|
const dragNodeHighlight = ref(false);
|
|
|
|
const context = useInjectTreeContext();
|
|
|
|
const context = useInjectTreeContext();
|
|
|
|
const instance = getCurrentInstance();
|
|
|
|
const instance = getCurrentInstance();
|
|
|
@ -198,7 +203,10 @@ export default defineComponent({
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const renderSwitcherIconDom = (isLeaf: boolean) => {
|
|
|
|
const renderSwitcherIconDom = (isLeaf: boolean) => {
|
|
|
|
const { switcherIcon: switcherIconFromProps = slots.switcherIcon } = props;
|
|
|
|
const {
|
|
|
|
|
|
|
|
switcherIcon: switcherIconFromProps = slots.switcherIcon ||
|
|
|
|
|
|
|
|
context.value.slots?.[props.data?.slots?.switcherIcon],
|
|
|
|
|
|
|
|
} = props;
|
|
|
|
const { switcherIcon: switcherIconFromCtx } = context.value;
|
|
|
|
const { switcherIcon: switcherIconFromCtx } = context.value;
|
|
|
|
|
|
|
|
|
|
|
|
const switcherIcon = switcherIconFromProps || switcherIconFromCtx;
|
|
|
|
const switcherIcon = switcherIconFromProps || switcherIconFromCtx;
|
|
|
@ -327,7 +335,13 @@ export default defineComponent({
|
|
|
|
|
|
|
|
|
|
|
|
// Icon + Title
|
|
|
|
// Icon + Title
|
|
|
|
const renderSelector = () => {
|
|
|
|
const renderSelector = () => {
|
|
|
|
const { title = slots.title, selected, icon = slots.icon, loading, data } = props;
|
|
|
|
const {
|
|
|
|
|
|
|
|
title = slots.title || context.value.slots?.[props.data?.slots?.title],
|
|
|
|
|
|
|
|
selected,
|
|
|
|
|
|
|
|
icon = slots.icon,
|
|
|
|
|
|
|
|
loading,
|
|
|
|
|
|
|
|
data,
|
|
|
|
|
|
|
|
} = props;
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
prefixCls,
|
|
|
|
showIcon,
|
|
|
|
showIcon,
|
|
|
@ -345,7 +359,7 @@ export default defineComponent({
|
|
|
|
let $icon;
|
|
|
|
let $icon;
|
|
|
|
|
|
|
|
|
|
|
|
if (showIcon) {
|
|
|
|
if (showIcon) {
|
|
|
|
const currentIcon = icon || treeIcon;
|
|
|
|
const currentIcon = icon || context.value.slots?.[data?.slots?.icon] || treeIcon;
|
|
|
|
|
|
|
|
|
|
|
|
$icon = currentIcon ? (
|
|
|
|
$icon = currentIcon ? (
|
|
|
|
<span class={classNames(`${prefixCls}-iconEle`, `${prefixCls}-icon__customize`)}>
|
|
|
|
<span class={classNames(`${prefixCls}-iconEle`, `${prefixCls}-icon__customize`)}>
|
|
|
@ -377,7 +391,7 @@ export default defineComponent({
|
|
|
|
class={classNames(
|
|
|
|
class={classNames(
|
|
|
|
`${wrapClass}`,
|
|
|
|
`${wrapClass}`,
|
|
|
|
`${wrapClass}-${nodeState.value || 'normal'}`,
|
|
|
|
`${wrapClass}-${nodeState.value || 'normal'}`,
|
|
|
|
!disabled && (selected || dragNodeHighlight) && `${prefixCls}-node-selected`,
|
|
|
|
!disabled && (selected || dragNodeHighlight.value) && `${prefixCls}-node-selected`,
|
|
|
|
!disabled && mergedDraggable && 'draggable',
|
|
|
|
!disabled && mergedDraggable && 'draggable',
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
draggable={(!disabled && mergedDraggable) || undefined}
|
|
|
|
draggable={(!disabled && mergedDraggable) || undefined}
|
|
|
|