Files
yunzerwebsiteallinone/uniapp/components/AppTabbar.vue
T
2026-11-16 17:22:50 +08:00

122 lines
2.2 KiB
Vue

<template>
<view class="app-tabbar">
<view class="tabbar-inner">
<view
v-for="tab in list"
:key="tab.name"
class="tab-item"
:class="{ active: current === tab.name }"
@tap="onTap(tab.name)"
>
<FaIcon
:name="tab.icon"
:color="current === tab.name ? '#2563eb' : '#94a3b8'"
:size="21"
/>
<text class="tab-text">{{ tab.text }}</text>
</view>
</view>
<view class="safe-area" />
</view>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
group: {
type: String,
default: ''
},
current: {
type: String,
default: 'home'
},
variant: {
type: String,
default: 'route'
},
tabs: {
type: Array,
default: null
}
})
const emit = defineEmits(['change'])
const DEFAULT_TABS = [
{ name: 'home', text: '概览', icon: 'gauge' },
{ name: 'functions', text: '功能', icon: 'table-cells' },
{ name: 'todo', text: '待办', icon: 'circle-check' },
{ name: 'mine', text: '回平台', icon: 'arrow-left' }
]
const list = computed(() => (props.tabs && props.tabs.length ? props.tabs : DEFAULT_TABS))
function onTap(name) {
if (name === 'mine' || name === 'platform') {
uni.reLaunch({ url: '/pages/nav/nav' })
return
}
if (name === props.current) return
if (props.variant === 'switch') {
emit('change', name)
return
}
uni.redirectTo({ url: `/pages/${props.group}/${name}/${name}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/theme.scss';
.app-tabbar {
flex-shrink: 0;
background: $color-card;
border-top: 1rpx solid $color-border;
box-shadow: 0 -4rpx 20rpx rgba(31, 43, 72, 0.05);
}
.tabbar-inner {
display: flex;
align-items: center;
justify-content: space-around;
padding: 12rpx 0 8rpx;
}
.tab-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 6rpx;
padding: 6rpx 0;
transition: transform 0.18s ease;
&.active {
.tab-text {
color: $color-primary;
font-weight: 600;
}
:deep(.fa-icon) {
transform: translateY(-2rpx);
}
}
&:active {
transform: scale(0.94);
}
}
.tab-text {
font-size: 22rpx;
line-height: 1.2;
color: $color-text-muted;
}
.safe-area {
height: constant(safe-area-inset-bottom);
height: env(safe-area-inset-bottom);
}
</style>