perf(component): 优化table 组件的insertTableDataRecord的方法,增加批量插入的功能。 (#2481)

Co-authored-by: huangwentao <huangwentao@dianchu.com>
This commit is contained in:
Vinton 2023-01-01 17:25:10 +08:00 committed by GitHub
parent aabafe8610
commit 31042de6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import {
} from 'vue';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { buildUUID } from '/@/utils/uuid';
import { isFunction, isBoolean } from '/@/utils/is';
import { isFunction, isBoolean, isObject } from '/@/utils/is';
import { get, cloneDeep, merge } from 'lodash-es';
import { FETCH_SETTING, ROW_KEY, PAGE_SIZE } from '../const';
@ -206,10 +206,14 @@ export function useDataSource(
});
}
function insertTableDataRecord(record: Recordable, index: number): Recordable | undefined {
function insertTableDataRecord(
record: Recordable | Recordable[],
index: number,
): Recordable | undefined {
// if (!dataSourceRef.value || dataSourceRef.value.length == 0) return;
index = index ?? dataSourceRef.value?.length;
unref(dataSourceRef).splice(index, 0, record);
const _record = isObject(record) ? [record as Recordable] : (record as Recordable[]);
unref(dataSourceRef).splice(index, 0, ..._record);
return unref(dataSourceRef);
}

View File

@ -97,7 +97,7 @@ export interface TableActionType {
setTableData: <T = Recordable>(values: T[]) => void;
updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void;
deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => void;
insertTableDataRecord: (record: Recordable, index?: number) => Recordable | void;
insertTableDataRecord: (record: Recordable | Recordable[], index?: number) => Recordable | void;
findTableDataRecord: (rowKey: string | number) => Recordable | void;
getColumns: (opt?: GetColumnsParams) => BasicColumn[];
setColumns: (columns: BasicColumn[] | string[]) => void;