diff --git a/components/timeline/icon.tsx b/components/timeline/icon.tsx index 058c946c..dd2c4757 100644 --- a/components/timeline/icon.tsx +++ b/components/timeline/icon.tsx @@ -15,6 +15,7 @@ const iconProps = { index: { type: Number, required: true }, icon: { type: [String, Function] as PropType }, slotRender: { type: Function as PropType }, + data: { type: Array as PropType }, } as const satisfies ComponentObjectPropsOptions; export default defineComponent({ @@ -25,9 +26,9 @@ export default defineComponent({ let customIcon: VNodeChild; // prop 的渲染函数优先级高于插槽 if (props.slotRender) { - customIcon = props.slotRender({ index: props.index }); + customIcon = props.slotRender({ index: props.index, item: props.data[props.index] }); } else if (typeof props.icon === 'function') { - customIcon = props.icon({ index: props.index }); + customIcon = props.icon({ index: props.index, item: props.data[props.index] }); } // 自定义渲染没有内容时,fallback diff --git a/components/timeline/props.ts b/components/timeline/props.ts index 16138743..dbd7a23c 100644 --- a/components/timeline/props.ts +++ b/components/timeline/props.ts @@ -54,6 +54,7 @@ type Color = CSSProperties['color']; */ export interface TimelineNodeSlotCommonParams { index: number; + item: TimelineNode; } /** 时间轴结点的参数 */ diff --git a/components/timeline/timeline.tsx b/components/timeline/timeline.tsx index 56e439dc..c09db941 100644 --- a/components/timeline/timeline.tsx +++ b/components/timeline/timeline.tsx @@ -136,9 +136,9 @@ const renderNode = (nodeProps: { let descContent: VNodeChild; // prop 的渲染函数优先级高于插槽 if (slots.desc) { - descContent = slots.desc({ index }); + descContent = slots.desc({ index, item: props.data[index] }); } else if (typeof desc === 'function') { - descContent = desc({ index }); + descContent = desc({ index, item: props.data[index] }); } else { descContent = desc; } @@ -146,9 +146,9 @@ const renderNode = (nodeProps: { // prop 的渲染函数优先级高于插槽 let titleContent: VNodeChild; if (slots.title) { - titleContent = slots.title({ index }); + titleContent = slots.title({ index, item: props.data[index] }); } else if (typeof title === 'function') { - titleContent = title({ index }); + titleContent = title({ index, item: props.data[index] }); } else { titleContent = title; } @@ -182,6 +182,7 @@ const renderNode = (nodeProps: { key={index} index={index} icon={icon} + data={props.data} style={[props.direction === 'column' && descPosition === 'opposite' && props.titleWidth && { left: props.titleWidth }]} slotRender={slots.icon} /> diff --git a/docs/.vitepress/components/timeline/customDesc.vue b/docs/.vitepress/components/timeline/customDesc.vue index ddfdd1e9..940f2bb8 100644 --- a/docs/.vitepress/components/timeline/customDesc.vue +++ b/docs/.vitepress/components/timeline/customDesc.vue @@ -12,7 +12,7 @@ 自定义辅助描述 -