refactor(tabbar): 重构tabbar配置逻辑并优化变量命名

将cacheTabbarEnable重命名为tabbarCacheEnable以提高可读性
新增customTabbarEnable和nativeTabbarNeedHide变量以明确功能
简化index.vue中的条件判断逻辑
This commit is contained in:
feige996
2025-08-04 10:53:16 +08:00
parent e3495bae69
commit 6725b1649c
2 changed files with 12 additions and 10 deletions

View File

@@ -1,18 +1,14 @@
<script setup lang="ts">
// 'i-carbon-code',
import { tabbarList as _tabBarList, cacheTabbarEnable, selectedTabbarStrategy, TABBAR_MAP } from './config'
import { tabbarList as _tabBarList, customTabbarEnable, nativeTabbarNeedHide, tabbarCacheEnable } from './config'
import { tabbarStore } from './store'
const customTabbarEnable
= selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
|| selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITHOUT_CACHE
/** tabbarList 里面的 path 从 pages.config.ts 得到 */
const tabbarList = _tabBarList.map(item => ({ ...item, path: `/${item.pagePath}` }))
function selectTabBar({ value: index }: { value: number }) {
const url = tabbarList[index].path
tabbarStore.setCurIdx(index)
if (cacheTabbarEnable) {
if (tabbarCacheEnable) {
uni.switchTab({ url })
}
else {
@@ -21,8 +17,7 @@ function selectTabBar({ value: index }: { value: number }) {
}
onLoad(() => {
// 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
const hideRedundantTabbarEnable = selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
hideRedundantTabbarEnable
nativeTabbarNeedHide
&& uni.hideTabBar({
fail(err) {
console.log('hideTabBar fail: ', err)