From f3cf162af1fa5634d4e562fa5239939af6f26093 Mon Sep 17 00:00:00 2001 From: JasonYHZ Date: Wed, 4 Aug 2021 08:59:21 +0800 Subject: [PATCH] feat(table): add getRawDataSource() function (#1029) --- src/components/Table/src/BasicTable.vue | 2 ++ src/components/Table/src/hooks/useDataSource.ts | 7 +++++++ src/components/Table/src/hooks/useTable.ts | 3 +++ src/components/Table/src/types/table.ts | 1 + src/views/demo/table/RefTable.vue | 6 ++++++ src/views/demo/table/UseTable.vue | 8 ++++++++ 6 files changed, 27 insertions(+) diff --git a/src/components/Table/src/BasicTable.vue b/src/components/Table/src/BasicTable.vue index e114611a..39739b0b 100644 --- a/src/components/Table/src/BasicTable.vue +++ b/src/components/Table/src/BasicTable.vue @@ -127,6 +127,7 @@ handleTableChange: onTableChange, getDataSourceRef, getDataSource, + getRawDataSource, setTableData, updateTableDataRecord, findTableDataRecord, @@ -273,6 +274,7 @@ setColumns, setLoading, getDataSource, + getRawDataSource, setProps, getRowSelection, getPaginationRef: getPagination, diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index fe6ab3a8..9b6d5c9d 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -47,6 +47,7 @@ export function useDataSource( filterInfo: {}, }); const dataSourceRef = ref([]); + const rawDataSourceRef = ref({}); watchEffect(() => { tableData.value = unref(dataSourceRef); @@ -235,6 +236,7 @@ export function useDataSource( } const res = await api(params); + rawDataSourceRef.value = res; const isArrayResult = Array.isArray(res); @@ -287,6 +289,10 @@ export function useDataSource( return getDataSourceRef.value as T[]; } + function getRawDataSource() { + return rawDataSourceRef.value as T; + } + async function reload(opt?: FetchParams) { await fetch(opt); } @@ -300,6 +306,7 @@ export function useDataSource( return { getDataSourceRef, getDataSource, + getRawDataSource, getRowKey, setTableData, getAutoCreateKey, diff --git a/src/components/Table/src/hooks/useTable.ts b/src/components/Table/src/hooks/useTable.ts index e20d67fe..8f25b313 100644 --- a/src/components/Table/src/hooks/useTable.ts +++ b/src/components/Table/src/hooks/useTable.ts @@ -82,6 +82,9 @@ export function useTable(tableProps?: Props): [ getDataSource: () => { return getTableInstance().getDataSource(); }, + getRawDataSource: () => { + return getTableInstance().getRawDataSource(); + }, 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 56bf2c8c..1a130a31 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -99,6 +99,7 @@ export interface TableActionType { getColumns: (opt?: GetColumnsParams) => BasicColumn[]; setColumns: (columns: BasicColumn[] | string[]) => void; getDataSource: () => T[]; + getRawDataSource: () => T; setLoading: (loading: boolean) => void; setProps: (props: Partial) => void; redoHeight: () => void; diff --git a/src/views/demo/table/RefTable.vue b/src/views/demo/table/RefTable.vue index f23f3cff..f2a0c6dd 100644 --- a/src/views/demo/table/RefTable.vue +++ b/src/views/demo/table/RefTable.vue @@ -6,6 +6,7 @@ 更改Columns 获取Columns 获取表格数据 + 获取接口原始数据 跳转到第2页
@@ -71,6 +72,10 @@ createMessage.info('请在控制台查看!'); console.log(getTableAction().getDataSource()); } + function getTableRawData() { + createMessage.info('请在控制台查看!'); + console.log(getTableAction().getRawDataSource()); + } function getPagination() { createMessage.info('请在控制台查看!'); @@ -107,6 +112,7 @@ reloadTable, getColumn, getTableData, + getTableRawData, getPagination, setPaginationInfo, getSelectRowList, diff --git a/src/views/demo/table/UseTable.vue b/src/views/demo/table/UseTable.vue index c20c1bec..7a6373b5 100644 --- a/src/views/demo/table/UseTable.vue +++ b/src/views/demo/table/UseTable.vue @@ -6,6 +6,7 @@ 更改Columns 获取Columns 获取表格数据 + 获取接口原始数据 跳转到第2页
@@ -38,6 +39,7 @@ setColumns, getColumns, getDataSource, + getRawDataSource, reload, getPaginationRef, setPagination, @@ -89,6 +91,11 @@ console.log(getDataSource()); } + function getTableRawData() { + createMessage.info('请在控制台查看!'); + console.log(getRawDataSource()); + } + function getPagination() { createMessage.info('请在控制台查看!'); console.log(getPaginationRef()); @@ -122,6 +129,7 @@ reloadTable, getColumn, getTableData, + getTableRawData, getPagination, setPaginationInfo, getSelectRowList, -- GitLab