Skip to content

Commit

Permalink
fix(table): wrong indeterminate state
Browse files Browse the repository at this point in the history
修复table在包含默认不显示的列时,settings的[列展示]复选框的初始indeterminate状态不正确的问题
  • Loading branch information
mynetfan committed Jun 5, 2021
1 parent fe2bcfc commit 495b1da
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Table/src/components/settings/ColumnSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import type { BasicColumn } from '../../types/table';
interface State {
indeterminate: boolean;
checkAll: boolean;
checkedList: string[];
defaultCheckList: string[];
Expand Down Expand Up @@ -158,7 +157,6 @@
const columnListRef = ref<ComponentRef>(null);
const state = reactive<State>({
indeterminate: false,
checkAll: true,
checkedList: [],
defaultCheckList: [],
Expand Down Expand Up @@ -233,7 +231,6 @@
// checkAll change
function onCheckAllChange(e: ChangeEvent) {
state.indeterminate = false;
const checkList = plainOptions.value.map((item) => item.value);
if (e.target.checked) {
state.checkedList = checkList;
Expand All @@ -244,10 +241,18 @@
}
}
const indeterminate = computed(() => {
const len = plainOptions.value.length;
let checkdedLen = state.checkedList.length;
if (unref(checkIndex)) {
checkdedLen--;
}
return checkdedLen > 0 && checkdedLen < len;
});
// Trigger when check/uncheck a column
function onChange(checkedList: string[]) {
const len = plainOptions.value.length;
state.indeterminate = !!checkedList.length && checkedList.length < len;
state.checkAll = checkedList.length === len;
const sortList = unref(plainSortOptions).map((item) => item.value);
Expand All @@ -261,7 +266,6 @@
function reset() {
state.checkedList = [...state.defaultCheckList];
state.checkAll = true;
state.indeterminate = false;
plainOptions.value = unref(cachePlainOptions);
plainSortOptions.value = unref(cachePlainOptions);
table.setColumns(table.getCacheColumns());
Expand Down Expand Up @@ -339,6 +343,7 @@
return {
t,
...toRefs(state),
indeterminate,
onCheckAllChange,
onChange,
plainOptions,
Expand Down

0 comments on commit 495b1da

Please sign in to comment.