tabbar bug修复

This commit is contained in:
BAKEYi 2026-05-27 15:45:10 +08:00
parent bbe660cbfc
commit 1d611bee0b
2 changed files with 192 additions and 137 deletions

View File

@ -1,10 +1,24 @@
<template>
<uv-tabbar fixed :value="selected" @change="change1" activeColor="#FF4767 " :placeholder="false"
:safeAreaInsetBottom="false" :customStyle="{height:`110rpx`}">
<!-- <uv-tabbar-item v-for="(item,index) in $store.state.tabbarList" :key="index" :text="item.text" -->
<uv-tabbar-item v-for="(item,index) in tabbarList" :key="index" :text="item.text"
:badge="getNum(index)"
:customStyle="{height:`110rpx`}">
<uv-tabbar
v-if="tabbarReady"
:key="refreshKey"
fixed
:value="currentTabIndex"
@change="onTabChange"
activeColor="#FF4767"
:placeholder="false"
:safeAreaInsetBottom="false"
:customStyle="{height:'110rpx'}"
>
<uv-tabbar-item
v-for="(item, idx) in tabbarList"
:key="idx"
:name="idx"
:text="item.text"
:badge="getNum(idx)"
:customStyle="{height:'110rpx'}"
@click="onItemClick(idx)"
>
<template v-slot:active-icon>
<image class="icon" :src="item.selectedIconPath"></image>
</template>
@ -16,116 +30,154 @@
</template>
<script>
import request from "@/utils/request";
export default {
import { mapState, mapMutations } from 'vuex';
import request from "@/utils/request";
export default {
name: "tab-bar",
props: {
selected: {
type: [Number, String]
}
},
// props.selected Vuex
data() {
return {
tabbarList: [{
"iconPath": "/static/images/tabbar/new_home_gray.png",
"text": "首页",
"selectedIconPath": "/static/images/tabbar/new_home.png",
"pagePath": "/pages/home/home"
refreshKey: 0, //
tabbarReady: false, //
tabbarList: [ // tab
{
iconPath: "/static/images/tabbar/new_home_gray.png",
text: "首页",
selectedIconPath: "/static/images/tabbar/new_home.png",
pagePath: "/pages/home/home"
},
{
"iconPath": "/static/images/tabbar/new_order_gray.png",
"text": "订单",
"selectedIconPath": "/static/images/tabbar/new_order.png",
"pagePath": "/pages/order/all-orders"
iconPath: "/static/images/tabbar/new_order_gray.png",
text: "订单",
selectedIconPath: "/static/images/tabbar/new_order.png",
pagePath: "/pages/order/all-orders"
},
{
"iconPath": "/static/images/tabbar/new_message_gray.png",
"text": "消息",
"selectedIconPath": "/static/images/tabbar/new_message.png",
"pagePath": "/pages/message/message"
iconPath: "/static/images/tabbar/new_message_gray.png",
text: "消息",
selectedIconPath: "/static/images/tabbar/new_message.png",
pagePath: "/pages/message/message"
},
{
"iconPath": "/static/images/tabbar/new_my_gray.png",
"text": "我的",
"selectedIconPath": "/static/images/tabbar/new_my.png",
"pagePath": "/pages/my/my"
iconPath: "/static/images/tabbar/new_my_gray.png",
text: "我的",
selectedIconPath: "/static/images/tabbar/new_my.png",
pagePath: "/pages/my/my"
}
]
};
},
computed: {
messageNum() {
return this.$store.state.messageNum || 0
// Vuex
...mapState(['currentTabIndex', 'messageNum'])
},
watch: {
// tabbarList
tabbarList: {
deep: true,
handler() {
this.rebuildTabbar();
}
}
},
async created() {
// if (!this.$store.state.tabbarList.length) {
// let isnNetwork = uni.getStorageSync("isnNetwork");
// if (isnNetwork) {
// await this.getButtonImg()
// } else {
// uni.getNetworkType({
// success: (res) => {
// console.log(res.networkType);
// if (res.networkType == "none") {
// this.$store.commit("setTabbarList", this.tabbarList)
// } else {
// //
// uni.setStorageSync("isnNetwork", 1);
// this.getButtonImg()
// }
// },
// });
// }
// }
created() {
//
this.tabbarReady = false;
this.$nextTick(() => {
this.tabbarReady = true;
//
// this.getButtonImg();
});
},
methods: {
...mapMutations(['SET_CURRENT_TAB_INDEX']),
//
setCurrentTabIndex(index) {
this.SET_CURRENT_TAB_INDEX(index);
},
// uv-tabbar
rebuildTabbar() {
this.tabbarReady = false;
this.$nextTick(() => {
this.refreshKey++;
this.tabbarReady = true;
});
},
// tab > 0
getNum(index) {
if (index == 2) {
return this.messageNum
} else {
return 0
if (index === 2 && this.messageNum > 0) {
return this.messageNum;
}
return null;
},
//
//
async getButtonImg() {
try {
let res = await request.post("/sj/poster/getButtonImg", {});
if (res.code == 200) {
// if (res.data?.photo) {
// this.topBgImage = res.data?.photo + '?time=666'
// }
if (res.code === 200) {
this.tabbarList.forEach((item, index) => {
if (res.data[index].iconPath) {
item.iconPath = res.data[index].iconPath
if (res.data[index]?.iconPath) {
item.iconPath = res.data[index].iconPath;
}
if (res.data[index].selectedIconPath) {
item.selectedIconPath = res.data[index].selectedIconPath
if (res.data[index]?.selectedIconPath) {
item.selectedIconPath = res.data[index].selectedIconPath;
}
})
});
this.$store.commit("setTabbarList", this.tabbarList);
//
this.rebuildTabbar();
}
} catch (err) {
console.error('getButtonImg 请求失败', err);
}
this.$store.commit("setTabbarList", this.tabbarList)
},
change1(val) {
// pages tabbar
// 使navigateTo 使
// uv-tabbar change
onTabChange(val) {
const idx = parseInt(val, 10);
this.doJump(idx);
},
// item
onItemClick(idx) {
this.doJump(idx);
},
// +
doJump(index) {
const idx = parseInt(index, 10);
if (isNaN(idx) || !this.tabbarList[idx]) return;
//
this.setCurrentTabIndex(idx);
//
const targetPage = this.tabbarList[idx].pagePath;
uni.switchTab({
url: this.tabbarList[val].pagePath
})
this.messageUpudateNum()
url: targetPage,
fail: (err) => console.error('switchTab 失败', err)
});
//
if (typeof this.messageUpudateNum === 'function') {
this.messageUpudateNum();
}
}
}
};
</script>
<style lang="scss">
.icon {
.icon {
height: 54rpx;
width: 54rpx;
}
::v-deep .uv-tabbar__content{
z-index: 999!important;
}
}
::v-deep .uv-tabbar__content {
z-index: 999 !important;
}
</style>

View File

@ -6,40 +6,43 @@ Vue.use(Vuex);
const store = new Vuex.Store({
state: {
messageNum: 0,//底部消息数量
sjServiceList:{},//商家分配手艺人时服务数据shop/staff
tabbarList: [], //底部设置
messageNum: 0, // 底部消息数量
// ========== 新增:全局当前选中的 tab 索引 ==========
currentTabIndex: 0, // 用于自定义 tabbar 高亮
// ============================================
sjServiceList: {}, // 商家分配手艺人时服务数据shop/staff
tabbarList: [], // 底部设置
reservationTime: {}, // 预约时刻信息
reservationSyr: {}, // 预约手艺人人信息
reservationAddress: {}, // 预约地址信息
selectStore: {}, //选择的门店信息
selectStore: {}, // 选择的门店信息
wxShareType: 0, // 正式版:0测试版:1体验版:2
//公共的变量这里的变量不能随便修改只能通过触发mutations的方法才能改变
searchCity: {
center: "117.330043,38.372266",
name: "黄骅",
},
systemInfo: uni.getSystemInfoSync(), //设备信息
//是否有定位权限
systemInfo: uni.getSystemInfoSync(),
isLocation: false,
//路由
baseUrl: "",
//手机和app信息
version: {
VersionCode: "",
DeviceBrand: "",
DeviceType: "",
},
//商家信息
sjInfo: {},
workSpaceSJClassList: [], //商家工位分类列表
workHourSJClassList: [], //商家工时分类列表
workSpaceSJClassList: [],
workHourSJClassList: [],
},
mutations: {
//写入底部消息数量
// 写入底部消息数量
setMessageNum(state, newval) {
state.messageNum = newval;
},
// ========== 新增:设置全局当前选中 tab 索引 ==========
SET_CURRENT_TAB_INDEX(state, index) {
state.currentTabIndex = index;
},
// ==============================================
clearServiceState(state) {
state.reservationTime = {};
state.reservationSyr = {};