From 1214b7c32c425750a4d0202a9b235eb9e45a6f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Tue, 3 Aug 2021 20:35:12 +0800 Subject: [PATCH] fix(table): `cellFormat` support `Map` close: #1031 --- src/components/Table/src/hooks/useColumns.ts | 16 +++++++--------- src/utils/is.ts | 4 ++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/Table/src/hooks/useColumns.ts b/src/components/Table/src/hooks/useColumns.ts index d1ef75055..8702f2a65 100644 --- a/src/components/Table/src/hooks/useColumns.ts +++ b/src/components/Table/src/hooks/useColumns.ts @@ -1,14 +1,14 @@ import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table'; import type { PaginationProps } from '../types/pagination'; import type { ComputedRef } from 'vue'; -import { unref, Ref, computed, watch, ref, toRaw } from 'vue'; +import { computed, Ref, ref, toRaw, unref, watch } from 'vue'; import { renderEditCell } from '../components/editable'; import { usePermission } from '/@/hooks/web/usePermission'; import { useI18n } from '/@/hooks/web/useI18n'; -import { isBoolean, isArray, isString, isObject, isFunction } from '/@/utils/is'; -import { isEqual, cloneDeep } from 'lodash-es'; +import { isArray, isBoolean, isFunction, isMap, isString } from '/@/utils/is'; +import { cloneDeep, isEqual } from 'lodash-es'; import { formatToDate } from '/@/utils/dateUtil'; -import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const'; +import { ACTION_COLUMN_FLAG, DEFAULT_ALIGN, INDEX_COLUMN_FLAG, PAGE_SIZE } from '../const'; function handleItem(item: BasicColumn, ellipsis: boolean) { const { key, dataIndex, children } = item; @@ -287,11 +287,9 @@ function sortFixedColumn(columns: BasicColumn[]) { } defColumns.push(column); } - const resultColumns = [...fixedLeftColumns, ...defColumns, ...fixedRightColumns].filter( + return [...fixedLeftColumns, ...defColumns, ...fixedRightColumns].filter( (item) => !item.defaultHidden ); - - return resultColumns; } // format cell @@ -317,8 +315,8 @@ export function formatCell(text: string, format: CellFormat, record: Recordable, return formatToDate(text, dateFormat); } - // enum - if (isObject(format) && Reflect.has(format, 'size')) { + // Map + if (isMap(format)) { return format.get(text); } } catch (error) { diff --git a/src/utils/is.ts b/src/utils/is.ts index eeff9270f..5b3ae08fb 100644 --- a/src/utils/is.ts +++ b/src/utils/is.ts @@ -84,6 +84,10 @@ export function isElement(val: unknown): val is Element { return isObject(val) && !!val.tagName; } +export function isMap(val: unknown): val is Map { + return is(val, 'Map'); +} + export const isServer = typeof window === 'undefined'; export const isClient = !isServer;