文件
fenleixinxi/uniapp/components/fc-tabbar/fc-tabbar.vue

154 行
3.8 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="fc-tabbar">
<view class="fc-tabbar__nav">
<view
v-for="(item, idx) in tabs"
:key="item.path"
class="fc-tabbar__item"
:class="{ 'fc-tabbar__item--active': current === idx, 'fc-tabbar__item--primary': item.primary }"
@click="switchTo(item, idx)"
>
<view class="fc-tabbar__icon" :class="{ 'fc-tabbar__icon--circle': item.primary }">
<image v-if="item.primary" class="fc-tabbar__plus" :src="iconUrl('plus-ink')" mode="aspectFit" />
<image v-else class="fc-tabbar__img" :src="iconUrl(current === idx ? item.active : item.icon)" mode="aspectFit" />
</view>
<text class="fc-tabbar__text">{{ item.text }}</text>
</view>
</view>
<view class="fc-safe-bottom"></view>
</view>
</template>
<script>
import { iconUrl } from '@/common/store/ui.js'
export default {
name: 'FcTabbar',
options: {
/** 开启虚拟化宿主节点,避免小程序自定义组件样式隔离产生非预期布局 */
virtualHost: true,
},
props: {
/** 当前激活的 Tab 索引(0:首页 1:分类 2:发布 3:通知 4:我的) */
current: { type: Number, default: 0 },
},
data() {
return {
tabs: [
{ text: '首页', icon: 'tab-home', active: 'tab-home-on', path: '/pages/index/index' },
{ text: '分类', icon: 'tab-category', active: 'tab-category-on', path: '/pages/category/index' },
{ text: '发布', icon: 'tab-post', active: 'tab-post-on', path: '/pages/post/create', primary: true },
{ text: '通知', icon: 'tab-message', active: 'tab-message-on', path: '/pages/message/index' },
{ text: '我的', icon: 'tab-mine', active: 'tab-mine-on', path: '/pages/mine/index' },
],
}
},
methods: {
/** 暴露给模板:图标地址由后台配置决定(未配置则用内置图标) */
iconUrl,
/**
* 切换底部导航目标页面
* @param {Object} item 目标 Tab 配置对象
* @param {number} idx 目标 Tab 索引
*/
switchTo(item, idx) {
if (idx === this.current) return
// 🌟 中间突出加号(发布):作为独立模态表单页推入,保留前序页面栈,支持原路返回
if (item.primary) {
uni.navigateTo({ url: item.path })
return
}
// 其余常驻 Tab 页面平滑切换:H5 环境优先 redirectTo 避免 reLaunch 导致的页面整体闪屏
// #ifdef H5
uni.redirectTo({
url: item.path,
fail: () => {
uni.reLaunch({ url: item.path })
},
})
// #endif
// #ifndef H5
uni.reLaunch({ url: item.path })
// #endif
},
},
}
</script>
<style lang="scss" scoped>
.fc-tabbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
background: #ffffff;
border-top: 2rpx solid $fc-border;
box-shadow: 0 -6rpx 24rpx rgba(4, 48, 30, 0.08);
box-sizing: border-box;
}
.fc-tabbar__nav {
display: flex;
align-items: center;
justify-content: space-around;
height: 104rpx;
padding-top: 8rpx;
box-sizing: border-box;
}
.fc-tabbar__item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-bottom: 8rpx;
cursor: pointer;
transition: transform 0.15s ease;
&:active {
transform: scale(0.94);
}
&--active {
.fc-tabbar__text {
color: $fc-primary-text;
font-weight: 600;
}
}
&--primary {
.fc-tabbar__text {
color: $fc-primary-text;
}
}
}
.fc-tabbar__icon {
height: 52rpx;
display: flex;
align-items: center;
justify-content: center;
&--circle {
width: 82rpx;
height: 82rpx;
margin-top: -42rpx;
border-radius: 50%;
background: $fc-gradient-primary;
border: 4rpx solid #ffffff;
box-shadow: 0 8rpx 24rpx rgba(0, 224, 112, 0.45);
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
}
.fc-tabbar__img {
width: 44rpx;
height: 44rpx;
}
.fc-tabbar__plus {
width: 40rpx;
height: 40rpx;
}
.fc-tabbar__text {
font-size: $fc-font-xs;
color: $fc-text-secondary;
margin-top: 4rpx;
}
</style>