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