Commit 8d7d0835adf4a7d1b8afc5e8bd911a60833006a4

Authored by vben
1 parent 31ff0559

feat(table): add summaryData prop #163

src/components/Table/src/components/TableAction.vue
... ... @@ -45,7 +45,7 @@
45 45 const { prefixCls } = useDesign('basic-table-action');
46 46 const table = useTableContext();
47 47 const getActions = computed(() => {
48   - return props.actions.map((action) => {
  48 + return (props.actions || []).map((action) => {
49 49 const { popConfirm } = action;
50 50 return {
51 51 type: 'link',
... ...
src/components/Table/src/components/TableFooter.vue
1 1 <template>
2 2 <Table
3   - v-if="summaryFunc"
  3 + v-if="summaryFunc || summaryData"
4 4 :showHeader="false"
5 5 :bordered="false"
6 6 :pagination="false"
... ... @@ -32,6 +32,9 @@
32 32 summaryFunc: {
33 33 type: Function as PropType<Fn>,
34 34 },
  35 + summaryData: {
  36 + type: Array as PropType<Recordable[]>,
  37 + },
35 38 scroll: {
36 39 type: Object as PropType<Recordable>,
37 40 },
... ... @@ -41,7 +44,11 @@
41 44 const table = useTableContext();
42 45  
43 46 const getDataSource = computed((): Recordable[] => {
44   - const { summaryFunc } = props;
  47 + const { summaryFunc, summaryData } = props;
  48 + if (summaryData?.length) {
  49 + summaryData.forEach((item, i) => (item[props.rowKey] = `${i}`));
  50 + return summaryData;
  51 + }
45 52 if (!isFunction(summaryFunc)) {
46 53 return [];
47 54 }
... ...
src/components/Table/src/hooks/useDataSource.ts
... ... @@ -163,11 +163,11 @@ export function useDataSource(
163 163 ...pageParams,
164 164 ...(useSearchForm ? getFieldsValue() : {}),
165 165 ...searchInfo,
166   - ...(opt ? opt.searchInfo : {}),
167   - ...(opt ? opt.sortInfo : {}),
168   - ...(opt ? opt.filterInfo : {}),
  166 + ...(opt?.searchInfo ?? {}),
169 167 ...sortInfo,
170 168 ...filterInfo,
  169 + ...(opt?.sortInfo ?? {}),
  170 + ...(opt?.filterInfo ?? {}),
171 171 };
172 172 if (beforeFetch && isFunction(beforeFetch)) {
173 173 params = beforeFetch(params) || params;
... ...
src/components/Table/src/hooks/useTableFooter.ts
... ... @@ -19,9 +19,9 @@ export function useTableFooter(
19 19 });
20 20  
21 21 const getFooterProps = computed((): Recordable | undefined => {
22   - const { summaryFunc, showSummary } = unref(propsRef);
  22 + const { summaryFunc, showSummary, summaryData } = unref(propsRef);
23 23 return showSummary && !unref(getIsEmptyData)
24   - ? () => h(TableFooter, { summaryFunc, scroll: unref(scrollRef) })
  24 + ? () => h(TableFooter, { summaryFunc, summaryData, scroll: unref(scrollRef) })
25 25 : undefined;
26 26 });
27 27  
... ...
src/components/Table/src/props.ts
... ... @@ -44,6 +44,11 @@ export const basicProps = {
44 44 default: null,
45 45 },
46 46  
  47 + summaryData: {
  48 + type: Array as PropType<Recordable[]>,
  49 + default: null,
  50 + },
  51 +
47 52 canColDrag: propTypes.bool.def(true),
48 53 api: {
49 54 type: Function as PropType<(...arg: any[]) => Promise<any>>,
... ... @@ -73,7 +78,7 @@ export const basicProps = {
73 78 emptyDataIsShowTable: propTypes.bool.def(true),
74 79 // 额外的请求参数
75 80 searchInfo: {
76   - type: Object as PropType<any>,
  81 + type: Object as PropType<Recordable>,
77 82 default: null,
78 83 },
79 84 // 使用搜索表单
... ...
src/components/Table/src/types/table.ts
... ... @@ -143,6 +143,8 @@ export interface BasicTableProps&lt;T = any&gt; {
143 143 autoCreateKey?: boolean;
144 144 // 计算合计行的方法
145 145 summaryFunc?: (...arg: any) => Recordable[];
  146 + // 自定义合计表格内容
  147 + summaryData?: Recordable[];
146 148 // 是否显示合计行
147 149 showSummary?: boolean;
148 150 // 是否可拖拽列
... ...
src/layouts/default/header/MultipleHeader.vue
... ... @@ -70,10 +70,14 @@
70 70 const getPlaceholderDomStyle = computed(
71 71 (): CSSProperties => {
72 72 let height = 0;
73   - if ((unref(getShowFullHeaderRef) || !unref(getSplit)) && unref(getShowHeader)) {
  73 + if (
  74 + (unref(getShowFullHeaderRef) || !unref(getSplit)) &&
  75 + unref(getShowHeader) &&
  76 + !unref(getFullContent)
  77 + ) {
74 78 height += HEADER_HEIGHT;
75 79 }
76   - if (unref(getShowMultipleTab)) {
  80 + if (unref(getShowMultipleTab) && !unref(getFullContent)) {
77 81 height += TABS_HEIGHT;
78 82 }
79 83 headerHeightRef.value = height;
... ...
src/views/demo/table/FooterTable.vue
... ... @@ -13,7 +13,7 @@
13 13 export default defineComponent({
14 14 components: { BasicTable },
15 15 setup() {
16   - function handleSummary(tableData: any[]) {
  16 + function handleSummary(tableData: Recordable[]) {
17 17 const totalNo = tableData.reduce((prev, next) => {
18 18 prev += next.no;
19 19 return prev;
... ...