dl_uniapp/components/tabbar/tabBar.vue
2025-03-31 14:31:41 +08:00

159 lines
3.1 KiB
Vue

<template>
<view class="tabbar-container">
<!-- :style="['width: calc(100% /' + tabbar.length + ')']" -->
<view class="tabbar-item" :class="[item.centerItem ? ' center-item' : '']" v-for="(item, i) in tabbar" :key="i"
@click="goPage(item)">
<view class="item-top">
<view style="position: relative;width: 45rpx;margin: auto;">
<image class="dl-image" :src="currPage === item.id ? item.selectedIconPath : item.iconPath" />
<image v-if="1==i" class="dl-vip" src="@/static/index/vip.png" mode="aspectFit"></image>
</view>
</view>
<view class="item-bottom" :class="[currPage === item.id ? 'item-active' : '']">{{ item.text }}</view>
</view>
</view>
</template>
<script>
export default {
props: {
currPage: {
Type: 'int',
default: 0
}
},
data() {
return {
tabbar: [{
id: 0,
code: "home",
text: "首页",
iconPath: '/static/images/tabbar/home.png',
selectedIconPath: '/static/images/tabbar/home_.png',
centerItem: false
},
{
id: 1,
code: "dingyue",
text: "订阅",
iconPath: '/static/images/tabbar/dingyue.png',
selectedIconPath: '/static/images/tabbar/dingyue_.png',
centerItem: false
},
{
id: 2,
code: "myNotice",
text: "我的通告",
iconPath: '/static/images/tabbar/my_notice.png',
selectedIconPath: '/static/images/tabbar/my_notice_.png',
centerItem: false
},
{
id: 3,
code: "my",
text: "我的",
iconPath: '/static/images/tabbar/my.png',
selectedIconPath: '/static/images/tabbar/my_.png',
centerItem: false
}
]
}
},
onLoad() {
},
onUnload() {
},
methods: {
/**
* 页面跳转
* @param {Object} item
*/
goPage(item) {
this.currPage = item.id
this.$emit("changeMenu", item.code)
}
}
}
</script>
<style scoped lang="scss">
$textDefaultColor: #9B9B9B; // 文字默认颜色
$textSelectedColor: #FC1F3E; // 文字选中颜色
$centerItemBg: #fff; // 中间凸起按钮背景
.tabbar-container {
bottom: 0;
position: fixed;
left: 0;
display: flex;
width: 100%;
height: 125rpx;
color: $textDefaultColor;
background-color: #F7F7F7;
background-size: 100% 100%;
}
.tabbar-item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
width: 150rpx;
height: 120rpx;
flex-grow: 1;
position: relative;
.item-top {
padding-top: 25rpx;
flex-shrink: 0;
width: 150rpx;
height: 130rpx;
.dl-image {
width: 70rpx;
height: 55rpx;
}
.dl-vip {
position: absolute;
height: 25rpx;
top: -10rpx;
right: -24px;
}
}
.item-bottom {
width: 100%;
font-size: 28rpx;
position: absolute;
bottom: 10rpx;
}
.item-active {
color: $textSelectedColor;
}
}
.center-item {
position: relative;
.item-top {
position: absolute;
top: -55rpx;
left: 50%;
transform: translateX(-50%);
width: 105rpx;
height: 105rpx;
background-color: $centerItemBg;
border-radius: 50%;
}
.item-bottom {
position: absolute;
bottom: 5rpx;
}
}
</style>