From 495b1da385e9b6428d2b994669d2065722445923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Sat, 5 Jun 2021 16:22:26 +0800 Subject: [PATCH] fix(table): wrong indeterminate state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复table在包含默认不显示的列时,settings的[列展示]复选框的初始indeterminate状态不正确的问题 --- .../src/components/settings/ColumnSetting.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Table/src/components/settings/ColumnSetting.vue b/src/components/Table/src/components/settings/ColumnSetting.vue index aab33ef8c16..cc230202f1d 100644 --- a/src/components/Table/src/components/settings/ColumnSetting.vue +++ b/src/components/Table/src/components/settings/ColumnSetting.vue @@ -117,7 +117,6 @@ import type { BasicColumn } from '../../types/table'; interface State { - indeterminate: boolean; checkAll: boolean; checkedList: string[]; defaultCheckList: string[]; @@ -158,7 +157,6 @@ const columnListRef = ref(null); const state = reactive({ - indeterminate: false, checkAll: true, checkedList: [], defaultCheckList: [], @@ -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; @@ -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); @@ -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()); @@ -339,6 +343,7 @@ return { t, ...toRefs(state), + indeterminate, onCheckAllChange, onChange, plainOptions,