2026-03-24 11:45:13 +08:00
|
|
|
<template>
|
|
|
|
|
<uv-tabbar fixed :value="selected" @change="change1" activeColor="#ee0a24" :placeholder="false"
|
|
|
|
|
:safeAreaInsetBottom="false" :customStyle="{height:`110rpx`}">
|
2026-03-25 13:34:16 +08:00
|
|
|
<uv-tabbar-item v-for="(item,index) in $store.state.tabbarList" :key="index" :badge="getNum(index)"
|
|
|
|
|
:customStyle="{height:`110rpx`}">
|
2026-03-24 11:45:13 +08:00
|
|
|
<template v-slot:active-icon>
|
|
|
|
|
<image class="icon" :src="item.selectedIconPath"></image>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:inactive-icon>
|
|
|
|
|
<image class="icon" :src="item.iconPath"></image>
|
|
|
|
|
</template>
|
|
|
|
|
</uv-tabbar-item>
|
|
|
|
|
</uv-tabbar>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import request from "@/utils/request";
|
|
|
|
|
export default {
|
|
|
|
|
name: "tab-bar",
|
|
|
|
|
props: {
|
|
|
|
|
selected: {
|
|
|
|
|
type: [Number, String]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tabbarList: [{
|
|
|
|
|
"iconPath": "/static/images/tabbar/new_home_gray.png",
|
|
|
|
|
"text": "首页",
|
|
|
|
|
"selectedIconPath": "/static/images/tabbar/new_home.png",
|
|
|
|
|
"pagePath": "/pages/home/home"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-03-25 13:34:16 +08:00
|
|
|
"iconPath": "/static/images/tabbar/new_message_gray.png",
|
|
|
|
|
"text": "消息",
|
|
|
|
|
"selectedIconPath": "/static/images/tabbar/new_message.png",
|
|
|
|
|
"pagePath": "/pages/message/message"
|
2026-03-24 11:45:13 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"iconPath": "/static/images/tabbar/new_my_gray.png",
|
|
|
|
|
"text": "我的",
|
|
|
|
|
"selectedIconPath": "/static/images/tabbar/new_my.png",
|
|
|
|
|
"pagePath": "/pages/my/my"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
},
|
2026-03-25 13:34:16 +08:00
|
|
|
computed: {
|
|
|
|
|
messageNum() {
|
|
|
|
|
return this.$store.state.messageNum || 0
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-03-24 11:45:13 +08:00
|
|
|
async created() {
|
|
|
|
|
if (!this.$store.state.tabbarList.length) {
|
|
|
|
|
let isnNetwork = uni.getStorageSync("isnNetwork");
|
|
|
|
|
if (isnNetwork) {
|
|
|
|
|
await this.getButtonImg()
|
|
|
|
|
} else {
|
|
|
|
|
uni.getNetworkType({
|
2026-03-25 13:34:16 +08:00
|
|
|
success: (res) => {
|
2026-03-24 11:45:13 +08:00
|
|
|
console.log(res.networkType);
|
|
|
|
|
if (res.networkType == "none") {
|
2026-03-25 13:34:16 +08:00
|
|
|
|
2026-03-24 11:45:13 +08:00
|
|
|
this.$store.commit("setTabbarList", this.tabbarList)
|
|
|
|
|
} else {
|
|
|
|
|
// 页面加载逻辑
|
|
|
|
|
uni.setStorageSync("isnNetwork", 1);
|
|
|
|
|
this.getButtonImg()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-25 13:34:16 +08:00
|
|
|
|
2026-03-24 11:45:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2026-03-25 13:34:16 +08:00
|
|
|
getNum(index) {
|
|
|
|
|
if (index == 1) {
|
|
|
|
|
return this.messageNum
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-03-24 11:45:13 +08:00
|
|
|
//获取头部背景图片
|
|
|
|
|
async getButtonImg() {
|
2026-03-25 13:34:16 +08:00
|
|
|
let res = await request.post("/sj/poster/getButtonImg", {});
|
2026-03-24 11:45:13 +08:00
|
|
|
if (res.code == 200) {
|
|
|
|
|
// if (res.data?.photo) {
|
|
|
|
|
// this.topBgImage = res.data?.photo + '?time=666'
|
|
|
|
|
// }
|
|
|
|
|
this.tabbarList.forEach((item, index) => {
|
|
|
|
|
if (res.data[index].iconPath) {
|
|
|
|
|
item.iconPath = res.data[index].iconPath
|
|
|
|
|
}
|
|
|
|
|
if (res.data[index].selectedIconPath) {
|
|
|
|
|
item.selectedIconPath = res.data[index].selectedIconPath
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.$store.commit("setTabbarList", this.tabbarList)
|
|
|
|
|
},
|
|
|
|
|
change1(val) {
|
|
|
|
|
// 因为在pages中配置了需要跳转的页面为 tabbar页面
|
|
|
|
|
// 所以不能使用navigateTo 只能使用下面这个方法跳转。
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
url: this.tabbarList[val].pagePath
|
|
|
|
|
})
|
2026-03-25 13:34:16 +08:00
|
|
|
this.messageUpudateNum()
|
2026-03-24 11:45:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.icon {
|
|
|
|
|
height: 98rpx;
|
|
|
|
|
width: 98rpx;
|
|
|
|
|
}
|
2026-03-25 13:34:16 +08:00
|
|
|
::v-deep .uv-tabbar__content{
|
|
|
|
|
z-index: 999!important;
|
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
</style>
|