fix(table): cellFormat support Map

close: #1031
This commit is contained in:
无木 2021-08-03 20:35:12 +08:00
parent c82040425d
commit 1214b7c32c
2 changed files with 11 additions and 9 deletions

View File

@ -1,14 +1,14 @@
import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table'; import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table';
import type { PaginationProps } from '../types/pagination'; import type { PaginationProps } from '../types/pagination';
import type { ComputedRef } from 'vue'; 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 { renderEditCell } from '../components/editable';
import { usePermission } from '/@/hooks/web/usePermission'; import { usePermission } from '/@/hooks/web/usePermission';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { isBoolean, isArray, isString, isObject, isFunction } from '/@/utils/is'; import { isArray, isBoolean, isFunction, isMap, isString } from '/@/utils/is';
import { isEqual, cloneDeep } from 'lodash-es'; import { cloneDeep, isEqual } from 'lodash-es';
import { formatToDate } from '/@/utils/dateUtil'; 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) { function handleItem(item: BasicColumn, ellipsis: boolean) {
const { key, dataIndex, children } = item; const { key, dataIndex, children } = item;
@ -287,11 +287,9 @@ function sortFixedColumn(columns: BasicColumn[]) {
} }
defColumns.push(column); defColumns.push(column);
} }
const resultColumns = [...fixedLeftColumns, ...defColumns, ...fixedRightColumns].filter( return [...fixedLeftColumns, ...defColumns, ...fixedRightColumns].filter(
(item) => !item.defaultHidden (item) => !item.defaultHidden
); );
return resultColumns;
} }
// format cell // format cell
@ -317,8 +315,8 @@ export function formatCell(text: string, format: CellFormat, record: Recordable,
return formatToDate(text, dateFormat); return formatToDate(text, dateFormat);
} }
// enum // Map
if (isObject(format) && Reflect.has(format, 'size')) { if (isMap(format)) {
return format.get(text); return format.get(text);
} }
} catch (error) { } catch (error) {

View File

@ -84,6 +84,10 @@ export function isElement(val: unknown): val is Element {
return isObject(val) && !!val.tagName; 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 isServer = typeof window === 'undefined';
export const isClient = !isServer; export const isClient = !isServer;