From 495e1d56ccaf8a70e770ba34b7a3120c3f96a4b5 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:02:19 +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.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/vue/src/components/Table/src/hooks/useDataSource.ts | 7 ++++--- apps/vue/src/components/Table/src/types/table.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/vue/src/components/Table/src/hooks/useDataSource.ts b/apps/vue/src/components/Table/src/hooks/useDataSource.ts index 15d3677e7..0a9f852b1 100644 --- a/apps/vue/src/components/Table/src/hooks/useDataSource.ts +++ b/apps/vue/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,11 @@ 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/apps/vue/src/components/Table/src/types/table.ts b/apps/vue/src/components/Table/src/types/table.ts index d3e9d4fea..6e5915fab 100644 --- a/apps/vue/src/components/Table/src/types/table.ts +++ b/apps/vue/src/components/Table/src/types/table.ts @@ -98,7 +98,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;