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