refactor:更换uview-plus tabbar组件

master
黄伟杰 3 days ago
parent bdd15e5104
commit 1846e783a3

@ -51,7 +51,7 @@ function handleClick(btn, index) {
background: #ffffff; background: #ffffff;
box-shadow: 0 -6rpx 24rpx rgba(0, 0, 0, 0.08); box-shadow: 0 -6rpx 24rpx rgba(0, 0, 0, 0.08);
padding: 20rpx 24rpx calc(20rpx + env(safe-area-inset-bottom)); padding: 20rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
z-index: 99; z-index: 90;
} }
.action-row { .action-row {

@ -1,24 +1,29 @@
<template> <template>
<view class="custom-tabbar" :style="{ paddingBottom: safeAreaBottom + 'px' }"> <up-tabbar
<view class="tabbar-inner"> :value="activeIndex"
<view :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" v-for="(item, index) in tabList"
:key="index" :key="index"
class="tabbar-item" :text="item.text"
:class="{ active: activeIndex === index }" :name="index"
@click="handleTabClick(item, index)"
> >
<image <template #active-icon>
:src="activeIndex === index ? item.selectedIcon : item.icon" <image :src="item.selectedIcon" class="tabbar-icon" mode="widthFix" />
class="tabbar-icon" </template>
mode="widthFix" <template #inactive-icon>
/> <image :src="item.icon" class="tabbar-icon" mode="widthFix" />
<text class="tabbar-text" :style="{ color: activeIndex === index ? activeColor : color }"> </template>
{{ item.text }} </up-tabbar-item>
</text> </up-tabbar>
</view>
</view>
</view>
</template> </template>
<script setup> <script setup>
@ -32,7 +37,7 @@ const { t } = useI18n()
const userStore = useUserStore() const userStore = useUserStore()
const { menus } = storeToRefs(userStore) const { menus } = storeToRefs(userStore)
const color = '#666666' const inactiveColor = '#666666'
const activeColor = '#1a3a5c' const activeColor = '#1a3a5c'
const activeIndex = ref(0) const activeIndex = ref(0)
@ -93,28 +98,19 @@ 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(() => { onMounted(() => {
activeIndex.value = getCurrentActiveIndex() 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 if (activeIndex.value === index) return
activeIndex.value = index activeIndex.value = index
const item = tabList.value[index]
if (item) {
uni.reLaunch({ uni.reLaunch({
url: item.path url: item.path
}) })
}
} }
watch(() => useUserStore().menus, () => { watch(() => useUserStore().menus, () => {
@ -123,43 +119,8 @@ watch(() => useUserStore().menus, () => {
</script> </script>
<style lang="scss" scoped> <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 { .tabbar-icon {
width: 48rpx; width: 48rpx;
height: 48rpx; height: 48rpx;
margin-bottom: 4rpx;
}
.tabbar-text {
font-size: 20rpx;
line-height: 1.2;
} }
</style> </style>

@ -188,7 +188,7 @@ defineExpose({ loadTodoList })
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 100; z-index: 10;
} }
.bell-icon { .bell-icon {

@ -14,8 +14,10 @@
<view class="nav-grid"> <view class="nav-grid">
<view v-for="item in configuredMenuList" :key="item.id" class="nav-item is-selected"> <view v-for="item in configuredMenuList" :key="item.id" class="nav-item is-selected">
<view class="nav-icon" :style="{ background: '#e1e6eb' }"> <view class="nav-icon" :style="{ background: '#e1e6eb' }">
<uni-icons v-if="isUniIcon(item.icon)" :type="getUniIconName(item.icon)" size="28" :color="item.accentColor" /> <uni-icons v-if="isUniIcon(item.icon)" :type="getUniIconName(item.icon)" size="28"
<u-icon v-else-if="isUviewIcon(item.icon)" :name="getUviewIconName(item.icon)" size="28" :color="item.accentColor"></u-icon> :color="item.accentColor" />
<u-icon v-else-if="isUviewIcon(item.icon)" :name="getUviewIconName(item.icon)" size="28"
:color="item.accentColor"></u-icon>
<text v-else class="nav-icon-text">{{ item.symbol }}</text> <text v-else class="nav-icon-text">{{ item.symbol }}</text>
</view> </view>
<text class="nav-text">{{ item.displayName }}</text> <text class="nav-text">{{ item.displayName }}</text>
@ -34,8 +36,10 @@
<view v-for="item in unconfiguredMenuList" :key="item.id" class="nav-item" <view v-for="item in unconfiguredMenuList" :key="item.id" class="nav-item"
@click="handleUnconfiguredClick(item)"> @click="handleUnconfiguredClick(item)">
<view class="nav-icon nav-icon-disabled" :style="{ background: '#e1e6eb' }"> <view class="nav-icon nav-icon-disabled" :style="{ background: '#e1e6eb' }">
<uni-icons v-if="isUniIcon(item.icon)" :type="getUniIconName(item.icon)" size="28" :color="item.accentColor" /> <uni-icons v-if="isUniIcon(item.icon)" :type="getUniIconName(item.icon)" size="28"
<u-icon v-else-if="isUviewIcon(item.icon)" :name="getUviewIconName(item.icon)" size="28" :color="item.accentColor"></u-icon> :color="item.accentColor" />
<u-icon v-else-if="isUviewIcon(item.icon)" :name="getUviewIconName(item.icon)" size="28"
:color="item.accentColor"></u-icon>
<text v-else class="nav-icon-text">{{ item.symbol }}</text> <text v-else class="nav-icon-text">{{ item.symbol }}</text>
</view> </view>
<text class="nav-text nav-text-disabled">{{ item.displayName }}</text> <text class="nav-text nav-text-disabled">{{ item.displayName }}</text>
@ -208,7 +212,7 @@ watch(() => props.visible, async (val) => {
z-index: 1000; z-index: 1000;
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
padding-bottom: calc(100rpx + env(safe-area-inset-bottom)); padding-bottom: calc(90rpx + env(safe-area-inset-bottom));
box-sizing: border-box; box-sizing: border-box;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;

@ -125,7 +125,7 @@ function handleClose() {
z-index: 1000; z-index: 1000;
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
padding-bottom: calc(100rpx + env(safe-area-inset-bottom)); padding-bottom: calc(90rpx + env(safe-area-inset-bottom));
box-sizing: border-box; box-sizing: border-box;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;

@ -73,7 +73,7 @@ function goTop() {
padding: 0 24rpx 24rpx; padding: 0 24rpx 24rpx;
margin-top: -40rpx; margin-top: -40rpx;
position: relative; position: relative;
z-index: 5; z-index: 1;
} }
.go-top-btn { .go-top-btn {
@ -88,7 +88,7 @@ function goTop() {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(26, 58, 92, 0.3); box-shadow: 0 8rpx 24rpx rgba(26, 58, 92, 0.3);
z-index: 10; z-index: 50;
&:active { &:active {
transform: scale(0.95); transform: scale(0.95);

Loading…
Cancel
Save