From 86ecb2729ef15bb0bb3fc7347a84ffa83487eec8 Mon Sep 17 00:00:00 2001 From: xachary <179740385@qq.com> Date: Wed, 20 Dec 2023 09:14:35 +0800 Subject: [PATCH] fix(BasicTable): column setting about action fixed and default not cache (#3441) --- .../src/components/settings/ColumnSetting.vue | 33 +++++++++++++++---- .../Table/src/components/settings/index.vue | 1 + 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/components/Table/src/components/settings/ColumnSetting.vue b/src/components/Table/src/components/settings/ColumnSetting.vue index e3f01414..7af39334 100644 --- a/src/components/Table/src/components/settings/ColumnSetting.vue +++ b/src/components/Table/src/components/settings/ColumnSetting.vue @@ -132,6 +132,18 @@ const attrs = useAttrs(); const table = useTableContext(); + const props = withDefaults( + defineProps<{ + /** + * 是否缓存列的设置 + */ + cache?: boolean; + }>(), + { + cache: () => false, + }, + ); + const getPopupContainer = () => { return isFunction(attrs.getPopupContainer) ? attrs.getPopupContainer() : getParentContainer(); }; @@ -168,7 +180,7 @@ // 列表列更新 tableColumnsUpdate(); // 更新列缓存 - columnOptionsSave(); + props.cache && columnOptionsSave(); } }); @@ -197,7 +209,7 @@ // 更新 showIndexColumn showIndexColumnUpdate(e.target.checked); // 更新 showIndexColumn 缓存 - tableSettingStore.setShowIndexColumn(e.target.checked); + props.cache && tableSettingStore.setShowIndexColumn(e.target.checked); // 从无到有需要处理 if (e.target.checked) { const columns = cloneDeep(table?.getColumns()); @@ -223,7 +235,7 @@ // 更新 showRowSelection showRowSelectionUpdate(e.target.checked); // 更新 showRowSelection 缓存 - tableSettingStore.setShowRowSelection(e.target.checked); + props.cache && tableSettingStore.setShowRowSelection(e.target.checked); }; // 更新列缓存 @@ -273,7 +285,7 @@ // 列表列更新 tableColumnsUpdate(); // 更新列缓存 - columnOptionsSave(); + props.cache && columnOptionsSave(); }; // 沿用逻辑 @@ -344,6 +356,13 @@ } } + // 是否存在 action + const actionIndex = columns.findIndex((o) => o.dataIndex === 'action'); + if (actionIndex > -1) { + const actionCol = columns.splice(actionIndex, 1); + columns.push(actionCol[0]); + } + // 设置列表列 tableColumnsSet(columns); }; @@ -384,7 +403,7 @@ // 列表列更新 tableColumnsUpdate(); // 更新列缓存 - columnOptionsSave(); + props.cache && columnOptionsSave(); }, }); } @@ -548,10 +567,10 @@ columnOptions.value = cloneDeep(options); // remove消失的列、push新出现的列 - diff(); + props.cache && diff(); // 从缓存恢复 - restore(); + props.cache && restore(); // 更新表单状态 formUpdate(); diff --git a/src/components/Table/src/components/settings/index.vue b/src/components/Table/src/components/settings/index.vue index f60e646b..ec41e9af 100644 --- a/src/components/Table/src/components/settings/index.vue +++ b/src/components/Table/src/components/settings/index.vue @@ -6,6 +6,7 @@ v-if="getSetting.setting" @columns-change="handleColumnChange" :getPopupContainer="getTableContainer" + :cache="false" />