Commit 31042de6bc0683132f57262e452dc3aa15cc8de0
Committed by
GitHub
1 parent
aabafe86
perf(component): 优化table 组件的insertTableDataRecord的方法,增加批量插入的功能。 (#2481)
Co-authored-by: huangwentao <huangwentao@dianchu.com>
Showing
2 changed files
with
8 additions
and
4 deletions
src/components/Table/src/hooks/useDataSource.ts
... | ... | @@ -13,7 +13,7 @@ import { |
13 | 13 | } from 'vue'; |
14 | 14 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
15 | 15 | import { buildUUID } from '/@/utils/uuid'; |
16 | -import { isFunction, isBoolean } from '/@/utils/is'; | |
16 | +import { isFunction, isBoolean, isObject } from '/@/utils/is'; | |
17 | 17 | import { get, cloneDeep, merge } from 'lodash-es'; |
18 | 18 | import { FETCH_SETTING, ROW_KEY, PAGE_SIZE } from '../const'; |
19 | 19 | |
... | ... | @@ -206,10 +206,14 @@ export function useDataSource( |
206 | 206 | }); |
207 | 207 | } |
208 | 208 | |
209 | - function insertTableDataRecord(record: Recordable, index: number): Recordable | undefined { | |
209 | + function insertTableDataRecord( | |
210 | + record: Recordable | Recordable[], | |
211 | + index: number, | |
212 | + ): Recordable | undefined { | |
210 | 213 | // if (!dataSourceRef.value || dataSourceRef.value.length == 0) return; |
211 | 214 | index = index ?? dataSourceRef.value?.length; |
212 | - unref(dataSourceRef).splice(index, 0, record); | |
215 | + const _record = isObject(record) ? [record as Recordable] : (record as Recordable[]); | |
216 | + unref(dataSourceRef).splice(index, 0, ..._record); | |
213 | 217 | return unref(dataSourceRef); |
214 | 218 | } |
215 | 219 | ... | ... |
src/components/Table/src/types/table.ts
... | ... | @@ -97,7 +97,7 @@ export interface TableActionType { |
97 | 97 | setTableData: <T = Recordable>(values: T[]) => void; |
98 | 98 | updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void; |
99 | 99 | deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => void; |
100 | - insertTableDataRecord: (record: Recordable, index?: number) => Recordable | void; | |
100 | + insertTableDataRecord: (record: Recordable | Recordable[], index?: number) => Recordable | void; | |
101 | 101 | findTableDataRecord: (rowKey: string | number) => Recordable | void; |
102 | 102 | getColumns: (opt?: GetColumnsParams) => BasicColumn[]; |
103 | 103 | setColumns: (columns: BasicColumn[] | string[]) => void; | ... | ... |