From 83bb0a0a6a4aba255e81294d5355ec0872eb79bc Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Mon, 11 Aug 2025 18:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=8E=92=E5=BA=8FdefSort=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Table/src/hooks/useDataSource.ts | 10 +++++++++- .../src/components/Table/src/types/table.ts | 2 +- .../src/views/system/examples/demo/index.vue | 16 +++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/jeecgboot-vue3/src/components/Table/src/hooks/useDataSource.ts b/jeecgboot-vue3/src/components/Table/src/hooks/useDataSource.ts index 6d1ec9812..e019d279a 100644 --- a/jeecgboot-vue3/src/components/Table/src/hooks/useDataSource.ts +++ b/jeecgboot-vue3/src/components/Table/src/hooks/useDataSource.ts @@ -238,12 +238,20 @@ export function useDataSource( const { sortInfo = {}, filterInfo } = searchState; + // 扩展默认排序多字段数组写法 + let defSortInfo: Recordable | undefined = {}; + if (defSort && Array.isArray(defSort) && defSort.length > 0) { + defSortInfo['defSortString'] = JSON.stringify(defSort); + } else { + defSortInfo = defSort; + } + let params: Recordable = { ...pageParams, // 由于 getFieldsValue 返回的不是逗号分割的数据,所以改用 validate ...(useSearchForm ? await validate() : {}), ...searchInfo, - ...defSort, + ...defSortInfo, ...(opt?.searchInfo ?? {}), ...sortInfo, ...filterInfo, diff --git a/jeecgboot-vue3/src/components/Table/src/types/table.ts b/jeecgboot-vue3/src/components/Table/src/types/table.ts index 9afc19958..8cc12fb51 100644 --- a/jeecgboot-vue3/src/components/Table/src/types/table.ts +++ b/jeecgboot-vue3/src/components/Table/src/types/table.ts @@ -190,7 +190,7 @@ export interface BasicTableProps { // 额外的请求参数 searchInfo?: Recordable; // 默认的排序参数 - defSort?: Recordable; + defSort?: Recordable | Recordable[]; // 使用搜索表单 useSearchForm?: boolean; // 表单配置 diff --git a/jeecgboot-vue3/src/views/system/examples/demo/index.vue b/jeecgboot-vue3/src/views/system/examples/demo/index.vue index bedc7a177..43367f5b2 100644 --- a/jeecgboot-vue3/src/views/system/examples/demo/index.vue +++ b/jeecgboot-vue3/src/views/system/examples/demo/index.vue @@ -123,11 +123,17 @@ style: { textAlign: 'left' }, }, }, - //自定义默认排序 - defSort: { - column: 'createTime,sex', - order: 'desc', - }, + //自定义默认多字段排序 + defSort: [ + { + column: 'name', + order: 'desc', + }, + { + column: 'sex', + order: 'asc', + }, + ], striped: true, useSearchForm: true, showTableSetting: true,