Commit d3e7755c by Lin

feat: 顶部tab及筛选栏组件封装

1 parent 392a1f76
<template>
<div class="top-header">
<!-- 左侧 Tabs -->
<div class="tabs-nav" ref="tabsNav">
<div
v-for="(tab, index) in tabs"
:key="tab"
:ref="`tabItem${index}`"
:class="['tab-item', { active: currentTab === tab }]"
@click="switchTab(tab)"
>
{{ tab }}
</div>
<!-- 选中指示条 - 独立元素,通过动态计算位置实现滑动效果 -->
<div
class="active-line"
:style="activeLineStyle"
></div>
</div>
<!-- 分割线 (可选,增加视觉间隔) -->
<div class="vertical-divider"></div>
<!-- 右侧 筛选区 + 按钮 -->
<div class="filter-area">
<div class="filter-group">
<span class="label">区域:</span>
<el-select v-model="localFilters.region" size="small" placeholder="全部" class="filter-select" filterable clearable>
<el-option label="全部" value="all"></el-option>
</el-select>
</div>
<div class="filter-group">
<span class="label">品牌:</span>
<el-cascader
v-model="localFilters.brand"
:options="brandOptions"
:props="cascaderProps"
collapse-tags
size="small"
class="filter-select-brand"
:show-all-levels="false"
clearable></el-cascader>
</div>
<div class="filter-group">
<span class="label">区域运营:</span>
<el-select v-model="localFilters.regionOps" size="small" placeholder="全部" class="filter-select" filterable clearable>
<el-option label="全部" value="all"></el-option>
</el-select>
</div>
<div class="filter-group">
<span class="label">线上运营:</span>
<el-select v-model="localFilters.onlineOps" size="small" placeholder="全部" class="filter-select" filterable clearable>
<el-option label="全部" value="all"></el-option>
</el-select>
</div>
<!-- 按钮组 -->
<div class="btn-group">
<el-button type="primary" size="small" class="btn-search" @click="handleSearch">查询</el-button>
<el-button size="small" class="btn-reset" @click="handleReset">重置</el-button>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'HeaderCustom',
props: {
// Tabs 配置
tabs: {
type: Array,
default: () => ['延保', '权益', '轻改']
},
// 当前选中的 Tab
value: {
type: String,
default: '延保'
},
// 筛选条件
filters: {
type: Object,
default: () => ({
region: '',
brand: [],
regionOps: '',
onlineOps: ''
})
},
// 品牌级联选择器数据
brandOptions: {
type: Array,
default: () => []
}
},
data() {
return {
currentTab: this.value,
activeLineStyle: { transform: 'translateX(0px)', width: '52px' },
localFilters: { ...this.filters },
// 级联选择器配置
cascaderProps: {
value: 'value',
label: 'label',
children: 'children',
expandTrigger: 'hover',
emitPath: true,
checkStrictly: true, // 允许选择任意一级
multiple: true // 启用多选功能(Element UI 2.x 需要在 props 中配置)
}
};
},
watch: {
// 监听外部传入的 value 变化
value(newVal) {
this.currentTab = newVal;
this.$nextTick(this.updateActiveLinePosition);
},
// 监听外部传入的 filters 变化
filters: {
handler(newVal) {
this.localFilters = { ...newVal };
},
deep: true
}
},
mounted() {
this.$nextTick(this.updateActiveLinePosition);
},
methods: {
switchTab(tab) {
this.currentTab = tab;
this.$emit('input', tab);
this.$emit('tab-change', tab);
this.$nextTick(this.updateActiveLinePosition);
},
updateActiveLinePosition() {
const currentIndex = this.tabs.indexOf(this.currentTab);
const tabItemRef = this.$refs[`tabItem${currentIndex}`];
if (!tabItemRef?.[0]) return;
const { offsetLeft, offsetWidth } = tabItemRef[0];
this.activeLineStyle = {
transform: `translateX(${offsetLeft}px)`,
width: `${offsetWidth}px`
};
},
handleSearch() {
this.$emit('search', { ...this.localFilters });
},
handleReset() {
const resetFilters = {
region: '',
brand: [],
regionOps: '',
onlineOps: ''
};
this.localFilters = { ...resetFilters };
this.$emit('reset', resetFilters);
this.$emit('search', resetFilters);
}
}
};
</script>
<style lang="scss" scoped>
// 颜色变量
$primary: #2A58AD;
$text-main: #1D2129;
$text-sub: #333333;
$text-sub-2: #666666;
$border: #E5E6EB;
$bg-red: #FEF0F0;
$text-red: #F53F3F;
$bg-orange: #FDF6EC;
$text-orange: #FF7D00;
// ================= Top Header =================
.top-header {
background: #fff;
height: 54px;
display: flex;
align-items: center;
padding: 0 24px;
border-radius: 4px;
margin-bottom: 1px;
position: sticky;
top: 0;
z-index: 100;
// 确保 sticky 定位正常工作
flex-shrink: 0;
}
.tabs-nav {
position: relative;
display: flex;
height: 100%;
.tab-item {
height: 100%;
width: 54px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 32px;
font-size: 16px;
color: $text-sub;
cursor: pointer;
transition: all 0.2s;
&:hover { color: $primary; }
&.active { color: $primary; font-weight: 500; font-size: 16px;}
}
}
.active-line {
position: absolute;
bottom: 0;
left: 0;
height: 3px;
background: $primary;
border-radius: 2px 2px 0 0;
transition: transform 0.3s cubic-bezier(0.645, 0.045, 0.355, 1),
width 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.vertical-divider {
width: 1px;
height: 20px;
background: $border;
margin-right: 32px;
}
.filter-area {
flex: 1;
display: flex;
align-items: center;
.filter-group {
display: flex;
align-items: center;
margin-right: 24px;
.label { font-size: 14px; color: $text-sub; margin-right: 8px; white-space: nowrap; }
.filter-select { width: 123px; }
.filter-select-brand { width: 170px; }
}
.btn-group { margin-left: auto; display: flex; gap: 12px; }
.btn-search { background: $primary; border-color: $primary; border-radius: 4px;&:hover { opacity: 0.9; }}
.btn-reset { background: #F2F3F5; border-color: #F2F3F5; color: $text-sub; &:hover { background: #e5e6eb; } border-radius: 4px;}
}
// 覆盖 Element UI 样式
::v-deep {
.el-input__inner {
border-radius: 2px;
border-color: $border;
color: $text-main;
&:hover { border-color: #C9CDD4; }
&:focus { border-color: $primary; }
}
.el-button--small { border-radius: 2px; }
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!