Skip to content

Commit 28d4615

Browse files
committed
feat: 添加filterIconSlotexpandSlot插槽,优化类型
1 parent d452f12 commit 28d4615

File tree

6 files changed

+3062
-3844
lines changed

6 files changed

+3062
-3844
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 3.3.0 (2025-07-30)
4+
5+
### 🎫 Feat
6+
7+
- 添加自定义 `filter` 图标插槽 `filterIconSlot`,可在 `template` 中使用
8+
- 添加展开列的自定义内容插槽 `expandSlot`,可在 `template` 中使用
9+
10+
### 🎫 types
11+
12+
- 优化类型
13+
314
## 3.2.1 (2024-08-31)
415

516
### 🐞 Bug fixes

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"element-plus": "^2.0.0"
6565
},
6666
"dependencies": {
67-
"element-plus": "^2.8.0",
67+
"element-plus": "^2.10.4",
6868
"vue": "^3.4.37"
6969
},
7070
"devDependencies": {
@@ -73,7 +73,7 @@
7373
"@commitlint/types": "^18.4.3",
7474
"@intlify/unplugin-vue-i18n": "^2.0.0",
7575
"@pureadmin/release": "^1.1.0",
76-
"@pureadmin/utils": "^2.0.1",
76+
"@pureadmin/utils": "^2.6.2",
7777
"@rollup/plugin-terser": "^0.4.4",
7878
"@types/node": "^20.10.5",
7979
"@vitejs/plugin-vue": "^4.4.1",
@@ -85,8 +85,8 @@
8585
"prettier": "^3.1.1",
8686
"resize-observer-polyfill": "^1.5.1",
8787
"rollup": "^4.3.0",
88-
"sass": "^1.69.5",
89-
"sass-loader": "^13.3.2",
88+
"sass": "^1.89.2",
89+
"sass-loader": "^16.0.5",
9090
"typescript": "^5.3.3",
9191
"vite": "4.5.1",
9292
"vite-svg-loader": "^5.1.0",

packages/components/table/index.tsx

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export default defineComponent({
173173
slot,
174174
headerRenderer,
175175
headerSlot,
176+
filterIconSlot,
177+
expandSlot,
176178
hide,
177179
children,
178180
prop,
@@ -212,36 +214,58 @@ export default defineComponent({
212214
}
213215
};
214216

215-
let scopedSlots = headerRenderer
216-
? {
217-
header: (scope: TableColumnScope) => {
218-
return (
219-
<Renderer
220-
render={headerRenderer}
221-
params={Object.assign(scope, {
222-
index: scope.$index,
223-
props,
224-
attrs
225-
})}
226-
></Renderer>
227-
);
228-
},
229-
...defaultSlots
230-
}
231-
: slots?.[headerSlot]
232-
? {
233-
header: (scope: TableColumnScope) => {
234-
return slots?.[headerSlot]?.(
235-
Object.assign(scope, {
236-
index: scope.$index,
237-
props,
238-
attrs
239-
})
240-
);
241-
},
242-
...defaultSlots
243-
}
244-
: defaultSlots;
217+
const scopedSlots: { [key: string]: (scope: TableColumnScope) => any } = {
218+
...defaultSlots
219+
};
220+
221+
if (headerRenderer) {
222+
scopedSlots.header = (scope: TableColumnScope) => {
223+
return (
224+
<Renderer
225+
render={headerRenderer}
226+
params={Object.assign(scope, {
227+
index: scope.$index,
228+
props,
229+
attrs
230+
})}
231+
/>
232+
);
233+
};
234+
} else if (slots?.[headerSlot]) {
235+
scopedSlots.header = (scope: TableColumnScope) => {
236+
return slots[headerSlot]?.(
237+
Object.assign(scope, {
238+
index: scope.$index,
239+
props,
240+
attrs
241+
})
242+
);
243+
};
244+
}
245+
246+
if (slots?.[filterIconSlot]) {
247+
scopedSlots["filter-icon"] = (scope: TableColumnScope) => {
248+
return slots[filterIconSlot]?.(
249+
Object.assign(scope, {
250+
index: scope.$index,
251+
props,
252+
attrs
253+
})
254+
);
255+
};
256+
}
257+
258+
if (slots?.[expandSlot]) {
259+
scopedSlots.expand = (scope: TableColumnScope) => {
260+
return slots[expandSlot]?.(
261+
Object.assign(scope, {
262+
index: scope.$index,
263+
props,
264+
attrs
265+
})
266+
);
267+
};
268+
}
245269

246270
if (children?.length > 0) {
247271
scopedSlots.default = () => children.map(renderColumns);

packages/types/table-column.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ export type TableColumn = {
102102
filterMethod?: FilterMethods;
103103
/** 选中的数据过滤项,如果需要自定义表头过滤的渲染方式,可能会需要此属性 */
104104
filteredValue?: Array<any>;
105+
/** 使用 `show-overflow-tooltip` 时自定义 `tooltip` 内容 */
106+
tooltipFormatter?: (data: {
107+
row: any;
108+
column: any;
109+
cellValue: any;
110+
}) => VNode | string;
105111
};
106112

107113
/**
@@ -115,6 +121,10 @@ export interface TableColumns extends TableColumn {
115121
slot?: string;
116122
/** 自定义表头的内容插槽 */
117123
headerSlot?: string;
124+
/** 自定义 `filter` 图标插槽 */
125+
filterIconSlot?: string;
126+
/** 展开列的自定义内容插槽 */
127+
expandSlot?: string;
118128
/** 多级表头,内部实现原理:嵌套 `el-table-column` */
119129
children?: Array<TableColumns>;
120130
/** 自定义单元格渲染器(`jsx`语法) */

packages/types/table-props.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
CellCls,
2020
Sort
2121
} from "element-plus";
22+
import type { VNode } from "vue";
2223
import type { TableOverflowTooltipOptions } from "element-plus/es/components/table/src/util";
2324

2425
/**
@@ -83,14 +84,16 @@ export type TableProps = {
8384
emptyText?: string;
8485
/** 是否默认展开所有行,当 `Table` 包含展开行存在或者为树形表格时有效,默认值为 `false` */
8586
defaultExpandAll?: boolean;
86-
/** 可以通过该属性设置 `Table` 目前的展开行,需要设置 `row-key` 属性才能使用,该属性为展开行的 `keys` 数组 */
87+
/** 可以通过该属性设置 `Table` 目前的展开行,需要设置 `row-key` 属性才能使用,该属性为展开行的 `keys` 数组。 从 [element-plus](https://element-plus.org/zh-CN/component/table.html#table-%E5%B1%9E%E6%80%A7) 的 `2.10.3` 版本开始,支持使用数字类型的键 */
8788
expandRowKeys?: any[];
8889
/** 默认的排序列的 `prop` 和顺序。它的 `prop` 属性指定默认的排序的列,`order` 指定默认排序的顺序,默认值为 `如果 prop 已配置, 同时 order 未配置, 那么 order 默认为升序` */
8990
defaultSort?: Sort;
9091
/** `tooltip effect` 属性,默认值为 `dark` */
9192
tooltipEffect?: Effect;
9293
/** 溢出 tooltip 的选项 参考 https://element-plus.org/zh-CN/component/tooltip.html#attributes 默认值为 `{ enterable: true, placement: 'top', showArrow: true, hideAfter: 200, popperOptions: { strategy: 'fixed' } }` */
9394
tooltipOptions?: TableOverflowTooltipOptions;
95+
/** 挂载到哪个 `DOM` 元素 */
96+
appendFilterPanelTo?: string;
9497
/** 是否在表尾显示合计行,默认值为 `false` */
9598
showSummary?: boolean;
9699
/** 合计行第一列的文本,默认值为 `合计` */
@@ -132,6 +135,18 @@ export type TableProps = {
132135
scrollbarAlwaysOn?: boolean;
133136
/** 确保主轴的最小尺寸,以便不超过内容,默认值为 `false` */
134137
flexible?: boolean;
138+
/** `body` 的滚动条的包裹容器 `tabindex` */
139+
scrollbarTabindex?: string | number;
140+
/** 是否允许拖动最后一列,默认值为 `true` */
141+
allowDragLastColumn?: boolean;
142+
/** 自定义 `show-overflow-tooltip` 时的 `tooltip` 内容 */
143+
tooltipFormatter?: (data: {
144+
row: any;
145+
column: any;
146+
cellValue: any;
147+
}) => VNode | string;
148+
/** 在折叠后是否在 `DOM` 中保留展开行内容,默认值为 `false` */
149+
preserveExpandedContent?: boolean;
135150
};
136151

137152
/**

0 commit comments

Comments
 (0)