From 96b9d3f4b39774504c412c207ccfb85528a19d0b Mon Sep 17 00:00:00 2001 From: chaishi <974383157@qq.com> Date: Sun, 15 Oct 2023 15:28:47 +0800 Subject: [PATCH] feat(table): radio filter controller improvement --- src/table/_example/filter-controlled.vue | 2 ++ src/table/filter-controller.tsx | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/table/_example/filter-controlled.vue b/src/table/_example/filter-controlled.vue index 0d993f9ad..a1105442f 100644 --- a/src/table/_example/filter-controlled.vue +++ b/src/table/_example/filter-controlled.vue @@ -107,6 +107,8 @@ export default { { label: '已过期', value: 2 }, { label: '审批失败', value: 3 }, ], + // confirm to search and hide filter popup + confirmEvents: ['onChange'], // 支持透传全部 Popup 组件属性 // popupProps: { // attach: () => document.body, diff --git a/src/table/filter-controller.tsx b/src/table/filter-controller.tsx index 9855cf62a..e253e0a81 100644 --- a/src/table/filter-controller.tsx +++ b/src/table/filter-controller.tsx @@ -106,15 +106,19 @@ export default defineComponent({ if (column.colKey && this.innerFilterValue && column.colKey in this.innerFilterValue) { filterComponentProps.value = this.innerFilterValue[column.colKey]; } - // 这个代码必须放在这里,没事儿别改 + // 这个代码必须放在这里,否则会造成顺序错误 const on = { change: (val: any) => { this.$emit('inner-filter-change', val, column); + if (column.filter?.confirmEvents?.includes('onChange')) { + this.filterPopupVisible = false; + } }, }; // 允许自定义触发确认搜索的事件 if (column.filter.confirmEvents) { column.filter.confirmEvents.forEach((event) => { + if (event === 'onChange') return; const pureEvent = lowerFirst(event.replace('on', '')); on[pureEvent] = () => { this.$emit('confirm', column);