|
1 | 1 | import type { TableColumnCtx } from 'element-plus' |
2 | | -import type { FunctionalComponent, ObjectEmitsOptions, VNodeChild } from 'vue' |
| 2 | +import type { |
| 3 | + FunctionalComponent, |
| 4 | + ObjectEmitsOptions, |
| 5 | + VNodeArrayChildren, |
| 6 | + VNodeChild, |
| 7 | +} from 'vue' |
3 | 8 | import type { ComponentProps } from 'vue-component-type-helpers' |
4 | | -import { isString, objectMap } from '@antfu/utils' |
| 9 | +import { isFunction, isString, objectMap } from '@antfu/utils' |
5 | 10 | import { ElTableColumn } from 'element-plus' |
| 11 | +import { isVNode } from 'vue' |
6 | 12 |
|
7 | 13 | /** |
8 | 14 | * `ElTableColumn` 的插槽类型 |
@@ -74,9 +80,15 @@ export type ObjectTableColumnProps<T extends { [K: PropertyKey]: any } = any> = |
74 | 80 |
|
75 | 81 | type FalsyTableColumnProps = false | null | undefined |
76 | 82 |
|
| 83 | +export type FunctionTableColumnProps = () => Exclude< |
| 84 | + VNodeChild, |
| 85 | + VNodeArrayChildren |
| 86 | +> |
| 87 | + |
77 | 88 | export type TableColumnProps<T extends { [K: PropertyKey]: any } = any> = |
78 | 89 | | FalsyTableColumnProps | |
79 | | - ObjectTableColumnProps<T> |
| 90 | + ObjectTableColumnProps<T> | |
| 91 | + FunctionTableColumnProps |
80 | 92 |
|
81 | 93 | export interface TableColumnsRenderProps { |
82 | 94 | /** |
@@ -111,6 +123,13 @@ export const TableColumnsRender: FunctionalComponent< |
111 | 123 | continue |
112 | 124 | } |
113 | 125 |
|
| 126 | + if (isFunction(column)) { |
| 127 | + const vNode = column() |
| 128 | + // 只有在返回 VNode 时才添加到列表中 |
| 129 | + isVNode(vNode) && vNodes.push(vNode) |
| 130 | + continue |
| 131 | + } |
| 132 | + |
114 | 133 | const { children, slots: userSlots = {}, ...columnProps } = column |
115 | 134 | const finalSlots = objectMap(userSlots, (key, value) => [ |
116 | 135 | key, |
|
0 commit comments