|
|
|
|
@ -1,24 +1,29 @@
|
|
|
|
|
<template>
|
|
|
|
|
<view class="custom-tabbar" :style="{ paddingBottom: safeAreaBottom + 'px' }">
|
|
|
|
|
<view class="tabbar-inner">
|
|
|
|
|
<view
|
|
|
|
|
<up-tabbar
|
|
|
|
|
:value="activeIndex"
|
|
|
|
|
:activeColor="activeColor"
|
|
|
|
|
:inactiveColor="inactiveColor"
|
|
|
|
|
:safeAreaInsetBottom="true"
|
|
|
|
|
:fixed="true"
|
|
|
|
|
:placeholder="true"
|
|
|
|
|
:border="false"
|
|
|
|
|
@change="handleChange"
|
|
|
|
|
zIndex="100"
|
|
|
|
|
>
|
|
|
|
|
<up-tabbar-item
|
|
|
|
|
v-for="(item, index) in tabList"
|
|
|
|
|
:key="index"
|
|
|
|
|
class="tabbar-item"
|
|
|
|
|
:class="{ active: activeIndex === index }"
|
|
|
|
|
@click="handleTabClick(item, index)"
|
|
|
|
|
:text="item.text"
|
|
|
|
|
:name="index"
|
|
|
|
|
>
|
|
|
|
|
<image
|
|
|
|
|
:src="activeIndex === index ? item.selectedIcon : item.icon"
|
|
|
|
|
class="tabbar-icon"
|
|
|
|
|
mode="widthFix"
|
|
|
|
|
/>
|
|
|
|
|
<text class="tabbar-text" :style="{ color: activeIndex === index ? activeColor : color }">
|
|
|
|
|
{{ item.text }}
|
|
|
|
|
</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<template #active-icon>
|
|
|
|
|
<image :src="item.selectedIcon" class="tabbar-icon" mode="widthFix" />
|
|
|
|
|
</template>
|
|
|
|
|
<template #inactive-icon>
|
|
|
|
|
<image :src="item.icon" class="tabbar-icon" mode="widthFix" />
|
|
|
|
|
</template>
|
|
|
|
|
</up-tabbar-item>
|
|
|
|
|
</up-tabbar>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
@ -32,7 +37,7 @@ const { t } = useI18n()
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
const { menus } = storeToRefs(userStore)
|
|
|
|
|
|
|
|
|
|
const color = '#666666'
|
|
|
|
|
const inactiveColor = '#666666'
|
|
|
|
|
const activeColor = '#1a3a5c'
|
|
|
|
|
|
|
|
|
|
const activeIndex = ref(0)
|
|
|
|
|
@ -93,29 +98,20 @@ const tabList = computed(() => {
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const systemInfo = uni.getSystemInfoSync()
|
|
|
|
|
const safeAreaBottom = computed(() => {
|
|
|
|
|
const model = (systemInfo.model || '').toLowerCase()
|
|
|
|
|
const hasNotch = model.includes('iphone x') || model.includes('iphone 1') || (systemInfo.safeAreaInsets && systemInfo.safeAreaInsets.bottom > 20)
|
|
|
|
|
return hasNotch ? 0 : 0
|
|
|
|
|
})
|
|
|
|
|
const safeAreaInsetBottom = ref(0)
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
activeIndex.value = getCurrentActiveIndex()
|
|
|
|
|
const insets = systemInfo.safeAreaInsets
|
|
|
|
|
if (insets && insets.bottom > 0) {
|
|
|
|
|
safeAreaInsetBottom.value = insets.bottom
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function handleTabClick(item, index) {
|
|
|
|
|
function handleChange(index) {
|
|
|
|
|
if (activeIndex.value === index) return
|
|
|
|
|
activeIndex.value = index
|
|
|
|
|
const item = tabList.value[index]
|
|
|
|
|
if (item) {
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
url: item.path
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(() => useUserStore().menus, () => {
|
|
|
|
|
activeIndex.value = getCurrentActiveIndex()
|
|
|
|
|
@ -123,43 +119,8 @@ watch(() => useUserStore().menus, () => {
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.custom-tabbar {
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
z-index: 10;
|
|
|
|
|
background-color: #ffffff;
|
|
|
|
|
box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.06);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabbar-inner {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabbar-item {
|
|
|
|
|
flex: 1;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
|
opacity: 0.7;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabbar-icon {
|
|
|
|
|
width: 48rpx;
|
|
|
|
|
height: 48rpx;
|
|
|
|
|
margin-bottom: 4rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabbar-text {
|
|
|
|
|
font-size: 20rpx;
|
|
|
|
|
line-height: 1.2;
|
|
|
|
|
}
|
|
|
|
|
</style>
|