51 lines
1.3 KiB
Vue
Raw Normal View History

2024-04-02 17:31:39 +08:00
<template>
2024-05-11 09:36:26 +08:00
<wd-tabbar
fixed
v-model="tabbarStore.curIdx"
bordered
safeAreaInsetBottom
placeholder
@change="selectTabBar"
>
<block v-for="(item, idx) in tabbarList" :key="item.path">
2024-05-11 09:43:58 +08:00
<!-- <wd-tabbar-item v-if="item.isUnocssIcon" :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 09:43:58 +08:00
</wd-tabbar-item> -->
<wd-tabbar-item :title="item.text" :icon="item.icon"></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">
2024-05-11 09:36:26 +08:00
import { tabBar } from '@/pages.json'
import { tabbarStore } from './tabbar'
2024-04-02 17:31:39 +08:00
2024-05-11 09:36:26 +08:00
/** tabbarList 里面的 path 必须和 pages.config.ts 的页面路径一致 */
const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
2024-04-02 17:31:39 +08:00
2024-05-11 09:36:26 +08:00
function selectTabBar({ value: index }: { value: number }) {
const url = tabbarList[index].path
tabbarStore.setCurIdx(index)
uni.switchTab({ url })
2024-04-02 17:31:39 +08:00
}
2024-05-11 11:32:34 +08:00
onLoad(() => {
// 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
2024-05-11 20:10:26 +08:00
// #ifdef APP-PLUS
uni.hideTabBar({
fail(err) {
console.log('hideTabBar fail: ', err)
},
success(res) {
console.log('hideTabBar success: ', res)
},
})
// #endif
2024-05-11 11:32:34 +08:00
})
2024-04-02 17:31:39 +08:00
</script>