262 行
6.1 KiB
Vue
262 行
6.1 KiB
Vue
<template>
|
||
<view class="yjyf-master-tabbar-container">
|
||
<view class="tabbar">
|
||
<!-- 1. 大厅 -->
|
||
<view class="tab" :class="{ on: activeIndex === 0 }" @tap="switchTab(0)">
|
||
<view class="icon-wrap">
|
||
<view class="icon-stage">
|
||
<image class="tab-icon" :class="{ faded: activeIndex === 0 }" src="/static/tabbar/master/hall-store.svg" mode="aspectFit" />
|
||
<image class="tab-icon tab-icon-active" :class="{ visible: activeIndex === 0 }" src="/static/tabbar/master/hall-store-active.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<text class="tab-txt">大厅</text>
|
||
</view>
|
||
|
||
<!-- 2. 订单 -->
|
||
<view class="tab" :class="{ on: activeIndex === 1 }" @tap="switchTab(1)">
|
||
<view class="icon-wrap">
|
||
<view class="icon-stage">
|
||
<image class="tab-icon" :class="{ faded: activeIndex === 1 }" src="/static/tabbar/master/orders.svg" mode="aspectFit" />
|
||
<image class="tab-icon tab-icon-active" :class="{ visible: activeIndex === 1 }" src="/static/tabbar/master/orders-active.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<text class="tab-txt">订单</text>
|
||
</view>
|
||
|
||
<!-- 3. 消息 -->
|
||
<view class="tab" :class="{ on: activeIndex === 2 }" @tap="switchTab(2)">
|
||
<view class="icon-wrap">
|
||
<view class="icon-box">
|
||
<view class="icon-stage">
|
||
<image class="tab-icon" :class="{ faded: activeIndex === 2 }" src="/static/tabbar/master/msg.svg" mode="aspectFit" />
|
||
<image class="tab-icon tab-icon-active" :class="{ visible: activeIndex === 2 }" src="/static/tabbar/master/msg-active.svg" mode="aspectFit" />
|
||
</view>
|
||
<view class="unread-badge" v-if="unreadCount > 0">
|
||
<text class="unread-txt">{{ unreadCount > 99 ? '99+' : unreadCount }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<text class="tab-txt">消息</text>
|
||
</view>
|
||
|
||
<!-- 4. 我的 -->
|
||
<view class="tab" :class="{ on: activeIndex === 3 }" @tap="switchTab(3)">
|
||
<view class="icon-wrap">
|
||
<view class="icon-stage">
|
||
<image class="tab-icon" :class="{ faded: activeIndex === 3 }" src="/static/tabbar/master/work.svg" mode="aspectFit" />
|
||
<image class="tab-icon tab-icon-active" :class="{ visible: activeIndex === 3 }" src="/static/tabbar/master/work-active.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<text class="tab-txt">我的</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 底部防遮挡垫高占位 -->
|
||
<view class="tabbar-placeholder"></view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, watch, onMounted, onBeforeUnmount } from 'vue';
|
||
import api from '@/utils/api.js';
|
||
import { isLogin } from '@/utils/request.js';
|
||
|
||
const props = defineProps({
|
||
current: {
|
||
type: Number,
|
||
default: 0
|
||
},
|
||
// false:单母页组件切换模式,0ms 极速秒切不销毁组件
|
||
standalone: {
|
||
type: Boolean,
|
||
default: false
|
||
}
|
||
});
|
||
|
||
const emit = defineEmits(['change']);
|
||
|
||
const activeIndex = ref(props.current);
|
||
const unreadCount = ref(0);
|
||
|
||
async function fetchUnread() {
|
||
if (!isLogin()) {
|
||
unreadCount.value = 0;
|
||
return;
|
||
}
|
||
try {
|
||
const res = await api.messageUnread({ type: 'master' });
|
||
unreadCount.value = Number(res?.unread || 0);
|
||
} catch (e) {}
|
||
}
|
||
|
||
watch(() => props.current, (val) => {
|
||
activeIndex.value = val;
|
||
});
|
||
|
||
onMounted(() => {
|
||
fetchUnread();
|
||
uni.$on('yjyf:refreshUnread', fetchUnread);
|
||
});
|
||
|
||
onBeforeUnmount(() => {
|
||
uni.$off('yjyf:refreshUnread', fetchUnread);
|
||
});
|
||
|
||
const TAB_ROUTES = [
|
||
'/pages/master/hall',
|
||
'/pages/master/hall?tab=1',
|
||
'/pages/master/hall?tab=2',
|
||
'/pages/master/hall?tab=3'
|
||
];
|
||
|
||
function switchTab(index) {
|
||
if (activeIndex.value === index) return;
|
||
|
||
// 单母页内仅触发切换事件,由父容器掌控登录校验与激活态,避免无效先亮后退
|
||
if (!props.standalone) {
|
||
emit('change', index);
|
||
return;
|
||
}
|
||
|
||
activeIndex.value = index;
|
||
emit('change', index);
|
||
|
||
const targetUrl = TAB_ROUTES[index];
|
||
if (targetUrl) {
|
||
uni.reLaunch({ url: targetUrl });
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
/* #ifdef MP-WEIXIN */
|
||
:host {
|
||
display: block;
|
||
width: 100%;
|
||
flex-shrink: 0;
|
||
}
|
||
/* #endif */
|
||
|
||
.yjyf-master-tabbar-container {
|
||
position: relative;
|
||
z-index: 99;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.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: 6rpx;
|
||
}
|
||
|
||
.icon-wrap {
|
||
width: 72rpx;
|
||
height: 50rpx;
|
||
border-radius: 25rpx;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
transition: background-color 0.18s ease, transform 0.15s ease;
|
||
}
|
||
|
||
.tab.on .icon-wrap {
|
||
background: #FFF7F0;
|
||
}
|
||
|
||
.tab:active .icon-wrap {
|
||
transform: scale(0.92);
|
||
}
|
||
|
||
.icon-box {
|
||
position: relative;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
.icon-stage {
|
||
position: relative;
|
||
width: 44rpx;
|
||
height: 44rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
.unread-badge {
|
||
position: absolute;
|
||
top: -8rpx;
|
||
right: -20rpx;
|
||
min-width: 32rpx;
|
||
height: 32rpx;
|
||
padding: 0 8rpx;
|
||
border-radius: 16rpx;
|
||
background: #E8331B;
|
||
border: 2rpx solid #FFFFFF;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
z-index: 2;
|
||
}
|
||
.unread-txt {
|
||
font-size: 22rpx;
|
||
color: #FFFFFF;
|
||
font-weight: 700;
|
||
line-height: 1;
|
||
transform: scale(0.85);
|
||
}
|
||
.tab-icon {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
width: 44rpx;
|
||
height: 44rpx;
|
||
opacity: 1;
|
||
}
|
||
.tab-icon.faded {
|
||
opacity: 0;
|
||
}
|
||
.tab-icon-active {
|
||
opacity: 0;
|
||
}
|
||
.tab-icon-active.visible {
|
||
opacity: 1;
|
||
}
|
||
|
||
.tab-txt {
|
||
margin-top: 4rpx;
|
||
font-size: 22rpx;
|
||
line-height: 1.2;
|
||
color: #9A9A9A;
|
||
transition: color 0.15s ease;
|
||
}
|
||
|
||
.tab.on .tab-txt {
|
||
color: #F0710D;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.tabbar-placeholder {
|
||
height: 112rpx;
|
||
padding-bottom: constant(safe-area-inset-bottom);
|
||
padding-bottom: env(safe-area-inset-bottom);
|
||
box-sizing: content-box !important;
|
||
}
|
||
</style>
|