Skip to content

Commit

Permalink
fix(BasicTable): column setting about action fixed and default not ca…
Browse files Browse the repository at this point in the history
…che (vbenjs#3441)
  • Loading branch information
xachary authored and chenhongbin committed Dec 20, 2023
1 parent 6d97df2 commit a23a997
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/components/Table/src/components/settings/ColumnSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -168,7 +180,7 @@
// 列表列更新
tableColumnsUpdate();
// 更新列缓存
columnOptionsSave();
props.cache && columnOptionsSave();
}
});
Expand Down Expand Up @@ -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());
Expand All @@ -223,7 +235,7 @@
// 更新 showRowSelection
showRowSelectionUpdate(e.target.checked);
// 更新 showRowSelection 缓存
tableSettingStore.setShowRowSelection(e.target.checked);
props.cache && tableSettingStore.setShowRowSelection(e.target.checked);
};
// 更新列缓存
Expand Down Expand Up @@ -273,7 +285,7 @@
// 列表列更新
tableColumnsUpdate();
// 更新列缓存
columnOptionsSave();
props.cache && columnOptionsSave();
};
// 沿用逻辑
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -384,7 +403,7 @@
// 列表列更新
tableColumnsUpdate();
// 更新列缓存
columnOptionsSave();
props.cache && columnOptionsSave();
},
});
}
Expand Down Expand Up @@ -548,10 +567,10 @@
columnOptions.value = cloneDeep(options);
// remove消失的列、push新出现的列
diff();
props.cache && diff();
// 从缓存恢复
restore();
props.cache && restore();
// 更新表单状态
formUpdate();
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/src/components/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
v-if="getSetting.setting"
@columns-change="handleColumnChange"
:getPopupContainer="getTableContainer"
:cache="false"
/>
<FullScreenSetting v-if="getSetting.fullScreen" :getPopupContainer="getTableContainer" />
</div>
Expand Down

0 comments on commit a23a997

Please sign in to comment.