diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 780b3f80..8b0c400f 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -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); } diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index df53ed95..6ac1eb47 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -97,7 +97,7 @@ export interface TableActionType { setTableData: (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;