From 34781d42e8da39e7656d02fb02d6220be6d0a3fa Mon Sep 17 00:00:00 2001 From: tangyh <306479353@qq.com> Date: Thu, 14 Oct 2021 22:15:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(Table):=20=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=BB=98=E8=AE=A4=E7=9A=84=E6=8E=92=E5=BA=8F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/src/hooks/useDataSource.ts | 3 ++- src/components/Table/src/props.ts | 5 +++++ src/components/Table/src/types/table.ts | 2 ++ src/settings/componentSetting.ts | 16 ++++++++++------ src/views/demo/table/UseTable.vue | 4 ++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 0ea0d5ee..81137266 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -241,7 +241,7 @@ export function useDataSource( } async function fetch(opt?: FetchParams) { - const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = + const { api, searchInfo, defSort, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = unref(propsRef); if (!api || !isFunction(api)) return; try { @@ -269,6 +269,7 @@ export function useDataSource( ...(useSearchForm ? getFieldsValue() : {}), ...searchInfo, ...(opt?.searchInfo ?? {}), + ...defSort, ...sortInfo, ...filterInfo, ...(opt?.sortInfo ?? {}), diff --git a/src/components/Table/src/props.ts b/src/components/Table/src/props.ts index b4df61ac..3e5a9c72 100644 --- a/src/components/Table/src/props.ts +++ b/src/components/Table/src/props.ts @@ -69,6 +69,11 @@ export const basicProps = { type: Object as PropType, default: null, }, + // 默认的排序参数 + defSort: { + type: Object as PropType, + default: null, + }, // 使用搜索表单 useSearchForm: propTypes.bool, // 表单配置 diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index 88f530ce..10f2c8ce 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -176,6 +176,8 @@ export interface BasicTableProps { emptyDataIsShowTable?: boolean; // 额外的请求参数 searchInfo?: Recordable; + // 默认的排序参数 + defSort?: Recordable; // 使用搜索表单 useSearchForm?: boolean; // 表单配置 diff --git a/src/settings/componentSetting.ts b/src/settings/componentSetting.ts index 8b3ba8e7..025bcda2 100644 --- a/src/settings/componentSetting.ts +++ b/src/settings/componentSetting.ts @@ -24,12 +24,16 @@ export default { // Custom general sort function defaultSortFn: (sortInfo: SorterResult) => { const { field, order } = sortInfo; - return { - // The sort field passed to the backend you - field, - // Sorting method passed to the background asc/desc - order, - }; + if (field && order) { + return { + // The sort field passed to the backend you + field, + // Sorting method passed to the background asc/desc + order, + }; + } else { + return {}; + } }, // Custom general filter function defaultFilterFn: (data: Partial>) => { diff --git a/src/views/demo/table/UseTable.vue b/src/views/demo/table/UseTable.vue index 7a6373b5..3c549979 100644 --- a/src/views/demo/table/UseTable.vue +++ b/src/views/demo/table/UseTable.vue @@ -54,6 +54,10 @@ titleHelpMessage: '使用useTable调用表格内方法', api: demoListApi, columns: getBasicColumns(), + defSort: { + field: 'name', + order: 'ascend', + }, rowKey: 'id', showTableSetting: true, onChange,