renderFooter.tsx
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Table } from 'ant-design-vue';
import { cloneDeep } from 'lodash-es';
import { unref, ComputedRef } from 'vue';
import { isFunction } from '/@/utils/is';
import type { BasicColumn, TableRowSelection } from '../types/table';
export default ({
scroll = {},
columnsRef,
summaryFunc,
rowKey = 'key',
dataSourceRef,
rowSelectionRef,
}: {
scroll: { x?: number | true; y?: number };
columnsRef: ComputedRef<BasicColumn[]>;
summaryFunc: any;
rowKey?: string;
dataSourceRef: ComputedRef<any[]>;
rowSelectionRef: ComputedRef<TableRowSelection | null>;
}) => {
if (!summaryFunc) {
return;
}
const dataSource: any[] = isFunction(summaryFunc) ? summaryFunc(unref(dataSourceRef)) : [];
const columns: BasicColumn[] = cloneDeep(unref(columnsRef));
const index = columns.findIndex((item) => item.flag === 'INDEX');
const hasRowSummary = dataSource.some((item) => Reflect.has(item, '_row'));
const hasIndexSummary = dataSource.some((item) => Reflect.has(item, '_index'));
if (index !== -1) {
if (hasIndexSummary) {
columns[index].customRender = ({ record }) => record._index;
columns[index].ellipsis = false;
} else {
Reflect.deleteProperty(columns[index], 'customRender');
}
}
if (unref(rowSelectionRef) && hasRowSummary) {
columns.unshift({
width: 60,
title: 'selection',
key: 'selectionKey',
align: 'center',
customRender: ({ record }) => record._row,
});
}
dataSource.forEach((item, i) => {
item[rowKey] = i;
});
return (
<Table
showHeader={false}
bordered={false}
pagination={false}
dataSource={dataSource}
rowKey={rowKey}
columns={columns}
tableLayout="fixed"
scroll={scroll as any}
/>
);
};