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>
<template> <template>
<div class="dashboard-page"> <div class="dashboard-page">
<!-- 1. 顶部导航栏 (Tabs + 筛选 + 按钮 同一行展示) --> <!-- 1. 顶部导航栏 (Tabs + 筛选 + 按钮 同一行展示) -->
<div class="top-header"> <header-custom
<!-- 左侧 Tabs --> v-model="currentTab"
<div class="tabs-nav" ref="tabsNav"> :tabs="tabs"
<div :filters="filters"
v-for="(tab, index) in tabs" :brand-options="brandOptions"
:key="tab" @tab-change="handleTabChange"
:ref="`tabItem${index}`" @search="handleSearch"
:class="['tab-item', { active: currentTab === tab }]" @reset="handleReset"
@click="switchTab(tab)" ></header-custom>
>
{{ 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="filters.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
: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="filters.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="filters.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">查询</el-button>
<el-button size="small" class="btn-reset">重置</el-button>
</div>
</div>
</div>
<!-- 2. 中间工具栏 --> <!-- 2. 中间工具栏 -->
<div class="toolbar-container"> <div class="toolbar-container">
...@@ -195,28 +143,19 @@ ...@@ -195,28 +143,19 @@
<script> <script>
import MonitorCard from './compoments/monitorCard.vue'; import MonitorCard from './compoments/monitorCard.vue';
import HeaderCustom from './compoments/headerCustom.vue';
export default { export default {
name: 'DashboardExact', name: 'DashboardExact',
components: { components: {
MonitorCard MonitorCard,
HeaderCustom
}, },
data() { data() {
return { return {
currentTab: '延保', currentTab: '延保',
tabs: ['延保', '权益', '轻改'], tabs: ['延保', '权益', '轻改'],
activeLineStyle: { transform: 'translateX(0px)', width: '52px' },
filters: { region: '', brand: [], regionOps: '', onlineOps: '' }, filters: { region: '', brand: [], regionOps: '', onlineOps: '' },
// 级联选择器配置
cascaderProps: {
value: 'value',
label: 'label',
children: 'children',
expandTrigger: 'hover',
emitPath: true,
checkStrictly: true, // 允许选择任意一级
multiple: true // 启用多选功能(Element UI 2.x 需要在 props 中配置)
},
// 品牌级联选择器数据 // 品牌级联选择器数据
brandOptions: [ brandOptions: [
{ {
...@@ -487,7 +426,6 @@ ...@@ -487,7 +426,6 @@
} }
}, },
mounted() { mounted() {
this.$nextTick(this.updateActiveLinePosition);
// 动态添加滚动样式,只影响当前页面的父容器 // 动态添加滚动样式,只影响当前页面的父容器
this.enablePageScroll(); this.enablePageScroll();
// 初始化日期范围 // 初始化日期范围
...@@ -508,20 +446,22 @@ ...@@ -508,20 +446,22 @@
const selectedCount = this.cardList.filter(card => card.checked).length; const selectedCount = this.cardList.filter(card => card.checked).length;
console.log('当前选中数量:', selectedCount); console.log('当前选中数量:', selectedCount);
}, },
switchTab(tab) { handleTabChange(tab) {
this.currentTab = tab; this.currentTab = tab;
this.$nextTick(this.updateActiveLinePosition); // 可以在这里处理 tab 切换后的业务逻辑
console.log('Tab 切换:', tab);
}, },
updateActiveLinePosition() { handleSearch(filters) {
const currentIndex = this.tabs.indexOf(this.currentTab); // 更新筛选条件
const tabItemRef = this.$refs[`tabItem${currentIndex}`]; this.filters = { ...filters };
if (!tabItemRef?.[0]) return; // 可以在这里处理查询逻辑
console.log('查询条件:', filters);
const { offsetLeft, offsetWidth } = tabItemRef[0]; },
this.activeLineStyle = { handleReset(filters) {
transform: `translateX(${offsetLeft}px)`, // 重置筛选条件
width: `${offsetWidth}px` this.filters = { ...filters };
}; // 可以在这里处理重置逻辑
console.log('重置筛选条件');
}, },
switchTimeRange(type) { switchTimeRange(type) {
this.timeRangeType = type; this.timeRangeType = type;
...@@ -734,106 +674,24 @@ ...@@ -734,106 +674,24 @@
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
// 颜色变量
$primary: #2A58AD; $primary: #2A58AD;
$text-main: #1D2129; $text-main: #1D2129;
$text-sub: #333333; $text-sub: #333333;
$text-sub-2: #666666;
$border: #E5E6EB; $border: #E5E6EB;
$bg-red: #FEF0F0; $bg-gray: #EFF3F6;
$text-red: #F53F3F; $bg-white: #fff;
$bg-orange: #FDF6EC;
$text-orange: #FF7D00;
.dashboard-page { .dashboard-page {
background-color: #f5f7fa; background-color: #f5f7fa;
min-height: 100vh; min-height: 100vh;
padding: 0 19px 20px; padding: 0 19px 20px;
box-sizing: border-box; box-sizing: border-box;
// 确保页面内容可以自然扩展和滚动
height: auto; height: auto;
} }
// ================= 1. 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;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
// 确保 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;}
}
// ================= 2. Toolbar =================
.toolbar-container { .toolbar-container {
background: #fff; background: $bg-white;
height: 56px; height: 56px;
padding: 12px 24px; padding: 12px 24px;
box-sizing: border-box; box-sizing: border-box;
...@@ -851,7 +709,6 @@ ...@@ -851,7 +709,6 @@
align-items: center; align-items: center;
font-size: 14px; font-size: 14px;
color: $text-sub; color: $text-sub;
.icon-text-btn { .icon-text-btn {
cursor: pointer; cursor: pointer;
display: flex; display: flex;
...@@ -868,101 +725,78 @@ ...@@ -868,101 +725,78 @@
object-fit: contain; object-fit: contain;
vertical-align: middle; vertical-align: middle;
} }
&.has-selected { &.has-selected { background-color: $bg-gray; }
background-color: #EFF3F6;
}
} }
.v-divider { margin: 0 20px; color: $border; } .v-divider { margin: 0 20px; color: $border; }
.time-control-group { .time-control-group {
margin: 0 16px 0 24px; margin: 0 16px 0 24px;
background: #EFF3F6; background: $bg-gray;
border-radius: 4px; border-radius: 4px;
.radio-group { .radio-group {
display: flex; display: flex;
gap: 8px; gap: 8px;
.radio-item { .radio-item {
padding: 5px 16px; padding: 5px 16px;
font-size: 13px; font-size: 13px;
cursor: pointer; cursor: pointer;
background: #EFF3F6; background: $bg-gray;
color: $text-sub; color: $text-sub;
border-radius: 4px; border-radius: 4px;
transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
will-change: background-color, color; will-change: background-color, color;
&.active { background: $primary; color: $bg-white; }
&.active {
background: #2A58AD;
color: #FFFFFF;
}
} }
} }
} }
.date-nav { .date-nav {
display: flex; display: flex;
align-items: center; align-items: center;
.btn-arrow { .btn-arrow {
cursor: pointer; cursor: pointer;
padding: 4px; padding: 4px;
transition: all 0.3s; transition: all 0.3s;
&:hover:not(.disabled) { color: $primary; } &:hover:not(.disabled) { color: $primary; }
&.disabled { &.disabled { cursor: not-allowed; color: #C9CDD4; opacity: 0.5; }
cursor: not-allowed;
color: #C9CDD4;
opacity: 0.5;
}
} }
.date-text { margin: 0 10px; font-weight: 500; color: $text-main; } .date-text { margin: 0 10px; font-weight: 500; color: $text-main; }
} }
} }
.tool-right { .tool-right {
.btn-blue { background: $primary; border-color: $primary;border-radius: 4px; &:hover { opacity: 0.9; }} .btn-blue, .btn-plain-blue {
.btn-plain-blue { background: $primary;
background: $primary;
border-color: $primary; border-color: $primary;
border-radius: 4px; border-radius: 4px;
&:hover { background: $primary; color: #fff; border-color: $primary; opacity: 0.9;} &:hover { opacity: 0.9; }
} }
.btn-plain-blue:hover { background: $primary; color: $bg-white; border-color: $primary; }
} }
// ================= 3. Card ================= .content-area {
.content-area { background-color: $bg-white;
background-color: #fff;
padding: 16px 20px; padding: 16px 20px;
// 确保内容区域可以正常扩展
min-height: 0; min-height: 0;
} }
.col-item { .col-item {
margin-bottom: 16px; margin-bottom: 16px;
// 确保卡片之间的左右间距为 16px padding: 0 8px;
padding-left: 8px;
padding-right: 8px;
} }
// ================= 4. Pagination =================
.footer-bar { .footer-bar {
display: flex; display: flex;
align-items: center; align-items: center;
font-size: 13px; font-size: 13px;
color: $text-sub; color: $text-sub;
background-color: #ffffff; background-color: $bg-white;
height: 68px; height: 68px;
padding: 0 20px; padding: 0 20px;
.total { margin-right: 16px; font-size: 14px; color: #606266;} .total { margin-right: 16px; font-size: 14px; color: #606266; }
.jump-slot { .jump-slot {
margin-left: 12px; margin-left: 12px;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
.mini-select { width: 55px; margin: 0 4px; } .mini-select { width: 55px; margin: 0 4px; }
.sep { margin: 0 6px; } .sep { margin: 0 6px; }
.jump-input { .jump-input {
width: 32px; width: 32px;
height: 24px; height: 24px;
...@@ -972,12 +806,12 @@ ...@@ -972,12 +806,12 @@
text-align: center; text-align: center;
outline: none; outline: none;
color: $text-main; color: $text-main;
&:hover { border-color: #C9CDD4; }
&:focus { border-color: $primary; } &:focus { border-color: $primary; }
} }
} }
} }
// 覆盖 Element UI 样式
::v-deep { ::v-deep {
.el-input__inner { .el-input__inner {
border-radius: 2px; border-radius: 2px;
...@@ -986,52 +820,41 @@ ...@@ -986,52 +820,41 @@
&:hover { border-color: #C9CDD4; } &:hover { border-color: #C9CDD4; }
&:focus { border-color: $primary; } &:focus { border-color: $primary; }
} }
.el-button--small { border-radius: 2px; } .el-button--small { border-radius: 2px; }
.el-pagination.is-background { .el-pagination.is-background {
.el-pager li { .el-pager li, .btn-prev, .btn-next {
border-radius: 2px; border-radius: 2px;
border: 1px solid $border; border: 1px solid $border;
background-color: #fff; background-color: $bg-white;
}
.el-pager li {
color: $text-sub; color: $text-sub;
&:not(.disabled).active { background-color: $primary; border-color: $primary; color: #fff; } &:not(.disabled).active { background-color: $primary; border-color: $primary; color: $bg-white; }
} }
.btn-prev, .btn-next { border-radius: 2px; background-color: #fff; border: 1px solid $border; }
} }
} }
</style> </style>
<style> <style>
/* 全局样式 - 仅影响本页面的弹窗和提示框 */
.pure-popover { .pure-popover {
padding: 4px 0 !important; padding: 4px 0 !important;
border-color: #E5E6EB !important; border-color: #E5E6EB !important;
box-shadow: 0 4px 10px rgba(0,0,0,0.1) !important; box-shadow: 0 4px 10px rgba(0,0,0,0.1) !important;
} }
.popover-list {
.popover-list { list-style: none;
list-style: none; margin: 0;
margin: 0; padding: 0;
padding: 0; li {
} padding: 9px 16px;
cursor: pointer;
.popover-list li { color: #333333;
padding: 9px 16px; font-size: 12px;
cursor: pointer; display: flex;
color: #333333; align-items: center;
font-size: 12px; &:hover { background-color: #F2F3F5; color: #3266E3; }
display: flex; i { margin-right: 8px; font-size: 14px; }
align-items: center; .icon-img { width: 18px; height: 18px; border-radius: 3px; margin-right: 8px; }
} }
.popover-list li:hover { background-color: #F2F3F5; color: #3266E3; }
.popover-list li i { margin-right: 8px; font-size: 14px; }
.popover-list li .icon-img {
width: 18px;
height: 18px;
border-radius: 3px;
margin-right: 8px;
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!