From 8d07bb29cba4fd6012520fd8d912b64a8f4e596b Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期五, 11 十月 2024 17:13:02 +0800 Subject: [PATCH] 初始状态设置 colFilter --- src/components/table/colFilter/ColFilter.vue | 44 +++++++++++++++++++++++++++++--------------- 1 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/table/colFilter/ColFilter.vue b/src/components/table/colFilter/ColFilter.vue index e113291..6a56b54 100644 --- a/src/components/table/colFilter/ColFilter.vue +++ b/src/components/table/colFilter/ColFilter.vue @@ -34,7 +34,7 @@ }); const colCheckChange = (option: CheckOption) => { - const { key, value } = option; + const { key } = option; if (key === allCheckKey) { if (option.indeterminate) { option.indeterminate = false; @@ -62,17 +62,10 @@ } } }; -const checkOptionList = ref<CheckOption[]>( - ( - [ - { - key: allCheckKey, - label: '鍏ㄩ��/涓嶉��', - value: true, - }, - ] as CheckOption[] - ).concat( - props.columnList.map((item) => ({ +const checkOptionList = computed<CheckOption[]>(() => { + let checkedCount = 0; + const options = props.columnList.map((item) => { + const result = { key: item.prop, label: item.label, get value() { @@ -81,7 +74,28 @@ set value(val) { item.isShow = val; }, - })) - ) -); + }; + + result.value && checkedCount++; + return result; + }); + const total = options.length; + const firstOption: CheckOption = { + key: allCheckKey, + label: '鍏ㄩ��/涓嶉��', + value: false, + }; + if (checkedCount === 0 || total === checkedCount) { + firstOption.indeterminate = false; + if (checkedCount === 0) { + firstOption.value = false; + } else { + firstOption.value = true; + } + } else { + firstOption.indeterminate = true; + } + options.unshift(firstOption); + return options; +}); </script> -- Gitblit v1.9.3