From 31042de6bc0683132f57262e452dc3aa15cc8de0 Mon Sep 17 00:00:00 2001 From: Vinton <45648362+vintonHuang@users.noreply.github.com> Date: Sun, 1 Jan 2023 17:25:10 +0800 Subject: [PATCH] =?UTF-8?q?perf(component):=20=E4=BC=98=E5=8C=96table=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84insertTableDataRecord=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82=20(#2481?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: huangwentao --- src/components/Table/src/hooks/useDataSource.ts | 10 +++++++--- src/components/Table/src/types/table.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 780b3f802..8b0c400f0 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 df53ed95c..6ac1eb47a 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;