From fc002d3db327a432259eb02e2a72b9b81381eb6e Mon Sep 17 00:00:00 2001 From: xachary <179740385@qq.com> Date: Tue, 26 Dec 2023 20:41:03 +0800 Subject: [PATCH] fix: column setting index column sort (#3463) * fix: keep rowSelection onChange call outside * fix: ColumnSetting index column sort wrong --- .../src/components/settings/ColumnSetting.vue | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/components/Table/src/components/settings/ColumnSetting.vue b/src/components/Table/src/components/settings/ColumnSetting.vue index 945bdbfe..85921fa1 100644 --- a/src/components/Table/src/components/settings/ColumnSetting.vue +++ b/src/components/Table/src/components/settings/ColumnSetting.vue @@ -113,6 +113,7 @@ import { getPopupContainer as getParentContainer } from '@/utils'; import { cloneDeep, omit } from 'lodash-es'; import Sortablejs from 'sortablejs'; + import { INDEX_COLUMN_FLAG } from '@/components/Table/src/const'; // 列表设置缓存 import { useTableSettingStore } from '@/store/modules/tableSetting'; @@ -210,22 +211,6 @@ showIndexColumnUpdate(e.target.checked); // 更新 showIndexColumn 缓存 props.cache && tableSettingStore.setShowIndexColumn(e.target.checked); - // 从无到有需要处理 - if (e.target.checked) { - const columns = cloneDeep(table?.getColumns()); - const idx = columns.findIndex((o) => o.flag === 'INDEX'); - // 找到序号列 - if (idx > -1) { - const cache = columns[idx]; - // 强制左fix - cache.fixed = 'left'; - // 强制移动到 第一/选择列后 - columns.splice(idx, 1); - columns.splice(0, 0, cache); - // 设置列表列 - tableColumnsSet(columns); - } - } }; // 是否显示选择列 @@ -340,8 +325,15 @@ // 考虑了所有列 const columns = cloneDeep(table.getColumns()); - // 从左 fixed 最一列开始排序 - let count = columns.filter((o) => o.fixed === 'left' || o.fixed === true).length; + // 从左 fixed 最一列开始排序(除了 序号列) + let count = columns.filter( + (o) => o.flag !== INDEX_COLUMN_FLAG && (o.fixed === 'left' || o.fixed === true), + ).length; + + // 序号列提前 + if (isIndexColumnShow.value) { + count++; + } // 按 columnOptions 的排序 调整 table.getColumns() 的顺序和值 for (const opt of columnOptions.value) {