From de5f9e304791ce131a589683282b42f77d10238c Mon Sep 17 00:00:00 2001 From: zhang Date: Fri, 5 Apr 2024 13:42:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(BasicTable):=20=E6=96=B0=E5=A2=9E=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=90=9C=E7=B4=A2=E8=8E=B7=E5=8F=96=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=20(#3715)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法 --- src/components/Table/src/BasicTable.vue | 2 ++ src/components/Table/src/hooks/useDataSource.ts | 9 ++++++++- src/components/Table/src/hooks/useTable.ts | 3 +++ src/components/Table/src/types/table.ts | 1 + src/views/demo/system/account/index.vue | 7 ++++++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/Table/src/BasicTable.vue b/src/components/Table/src/BasicTable.vue index 174d6d971..943b98d3b 100644 --- a/src/components/Table/src/BasicTable.vue +++ b/src/components/Table/src/BasicTable.vue @@ -144,6 +144,7 @@ getDataSourceRef, getDataSource, getRawDataSource, + getSearchInfo, setTableData, updateTableDataRecord, deleteTableDataRecord, @@ -300,6 +301,7 @@ setLoading, getDataSource, getRawDataSource, + getSearchInfo, setProps, getRowSelection, getPaginationRef: getPagination, diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index aa6a85f3c..f5da7d45c 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -50,6 +50,7 @@ export function useDataSource( }); const dataSourceRef = ref([]); const rawDataSourceRef = ref({}); + const searchInfoRef = ref({}); watchEffect(() => { tableData.value = unref(dataSourceRef); @@ -275,7 +276,7 @@ export function useDataSource( if (beforeFetch && isFunction(beforeFetch)) { params = (await beforeFetch(params)) || params; } - + searchInfoRef.value = params; const res = await api(params); rawDataSourceRef.value = res; @@ -339,6 +340,10 @@ export function useDataSource( return await fetch(opt); } + function getSearchInfo() { + return searchInfoRef.value as T; + } + onMounted(() => { useTimeoutFn(() => { unref(propsRef).immediate && fetch(); @@ -349,6 +354,8 @@ export function useDataSource( getDataSourceRef, getDataSource, getRawDataSource, + searchInfoRef, + getSearchInfo, getRowKey, setTableData, getAutoCreateKey, diff --git a/src/components/Table/src/hooks/useTable.ts b/src/components/Table/src/hooks/useTable.ts index 196eecd94..1e353ab03 100644 --- a/src/components/Table/src/hooks/useTable.ts +++ b/src/components/Table/src/hooks/useTable.ts @@ -89,6 +89,9 @@ export function useTable(tableProps?: Props): [ getRawDataSource: () => { return getTableInstance().getRawDataSource(); }, + getSearchInfo: () => { + return getTableInstance().getSearchInfo(); + }, getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => { const columns = getTableInstance().getColumns({ ignoreIndex }) || []; return toRaw(columns); diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index ed268f178..653b736b0 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -114,6 +114,7 @@ export interface TableActionType { setColumns: (columns: BasicColumn[] | string[]) => void; getDataSource: () => T[]; getRawDataSource: () => T; + getSearchInfo: () => T; setLoading: (loading: boolean) => void; setProps: (props: Partial) => void; redoHeight: () => void; diff --git a/src/views/demo/system/account/index.vue b/src/views/demo/system/account/index.vue index fd406acba..86e0dbc1e 100644 --- a/src/views/demo/system/account/index.vue +++ b/src/views/demo/system/account/index.vue @@ -4,6 +4,7 @@