From 679397f56dd5fcd301dbf95849da9144aebc9a63 Mon Sep 17 00:00:00 2001 From: gene9831 Date: Thu, 5 Dec 2024 19:52:20 +0800 Subject: [PATCH] fix: simplify code logic --- .../src/meta/block/src/BlockGroupFilters.vue | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue b/packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue index 3a9e0ec9c..e8a883e7c 100644 --- a/packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue +++ b/packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue @@ -7,9 +7,14 @@ v-if="!filter.usingSelect" v-model="state.checkGroup[filter.id]" type="checkbox" - @change="getFilters($event, filter.id, filter.children)" + @change="getFilters($event, filter.id)" > - + @@ -59,7 +64,7 @@ export default { ) }) - // 这里重新计算selectOptions的原因:tiny-option的value属性如果是一个对象,那么此对象内部需要有value属性 + // 不同的filter,值所在的字段可能是id或者name。这里把实际的值都映射到value字段 const selectOptions = computed(() => { return props.filters.reduce( (result, filter) => ({ @@ -73,19 +78,9 @@ export default { ) }) - const getFilters = (checked, id, child) => { - filters[id] = [] + const getFilters = (checked, id) => { + filters[id] = checked - // tiny-checkbox-group的选中值是一个字符串数组 - if (typeof checked.at(0) === 'string') { - child.forEach((item) => { - if (checked.includes(item.name)) { - filters[id].push(item.id) - } - }) - } else { - filters[id] = checked.map((item) => item.value) - } emit('search', null, filters) }