Commit 78a0f397 authored by 徐一鸣's avatar 徐一鸣

服务管理筛选组件优化

parent 793994fd
<template> <template>
<ul <ul
class="ces_filter_container" class="ces_filter_container"
ref="filterContainer"
v-if="filterList && filterData && filterToggle" v-if="filterList && filterData && filterToggle"
v-show="show" v-show="show"
> >
...@@ -9,41 +8,34 @@ ...@@ -9,41 +8,34 @@
<div class="ces_filter_name"> <div class="ces_filter_name">
<span v-text="item.name + ':'"></span> <span v-text="item.name + ':'"></span>
</div> </div>
<ul class="ces_filter_data"> <ul
<li class="ces_filter_data"
v-for="(v, i) in item.data" :ref="'filterList_' + index"
:key="'f_l_d_' + index + '_' + i"
v-show="filterToggle[item.prop] || i < filterLength"
:style="{ :style="{
'margin-top': i < filterLength ? '0' : '10px', height: filterToggle[item.prop] ? '' : '42px',
}" }"
> >
<li v-for="(v, i) in item.data" :key="'f_l_d_' + index + '_' + i">
<a <a
class="text_clip" class="text_clip"
:class="{ current: isCurrentFilter(item.prop, v) }" :class="{ current: isCurrentFilter(item.prop, v) }"
@click.prevent="selectFilter(item.prop, v)" @click.prevent="selectFilter(item.prop, v)"
>
<el-tooltip
effect="dark"
:content="v.name"
placement="top"
> >
<span v-text="v.name"></span> <span v-text="v.name"></span>
</el-tooltip>
</a> </a>
</li> </li>
<div <div
class="toggle_bar" class="toggle_bar"
v-if="item.data.length > filterLength"
@click="filterToggleAction(item.prop)" @click="filterToggleAction(item.prop)"
v-if="showToggleBar[index]"
> >
<span>{{ filterToggle[item.prop] ? "收起" : "展开" }}</span> <span>{{ filterToggle[item.prop] ? "收起" : "展开" }}</span>
<i <i
:class=" :class="
filterToggle[item.prop] filterToggle[item.prop]
? 'el-icon-caret-bottom' ? 'el-icon-caret-top'
: 'el-icon-caret-top' : 'el-icon-caret-bottom'
" "
></i> ></i>
</div> </div>
...@@ -67,7 +59,7 @@ export default { ...@@ -67,7 +59,7 @@ export default {
data: () => ({ data: () => ({
filterData: null, // 筛选条件 filterData: null, // 筛选条件
filterToggle: null, // 控制筛选条件的展开和收起 filterToggle: null, // 控制筛选条件的展开和收起
filterLength: 0, // 每行最多可容纳多少个过滤条件 showToggleBar: [],
}), }),
watch: { watch: {
filterList: { filterList: {
...@@ -78,7 +70,7 @@ export default { ...@@ -78,7 +70,7 @@ export default {
}, },
show(value) { show(value) {
if (value) { if (value) {
this.getFilterLength(); this.resizePage();
} }
}, },
}, },
...@@ -93,18 +85,21 @@ export default { ...@@ -93,18 +85,21 @@ export default {
}); });
} }
}, },
getFilterLength() { resizePage() {
if (this.show) { if (this.show) {
this.$nextTick(() => { this.$nextTick(() => {
let width = this.showToggleBar = [];
this.$refs.filterContainer.getBoundingClientRect().width - this.filterList.forEach((item, index) => {
20 * 2 - // 两侧padding let filterList = this.$refs["filterList_" + index][0];
100 - // 左侧标题 let width = filterList.getBoundingClientRect().width - 100;
20 - // 距左侧标题的边距 let totalWidth = 0;
110; // 折叠按钮的宽度
filterList.querySelectorAll("li").forEach((v, i) => {
totalWidth += v.getBoundingClientRect().width;
});
this.filterLength = Math.floor(width / 150); this.showToggleBar.push(totalWidth > width);
// console.log("每行最多可容纳" + this.filterLength + "个filter"); });
}); });
} }
}, },
...@@ -131,10 +126,10 @@ export default { ...@@ -131,10 +126,10 @@ export default {
mounted() { mounted() {
this.initFilterData(); this.initFilterData();
window.addEventListener("resize", this.getFilterLength); window.addEventListener("resize", this.resizePage);
}, },
destroyed() { destroyed() {
window.removeEventListener("resize", this.getFilterLength); window.removeEventListener("resize", this.resizePage);
}, },
}; };
</script> </script>
...@@ -165,24 +160,22 @@ export default { ...@@ -165,24 +160,22 @@ export default {
.ces_filter_data { .ces_filter_data {
width: calc(100% - 120px); width: calc(100% - 120px);
min-height: 42px; min-height: 42px;
padding-right: 110px; padding-right: 100px;
box-sizing: border-box; box-sizing: border-box;
margin-left: 20px; margin-left: 20px;
flex-grow: 1; flex-grow: 1;
display: inline-flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
padding-bottom: 11px;
position: relative; position: relative;
} overflow: hidden;
.ces_filter_container > li:not(:last-child) > .ces_filter_data { font-size: 0;
border-bottom: 1px solid #e9ecf3;
} }
.ces_filter_data > li { .ces_filter_data > li {
flex-shrink: 0; display: inline-block;
vertical-align: middle;
padding-right: 20px; padding-right: 20px;
} }
.ces_filter_container > li:not(:last-child) > .ces_filter_data {
border-bottom: 1px solid #e9ecf3;
}
.ces_filter_data > .toggle_bar { .ces_filter_data > .toggle_bar {
height: 30px; height: 30px;
position: absolute; position: absolute;
...@@ -193,10 +186,12 @@ export default { ...@@ -193,10 +186,12 @@ export default {
color: #0f2683; color: #0f2683;
cursor: pointer; cursor: pointer;
} }
.ces_filter_data > li {
margin-bottom: 10px;
}
.ces_filter_data > li > a { .ces_filter_data > li > a {
display: block; display: block;
height: 30px; height: 30px;
width: 130px;
padding: 0 15px; padding: 0 15px;
box-sizing: border-box; box-sizing: border-box;
border-radius: 12px; border-radius: 12px;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment