From 8b3a4d37a8addd151b918cf64bce6361376dec9e Mon Sep 17 00:00:00 2001 From: vben <anncwb@126.com> Date: 星期三, 21 十月 2020 21:44:57 +0800 Subject: [PATCH] feat: add table setting --- src/components/Table/src/hooks/useColumns.ts | 25 ++++++++----------------- 1 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/components/Table/src/hooks/useColumns.ts b/src/components/Table/src/hooks/useColumns.ts index 77c1176..b1a627a 100644 --- a/src/components/Table/src/hooks/useColumns.ts +++ b/src/components/Table/src/hooks/useColumns.ts @@ -81,28 +81,19 @@ } if (actionColumn) { const hasIndex = columns.findIndex((column) => column.flag === 'ACTION'); - if (hasIndex === -1) { - columns.push({ - fixed: 'right', - ...actionColumn, - flag: 'ACTION', - }); - } else { - columns[hasIndex] = { - ...columns[hasIndex], - fixed: 'right', - ...actionColumn, - flag: 'ACTION', - }; - } + columns.push({ + ...(hasIndex === -1 ? columns[hasIndex] : {}), + fixed: 'right', + ...actionColumn, + flag: 'ACTION', + }); } return columns; }); function setColumns(columns: BasicColumn[] | string[]) { - if (!isArray(columns)) { - return; - } + if (!isArray(columns)) return; + if (columns.length <= 0) { columnsRef.value = []; return; -- Gitblit v1.8.0