fix: 修复Table当dataIndex为数组时,列设置中勾选列是否展示时使column结构异常的问题 (#1626)

This commit is contained in:
Leo Caan (陈栋) 2022-03-19 00:05:30 +08:00 committed by GitHub
parent 573a443007
commit 3d55b0d45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,7 +197,7 @@ export function useColumns(
* set columns
* @param columnList keycolumn
*/
function setColumns(columnList: Partial<BasicColumn>[] | string[]) {
function setColumns(columnList: Partial<BasicColumn>[] | (string | string[])[]) {
const columns = cloneDeep(columnList);
if (!isArray(columns)) return;
@ -210,23 +210,23 @@ export function useColumns(
const cacheKeys = cacheColumns.map((item) => item.dataIndex);
if (!isString(firstColumn)) {
if (!isString(firstColumn) && !isArray(firstColumn)) {
columnsRef.value = columns as BasicColumn[];
} else {
const columnKeys = columns as string[];
const columnKeys = (columns as (string | string[])[]).map(m => m.toString());
const newColumns: BasicColumn[] = [];
cacheColumns.forEach((item) => {
newColumns.push({
...item,
defaultHidden: !columnKeys.includes(item.dataIndex! || (item.key as string)),
defaultHidden: !columnKeys.includes(item.dataIndex?.toString() || (item.key as string))
});
});
// Sort according to another array
if (!isEqual(cacheKeys, columns)) {
newColumns.sort((prev, next) => {
return (
columnKeys.indexOf(prev.dataIndex as string) -
columnKeys.indexOf(next.dataIndex as string)
columnKeys.indexOf(prev.dataIndex?.toString() as string) -
columnKeys.indexOf(next.dataIndex?.toString() as string)
);
});
}