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,7 +13,7 @@ import { | ||
13 | } from 'vue'; | 13 | } from 'vue'; |
14 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; | 14 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
15 | import { buildUUID } from '/@/utils/uuid'; | 15 | import { buildUUID } from '/@/utils/uuid'; |
16 | -import { isFunction, isBoolean } from '/@/utils/is'; | 16 | +import { isFunction, isBoolean, isObject } from '/@/utils/is'; |
17 | import { get, cloneDeep, merge } from 'lodash-es'; | 17 | import { get, cloneDeep, merge } from 'lodash-es'; |
18 | import { FETCH_SETTING, ROW_KEY, PAGE_SIZE } from '../const'; | 18 | import { FETCH_SETTING, ROW_KEY, PAGE_SIZE } from '../const'; |
19 | 19 | ||
@@ -206,10 +206,14 @@ export function useDataSource( | @@ -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 | // if (!dataSourceRef.value || dataSourceRef.value.length == 0) return; | 213 | // if (!dataSourceRef.value || dataSourceRef.value.length == 0) return; |
211 | index = index ?? dataSourceRef.value?.length; | 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 | return unref(dataSourceRef); | 217 | return unref(dataSourceRef); |
214 | } | 218 | } |
215 | 219 |
src/components/Table/src/types/table.ts
@@ -97,7 +97,7 @@ export interface TableActionType { | @@ -97,7 +97,7 @@ export interface TableActionType { | ||
97 | setTableData: <T = Recordable>(values: T[]) => void; | 97 | setTableData: <T = Recordable>(values: T[]) => void; |
98 | updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void; | 98 | updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void; |
99 | deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => void; | 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 | findTableDataRecord: (rowKey: string | number) => Recordable | void; | 101 | findTableDataRecord: (rowKey: string | number) => Recordable | void; |
102 | getColumns: (opt?: GetColumnsParams) => BasicColumn[]; | 102 | getColumns: (opt?: GetColumnsParams) => BasicColumn[]; |
103 | setColumns: (columns: BasicColumn[] | string[]) => void; | 103 | setColumns: (columns: BasicColumn[] | string[]) => void; |