Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update block filters UI in materials #914

Merged
merged 9 commits into from
Dec 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
justify-content: center;
}
.footer-toolbar {
margin-right: -12px;
.icon-wrap {
width: 20px;
height: 20px;
Expand Down
85 changes: 65 additions & 20 deletions packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,47 @@
<div class="block-filters-item-label">{{ filter.name }}</div>
<div class="block-filters-item-value">
<tiny-checkbox-group
v-model="state.checkGroup"
v-if="!filter.usingSelect"
v-model="state.checkGroup[filter.id]"
type="checkbox"
@change="getFilters(filter.id, filter.children)"
@change="getFilters($event, filter.id)"
>
<tiny-checkbox v-for="item in filter.children" :key="item.name" :label="item.name"></tiny-checkbox>
<tiny-checkbox
v-for="item in selectOptions[filter.id]"
:key="item.value"
:text="item.name"
:label="item.value"
></tiny-checkbox>
</tiny-checkbox-group>
<tiny-select
v-else
v-model="state.checkGroup[filter.id]"
size="mini"
multiple
@change="getFilters($event, filter.id)"
>
<tiny-option
v-for="item in selectOptions[filter.id]"
:key="item.value"
:label="item.name"
:value="item.value"
></tiny-option>
</tiny-select>
</div>
</div>
</div>
</template>

<script>
import { reactive } from 'vue'
import { CheckboxGroup, Checkbox } from '@opentiny/vue'
import { computed, reactive } from 'vue'
import { CheckboxGroup, Checkbox, Select, Option } from '@opentiny/vue'

export default {
components: {
TinyCheckboxGroup: CheckboxGroup,
TinyCheckbox: Checkbox
TinyCheckbox: Checkbox,
TinySelect: Select,
TinyOption: Option
},
props: {
filters: {
Expand All @@ -33,25 +55,38 @@ export default {
setup(props, { emit }) {
const filters = {}
const state = reactive({
checkGroup: []
checkGroup: props.filters.reduce(
(result, filter) => ({
...result,
[filter.id]: []
}),
{}
)
})

const getFilters = (id, child) => {
filters[id] = []
if (id === 'tag') {
filters[id] = state.checkGroup
} else {
child.forEach((item) => {
if (state.checkGroup.includes(item.name)) {
filters[id].push(item.id)
}
})
}
// 不同的filter,值所在的字段可能是id或者name。这里把实际的值都映射到value字段
const selectOptions = computed(() => {
return props.filters.reduce(
(result, filter) => ({
...result,
[filter.id]: filter.children.map((item) => ({
...item,
value: item.id || item.name
}))
}),
{}
)
})

const getFilters = (checked, id) => {
filters[id] = checked

emit('search', null, filters)
}

return {
state,
selectOptions,
getFilters
}
}
Expand All @@ -61,6 +96,12 @@ export default {
<style lang="less" scoped>
.block-add-filters {
color: var(--ti-lowcode-materials-block-filter-text-color);
& > div {
min-height: 24px;
}
& > div + div {
margin-top: 12px;
}

.block-add-filters-item {
display: flex;
Expand All @@ -73,13 +114,11 @@ export default {
align-items: center;
justify-content: flex-start;
width: 76px;
height: 28px;
color: var(--te-common-text-secondary);
border-radius: 2px;
}

.block-filters-item-value {
align-items: center;
flex: 1;
color: var(--te-common-text-primary);
.block-filters-value-item {
Expand All @@ -94,6 +133,12 @@ export default {
display: none;
}
}
:deep(.tiny-select.tiny-select .tiny-select__tags) {
max-width: calc(100% - 24px) !important;
.tiny-tag {
background-color: var(--te-common-bg-container);
gene9831 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ export default {
{
id: 'author',
name: '按作者',
children: []
children: [],
usingSelect: true
},
{
id: 'tag',
name: '按标签',
children: []
children: [],
usingSelect: true
}
]
})
Expand Down
Loading