Skip to content

Commit

Permalink
fix: block list filters not clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
gene9831 committed Jan 8, 2025
1 parent a14a508 commit f524c06
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
29 changes: 18 additions & 11 deletions packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<div class="block-filters-item-value">
<tiny-checkbox-group
v-if="!filter.usingSelect"
v-model="state.checkGroup[filter.id]"
v-model="state.filterValues[filter.id]"
type="checkbox"
@change="getFilters($event, filter.id)"
@change="handleValueChange"
>
<tiny-checkbox
v-for="item in selectOptions[filter.id]"
Expand All @@ -18,11 +18,11 @@
</tiny-checkbox-group>
<tiny-select
v-else
v-model="state.checkGroup[filter.id]"
v-model="state.filterValues[filter.id]"
size="mini"
multiple
is-drop-inherit-width
@change="getFilters($event, filter.id)"
@change="handleValueChange"
>
<tiny-option
v-for="item in selectOptions[filter.id]"
Expand Down Expand Up @@ -54,15 +54,19 @@ export default {
}
},
setup(props, { emit }) {
const filters = {}
const state = reactive({
checkGroup: props.filters.reduce(
const initFilterValues = () => {
return props.filters.reduce(
(result, filter) => ({
...result,
[filter.id]: []
}),
{}
)
}
const state = reactive({
// filterValues 是一个对象。key 为 filter id,value 为选中的值,是一个数组
filterValues: initFilterValues()
})
// 不同的filter,值所在的字段可能是id或者name。这里把实际的值都映射到value字段
Expand All @@ -79,16 +83,19 @@ export default {
)
})
const getFilters = (checked, id) => {
filters[id] = checked
const handleValueChange = () => {
emit('search', state.filterValues)
}
emit('search', null, filters)
const clearFilters = () => {
state.filterValues = initFilterValues()
}
return {
state,
selectOptions,
getFilters
handleValueChange,
clearFilters
}
}
}
Expand Down
27 changes: 21 additions & 6 deletions packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
<template #content>
<div class="block-add-content">
<div class="block-add-content-title">区块列表</div>
<block-group-filters :filters="state.filters" @search="searchBlocks"></block-group-filters>
<block-group-filters
ref="groupFiltersRef"
:filters="state.filters"
@search="searchBlocks"
></block-group-filters>
<block-group-transfer v-model:blockList="state.blockList">
<template #search>
<tiny-search
class="transfer-order-search"
v-model="state.searchValue"
placeholder="请输入关键词"
@update:modelValue="searchBlocks"
@update:modelValue="searchBlocks(state.filterValues)"
>
<template #prefix>
<tiny-icon-search />
Expand Down Expand Up @@ -106,9 +110,18 @@ export default {
children: [],
usingSelect: true
}
]
],
filterValues: {}
})
const groupFiltersRef = ref(null)
const clearSearchParams = () => {
state.searchValue = ''
state.filterValues = {}
groupFiltersRef.value?.clearFilters()
}
const addBlocks = () => {
const groupId = selectedGroup.value.groupId
fetchGroupBlocksById({ groupId })
Expand Down Expand Up @@ -142,7 +155,7 @@ export default {
useMaterial().updateCanvasDependencies(addedBlocks)
isRefresh.value = true
state.searchValue = ''
clearSearchParams()
selectedBlockArray.value.length = 0
useResource().fetchResource({ isInit: false }) // 添加区块分组,不需要重新init页面或者区块。
useNotify({
Expand All @@ -165,7 +178,7 @@ export default {
}
const closeGroupPanel = () => {
state.searchValue = ''
clearSearchParams()
selectedBlockArray.value.length = 0
panelState.isBlockGroupPanel = false
closePanel()
Expand All @@ -180,7 +193,8 @@ export default {
return blocks.filter((block) => !isInBlockGroup(block) && !isSelectedBlock(block))
}
const searchBlocks = (value, filters) => {
const searchBlocks = (filters) => {
state.filterValues = filters
nextTick(() => {
const params = {
groupId: selectedGroup.value.groupId,
Expand Down Expand Up @@ -259,6 +273,7 @@ export default {
return {
selectedGroup,
state,
groupFiltersRef,
panel,
closeGroupPanel,
addBlocks,
Expand Down

0 comments on commit f524c06

Please sign in to comment.