文件
yjyf/yjyf-app/components/YjyfTabBar.vue
YuanWen 9ae2b976a8 feat: 重构首页与全局UI,新增服务选择抽屉与统一导航组件
新增统一导航栏组件YjyfNavBar,替换各页面原生导航
新增服务选择抽屉组件GoodsPickerDrawer,实现分类选品流程
新增tabbar图标矢量资源,优化底部导航样式
新增后端运力统计接口与多商品下单逻辑
修复页面跳转逻辑,统一使用switchTab/redirectTo
优化订单创建与评价页的UI组件化,提升一致性
2026-11-02 18:27:37 +08:00

186 行
4.2 KiB
Vue

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

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

<template>
<view class="yjyf-tabbar-container">
<view class="tabbar">
<!-- 1. 首页 -->
<view class="tab" :class="{ on: current === 0 }" @tap="switchTab(0)">
<image class="tab-icon" :src="current === 0 ? '/static/tabbar/home-active.svg' : '/static/tabbar/home.svg'" mode="aspectFit" />
<text class="tab-txt">首页</text>
</view>
<!-- 2. 订单 -->
<view class="tab" :class="{ on: current === 1 }" @tap="switchTab(1)">
<image class="tab-icon" :src="current === 1 ? '/static/tabbar/order-active.svg' : '/static/tabbar/order.svg'" mode="aspectFit" />
<text class="tab-txt">订单</text>
</view>
<!-- 3. 中央上浮主按钮:立即下单 -->
<view class="tab tab-center">
<view class="fab" :class="{ active: current === 'order' }" @tap="onOrder">
<image class="fab-icon" src="/static/tabbar/order-quick.svg" mode="aspectFit" />
<text class="fab-txt">立即下单</text>
</view>
</view>
<!-- 4. 消息 -->
<view class="tab" :class="{ on: current === 2 }" @tap="switchTab(2)">
<image class="tab-icon" :src="current === 2 ? '/static/tabbar/message-active.svg' : '/static/tabbar/message.svg'" mode="aspectFit" />
<text class="tab-txt">消息</text>
</view>
<!-- 5. 我的 -->
<view class="tab" :class="{ on: current === 3 }" @tap="switchTab(3)">
<image class="tab-icon" :src="current === 3 ? '/static/tabbar/mine-active.svg' : '/static/tabbar/mine.svg'" mode="aspectFit" />
<text class="tab-txt">我的</text>
</view>
</view>
<!-- 底部防遮挡垫高占位 -->
<view class="tabbar-placeholder"></view>
</view>
</template>
<script setup>
import { isLogin, toLogin } from '@/utils/request.js'
const props = defineProps({
current: {
type: [Number, String],
default: 0
}
})
const TAB_ROUTES = [
'/pages/index/index',
'/pages/order/list',
'/pages/message/message',
'/pages/mine/mine'
]
function needLogin() {
if (isLogin()) return true
toLogin()
return false
}
function onOrder() {
if (props.current === 'order') return
if (!needLogin()) return
uni.navigateTo({ url: '/pages/category/category' })
}
function switchTab(index) {
if (props.current === index) return
if (index > 0 && !needLogin()) return
const targetUrl = TAB_ROUTES[index]
if (targetUrl) {
uni.switchTab({
url: targetUrl,
fail: () => {
uni.redirectTo({ url: targetUrl })
}
})
}
}
</script>
<style scoped>
.yjyf-tabbar-container {
position: relative;
z-index: 99;
}
/* ---------- 自定义底部导航栏 (保持 content-box 避免被 safe-area 挤压高度) ---------- */
.tabbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 99;
box-sizing: content-box !important;
height: 112rpx;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
display: flex;
background: #ffffff;
box-shadow: 0 -6rpx 24rpx rgba(0, 0, 0, 0.07);
}
.tab {
flex: 1;
height: 112rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-bottom: 8rpx;
}
.tab-txt {
margin-top: 8rpx;
font-size: 22rpx;
line-height: 1.2;
color: #9A9A9A;
}
.tab.on .tab-txt {
color: #F0710D;
font-weight: 600;
}
/* 底部图标 */
.tab-icon {
width: 44rpx;
height: 44rpx;
flex-shrink: 0;
}
/* ---------- 中央上浮主按钮 ---------- */
.tab-center {
position: relative;
height: 112rpx;
overflow: visible;
}
.fab {
position: absolute;
left: 50%;
top: -52rpx;
width: 128rpx;
height: 128rpx;
margin-left: -64rpx;
border-radius: 50%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient(180deg, #FFB65E 0%, #EE7412 100%);
box-shadow: 0 10rpx 26rpx rgba(238, 116, 18, 0.45);
}
.fab.active {
box-shadow: 0 10rpx 32rpx rgba(238, 116, 18, 0.65), 0 0 0 6rpx rgba(255, 182, 94, 0.35);
transform: scale(1.03);
}
.fab-icon {
width: 44rpx;
height: 44rpx;
flex-shrink: 0;
}
.fab-txt {
margin-top: 4rpx;
font-size: 22rpx;
line-height: 1.2;
color: #ffffff;
}
/* 底部安全区占位 */
.tabbar-placeholder {
width: 100%;
height: calc(120rpx + constant(safe-area-inset-bottom));
height: calc(120rpx + env(safe-area-inset-bottom));
}
</style>