feat: 使用自定义tabBar组件,emoji图标显示

- 创建custom-tabbar组件
- 使用emoji图标:首页🏠、记录📋、工具🔧、我的👤
- 在各tabBar页面添加自定义tabBar组件
- pages.json启用custom: true
This commit is contained in:
H1d3rOne committed 2026-03-07 21:06:01 +08:00
1 parent 76e33379c7
commit af1ef3ab8e
6 files changed
+139 -12

No files matched your search

@@ -0,0 +1,120 @@
<template>
<view class="custom-tabbar">
<view
v-for="(item, index) in tabList"
:key="index"
class="tabbar-item"
:class="{ active: currentIndex === index }"
@click="switchTab(index)"
>
<view class="tabbar-icon">
<text class="icon-emoji">{{ item.icon }}</text>
</view>
<text class="tabbar-text">{{ item.text }}</text>
</view>
</view>
</template>
<script>
export default {
name: 'CustomTabbar',
props: {
current: {
type: Number,
default: 0
}
},
data() {
return {
currentIndex: 0,
tabList: [
{
text: '首页',
icon: '🏠',
pagePath: '/pages/index/index'
},
{
text: '记录',
icon: '📋',
pagePath: '/pages/records/records'
},
{
text: '工具',
icon: '🔧',
pagePath: '/pages/tools/tools'
},
{
text: '我的',
icon: '👤',
pagePath: '/pages/mine/mine'
}
]
}
},
watch: {
current: {
immediate: true,
handler(val) {
this.currentIndex = val
}
}
},
methods: {
switchTab(index) {
if (this.currentIndex === index) return
this.currentIndex = index
const path = this.tabList[index].pagePath
uni.switchTab({
url: path
})
}
}
}
</script>
<style scoped>
.custom-tabbar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100rpx;
background: #ffffff;
display: flex;
align-items: center;
justify-content: space-around;
border-top: 1rpx solid #f0f0f0;
box-shadow: 0 -2rpx 20rpx rgba(0, 0, 0, 0.05);
z-index: 9999;
padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 8rpx 0;
}
.tabbar-icon {
margin-bottom: 4rpx;
}
.icon-emoji {
font-size: 44rpx;
line-height: 1;
}
.tabbar-text {
font-size: 20rpx;
color: #999999;
transition: color 0.3s;
}
.tabbar-item.active .tabbar-text {
color: #DB2777;
font-weight: 500;
}
</style>
+11 -12
View File
@@ -168,6 +168,7 @@
"navigationBarTitleText": "玄机排盘"
},
"tabBar": {
"custom": true,
"color": "#999999",
"selectedColor": "#DB2777",
"backgroundColor": "#ffffff",
@@ -175,28 +176,26 @@
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "static/tabbar/home.png",
"selectedIconPath": "static/tabbar/home-active.png"
"text": "首页"
},
{
"pagePath": "pages/records/records",
"text": "记录",
"iconPath": "static/tabbar/record.png",
"selectedIconPath": "static/tabbar/record-active.png"
"text": "记录"
},
{
"pagePath": "pages/tools/tools",
"text": "工具",
"iconPath": "static/tabbar/tool.png",
"selectedIconPath": "static/tabbar/tool-active.png"
"text": "工具"
},
{
"pagePath": "pages/mine/mine",
"text": "我的",
"iconPath": "static/tabbar/mine.png",
"selectedIconPath": "static/tabbar/mine-active.png"
"text": "我的"
}
]
},
"easycom": {
"autoscan": true,
"custom": {
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
}
}
}
@@ -153,6 +153,8 @@
<view class="footer">
<view class="footer-divider"></view>
</view>
<custom-tabbar :current="0"></custom-tabbar>
</view>
</template>
@@ -23,6 +23,8 @@
<view class="version">
<text class="version-text">版本 1.0.0</text>
</view>
<custom-tabbar :current="3"></custom-tabbar>
</view>
</template>
@@ -28,6 +28,8 @@
</view>
</view>
</view>
<custom-tabbar :current="1"></custom-tabbar>
</view>
</template>
@@ -22,6 +22,8 @@
</view>
</view>
</view>
<custom-tabbar :current="2"></custom-tabbar>
</view>
</template>