2024-04-02 17:31:39 +08:00
|
|
|
<template>
|
2024-05-11 09:36:26 +08:00
|
|
|
<wd-tabbar
|
2025-06-21 14:13:30 +08:00
|
|
|
v-if="customTabbarEnable"
|
2024-05-11 09:36:26 +08:00
|
|
|
fixed
|
|
|
|
v-model="tabbarStore.curIdx"
|
|
|
|
bordered
|
|
|
|
safeAreaInsetBottom
|
|
|
|
placeholder
|
|
|
|
@change="selectTabBar"
|
|
|
|
>
|
|
|
|
<block v-for="(item, idx) in tabbarList" :key="item.path">
|
2024-05-11 21:26:56 +08:00
|
|
|
<wd-tabbar-item
|
|
|
|
v-if="item.iconType === 'wot'"
|
|
|
|
:title="item.text"
|
|
|
|
:icon="item.icon"
|
|
|
|
></wd-tabbar-item>
|
2024-05-12 16:37:25 +08:00
|
|
|
<wd-tabbar-item
|
|
|
|
v-else-if="item.iconType === 'unocss' || item.iconType === 'iconfont'"
|
|
|
|
:title="item.text"
|
|
|
|
>
|
2024-05-11 09:36:26 +08:00
|
|
|
<template #icon>
|
|
|
|
<view
|
|
|
|
h-40rpx
|
|
|
|
w-40rpx
|
|
|
|
:class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
|
|
|
|
></view>
|
|
|
|
</template>
|
2024-05-11 21:26:56 +08:00
|
|
|
</wd-tabbar-item>
|
|
|
|
<wd-tabbar-item v-else-if="item.iconType === 'local'" :title="item.text">
|
|
|
|
<template #icon>
|
|
|
|
<image :src="item.icon" h-40rpx w-40rpx />
|
|
|
|
</template>
|
|
|
|
</wd-tabbar-item>
|
2024-05-11 09:36:26 +08:00
|
|
|
</block>
|
|
|
|
</wd-tabbar>
|
2024-04-02 17:31:39 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-06-21 14:13:30 +08:00
|
|
|
import { tabbarList as _tabBarList, cacheTabbarEnable, selectedTabbarStrategy } from './tabbarList'
|
2024-05-11 09:36:26 +08:00
|
|
|
import { tabbarStore } from './tabbar'
|
2024-04-02 17:31:39 +08:00
|
|
|
|
2025-06-21 14:13:30 +08:00
|
|
|
const customTabbarEnable = selectedTabbarStrategy === 1 || selectedTabbarStrategy === 2
|
2024-05-28 11:33:15 +08:00
|
|
|
/** tabbarList 里面的 path 从 pages.config.ts 得到 */
|
2025-06-03 12:38:13 +08:00
|
|
|
const tabbarList = _tabBarList.map((item) => ({ ...item, path: `/${item.pagePath}` }))
|
2024-05-11 09:36:26 +08:00
|
|
|
function selectTabBar({ value: index }: { value: number }) {
|
|
|
|
const url = tabbarList[index].path
|
|
|
|
tabbarStore.setCurIdx(index)
|
2025-06-21 14:13:30 +08:00
|
|
|
if (cacheTabbarEnable) {
|
2025-06-21 12:54:52 +08:00
|
|
|
uni.switchTab({ url })
|
2025-06-21 14:13:30 +08:00
|
|
|
} else {
|
|
|
|
uni.navigateTo({ url })
|
2025-06-21 12:54:52 +08:00
|
|
|
}
|
2024-04-02 17:31:39 +08:00
|
|
|
}
|
2024-05-11 11:32:34 +08:00
|
|
|
onLoad(() => {
|
|
|
|
// 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
|
2025-06-21 14:13:30 +08:00
|
|
|
const hideRedundantTabbarEnable = selectedTabbarStrategy === 1
|
|
|
|
hideRedundantTabbarEnable &&
|
|
|
|
uni.hideTabBar({
|
|
|
|
fail(err) {
|
|
|
|
console.log('hideTabBar fail: ', err)
|
|
|
|
},
|
|
|
|
success(res) {
|
|
|
|
console.log('hideTabBar success: ', res)
|
|
|
|
},
|
|
|
|
})
|
2024-05-11 11:32:34 +08:00
|
|
|
})
|
2024-04-02 17:31:39 +08:00
|
|
|
</script>
|