Commit f3cf162af1fa5634d4e562fa5239939af6f26093

Authored by JasonYHZ
Committed by GitHub
1 parent 38194307

feat(table): add getRawDataSource() function (#1029)

src/components/Table/src/BasicTable.vue
@@ -127,6 +127,7 @@ @@ -127,6 +127,7 @@
127 handleTableChange: onTableChange, 127 handleTableChange: onTableChange,
128 getDataSourceRef, 128 getDataSourceRef,
129 getDataSource, 129 getDataSource,
  130 + getRawDataSource,
130 setTableData, 131 setTableData,
131 updateTableDataRecord, 132 updateTableDataRecord,
132 findTableDataRecord, 133 findTableDataRecord,
@@ -273,6 +274,7 @@ @@ -273,6 +274,7 @@
273 setColumns, 274 setColumns,
274 setLoading, 275 setLoading,
275 getDataSource, 276 getDataSource,
  277 + getRawDataSource,
276 setProps, 278 setProps,
277 getRowSelection, 279 getRowSelection,
278 getPaginationRef: getPagination, 280 getPaginationRef: getPagination,
src/components/Table/src/hooks/useDataSource.ts
@@ -47,6 +47,7 @@ export function useDataSource( @@ -47,6 +47,7 @@ export function useDataSource(
47 filterInfo: {}, 47 filterInfo: {},
48 }); 48 });
49 const dataSourceRef = ref<Recordable[]>([]); 49 const dataSourceRef = ref<Recordable[]>([]);
  50 + const rawDataSourceRef = ref<Recordable>({});
50 51
51 watchEffect(() => { 52 watchEffect(() => {
52 tableData.value = unref(dataSourceRef); 53 tableData.value = unref(dataSourceRef);
@@ -235,6 +236,7 @@ export function useDataSource( @@ -235,6 +236,7 @@ export function useDataSource(
235 } 236 }
236 237
237 const res = await api(params); 238 const res = await api(params);
  239 + rawDataSourceRef.value = res;
238 240
239 const isArrayResult = Array.isArray(res); 241 const isArrayResult = Array.isArray(res);
240 242
@@ -287,6 +289,10 @@ export function useDataSource( @@ -287,6 +289,10 @@ export function useDataSource(
287 return getDataSourceRef.value as T[]; 289 return getDataSourceRef.value as T[];
288 } 290 }
289 291
  292 + function getRawDataSource<T = Recordable>() {
  293 + return rawDataSourceRef.value as T;
  294 + }
  295 +
290 async function reload(opt?: FetchParams) { 296 async function reload(opt?: FetchParams) {
291 await fetch(opt); 297 await fetch(opt);
292 } 298 }
@@ -300,6 +306,7 @@ export function useDataSource( @@ -300,6 +306,7 @@ export function useDataSource(
300 return { 306 return {
301 getDataSourceRef, 307 getDataSourceRef,
302 getDataSource, 308 getDataSource,
  309 + getRawDataSource,
303 getRowKey, 310 getRowKey,
304 setTableData, 311 setTableData,
305 getAutoCreateKey, 312 getAutoCreateKey,
src/components/Table/src/hooks/useTable.ts
@@ -82,6 +82,9 @@ export function useTable(tableProps?: Props): [ @@ -82,6 +82,9 @@ export function useTable(tableProps?: Props): [
82 getDataSource: () => { 82 getDataSource: () => {
83 return getTableInstance().getDataSource(); 83 return getTableInstance().getDataSource();
84 }, 84 },
  85 + getRawDataSource: () => {
  86 + return getTableInstance().getRawDataSource();
  87 + },
85 getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => { 88 getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => {
86 const columns = getTableInstance().getColumns({ ignoreIndex }) || []; 89 const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
87 return toRaw(columns); 90 return toRaw(columns);
src/components/Table/src/types/table.ts
@@ -99,6 +99,7 @@ export interface TableActionType { @@ -99,6 +99,7 @@ export interface TableActionType {
99 getColumns: (opt?: GetColumnsParams) => BasicColumn[]; 99 getColumns: (opt?: GetColumnsParams) => BasicColumn[];
100 setColumns: (columns: BasicColumn[] | string[]) => void; 100 setColumns: (columns: BasicColumn[] | string[]) => void;
101 getDataSource: <T = Recordable>() => T[]; 101 getDataSource: <T = Recordable>() => T[];
  102 + getRawDataSource: <T = Recordable>() => T;
102 setLoading: (loading: boolean) => void; 103 setLoading: (loading: boolean) => void;
103 setProps: (props: Partial<BasicTableProps>) => void; 104 setProps: (props: Partial<BasicTableProps>) => void;
104 redoHeight: () => void; 105 redoHeight: () => void;
src/views/demo/table/RefTable.vue
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 <a-button class="mr-2" @click="changeColumns"> 更改Columns </a-button> 6 <a-button class="mr-2" @click="changeColumns"> 更改Columns </a-button>
7 <a-button class="mr-2" @click="getColumn"> 获取Columns </a-button> 7 <a-button class="mr-2" @click="getColumn"> 获取Columns </a-button>
8 <a-button class="mr-2" @click="getTableData"> 获取表格数据 </a-button> 8 <a-button class="mr-2" @click="getTableData"> 获取表格数据 </a-button>
  9 + <a-button class="mr-2" @click="getTableRawData"> 获取接口原始数据 </a-button>
9 <a-button class="mr-2" @click="setPaginationInfo"> 跳转到第2页 </a-button> 10 <a-button class="mr-2" @click="setPaginationInfo"> 跳转到第2页 </a-button>
10 </div> 11 </div>
11 <div class="mb-4"> 12 <div class="mb-4">
@@ -71,6 +72,10 @@ @@ -71,6 +72,10 @@
71 createMessage.info('请在控制台查看!'); 72 createMessage.info('请在控制台查看!');
72 console.log(getTableAction().getDataSource()); 73 console.log(getTableAction().getDataSource());
73 } 74 }
  75 + function getTableRawData() {
  76 + createMessage.info('请在控制台查看!');
  77 + console.log(getTableAction().getRawDataSource());
  78 + }
74 79
75 function getPagination() { 80 function getPagination() {
76 createMessage.info('请在控制台查看!'); 81 createMessage.info('请在控制台查看!');
@@ -107,6 +112,7 @@ @@ -107,6 +112,7 @@
107 reloadTable, 112 reloadTable,
108 getColumn, 113 getColumn,
109 getTableData, 114 getTableData,
  115 + getTableRawData,
110 getPagination, 116 getPagination,
111 setPaginationInfo, 117 setPaginationInfo,
112 getSelectRowList, 118 getSelectRowList,
src/views/demo/table/UseTable.vue
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 <a-button class="mr-2" @click="changeColumns"> 更改Columns </a-button> 6 <a-button class="mr-2" @click="changeColumns"> 更改Columns </a-button>
7 <a-button class="mr-2" @click="getColumn"> 获取Columns </a-button> 7 <a-button class="mr-2" @click="getColumn"> 获取Columns </a-button>
8 <a-button class="mr-2" @click="getTableData"> 获取表格数据 </a-button> 8 <a-button class="mr-2" @click="getTableData"> 获取表格数据 </a-button>
  9 + <a-button class="mr-2" @click="getTableRawData"> 获取接口原始数据 </a-button>
9 <a-button class="mr-2" @click="setPaginationInfo"> 跳转到第2页 </a-button> 10 <a-button class="mr-2" @click="setPaginationInfo"> 跳转到第2页 </a-button>
10 </div> 11 </div>
11 <div class="mb-4"> 12 <div class="mb-4">
@@ -38,6 +39,7 @@ @@ -38,6 +39,7 @@
38 setColumns, 39 setColumns,
39 getColumns, 40 getColumns,
40 getDataSource, 41 getDataSource,
  42 + getRawDataSource,
41 reload, 43 reload,
42 getPaginationRef, 44 getPaginationRef,
43 setPagination, 45 setPagination,
@@ -89,6 +91,11 @@ @@ -89,6 +91,11 @@
89 console.log(getDataSource()); 91 console.log(getDataSource());
90 } 92 }
91 93
  94 + function getTableRawData() {
  95 + createMessage.info('请在控制台查看!');
  96 + console.log(getRawDataSource());
  97 + }
  98 +
92 function getPagination() { 99 function getPagination() {
93 createMessage.info('请在控制台查看!'); 100 createMessage.info('请在控制台查看!');
94 console.log(getPaginationRef()); 101 console.log(getPaginationRef());
@@ -122,6 +129,7 @@ @@ -122,6 +129,7 @@
122 reloadTable, 129 reloadTable,
123 getColumn, 130 getColumn,
124 getTableData, 131 getTableData,
  132 + getTableRawData,
125 getPagination, 133 getPagination,
126 setPaginationInfo, 134 setPaginationInfo,
127 getSelectRowList, 135 getSelectRowList,