调整 发布

This commit is contained in:
浅念
2026-03-12 16:47:27 +08:00
parent 12bc0f8ba9
commit f892dbcb32
13 changed files with 536 additions and 111 deletions
+22 -10
View File
@@ -1,15 +1,15 @@
<template>
<view class="custom-tabbar" :style="{ paddingBottom: safeAreaInsets.bottom + 'px' }">
<view
v-for="(item, index) in tabList"
<view
v-for="(item, index) in tabList"
:key="index"
class="tab-item"
:class="{ active: current === index }"
@tap="switchTab(item, index)"
>
<image
class="tab-icon"
:src="current === index ? item.selectedIconPath : item.iconPath"
<image
class="tab-icon"
:src="current === index ? item.selectedIconPath : item.iconPath"
mode="aspectFit"
/>
<text class="tab-text">{{ item.text }}</text>
@@ -18,7 +18,7 @@
</template>
<script>
import { getVisibleTabBar, getCurrentTabIndex, getUserRole } from '@/common/tabbar.js'
import { getVisibleTabBar, getCurrentTabIndex } from '@/common/tabbar.js'
export default {
name: 'CustomTabBar',
@@ -27,18 +27,26 @@
current: 0,
safeAreaInsets: {
bottom: 0
}
},
forceUpdate: 0
}
},
computed: {
tabList() {
// 根据权限获取可见的 tabbar 列表
const userRole = getUserRole()
return getVisibleTabBar(userRole)
// 添加 forceUpdate 依赖,确保角色变化时重新计算
void this.forceUpdate
return getVisibleTabBar()
}
},
created() {
this.initSafeArea()
// 监听角色变化事件
uni.$on('userRoleChanged', this.onRoleChanged)
},
onUnload() {
// 移除监听
uni.$off('userRoleChanged', this.onRoleChanged)
},
mounted() {
this.updateCurrent()
@@ -57,6 +65,10 @@
}
},
methods: {
// 角色变化时触发更新
onRoleChanged() {
this.forceUpdate++
},
initSafeArea() {
// 获取安全区域信息(适配 iPhone X 等)
// #ifdef APP-PLUS || H5
@@ -71,7 +83,7 @@
updateCurrent() {
const pages = getCurrentPages()
if (pages.length === 0) return
const currentPage = pages[pages.length - 1]
const currentPath = currentPage.route || currentPage.$route?.path || ''
const index = getCurrentTabIndex(currentPath)