2025-06-21 16:56:24 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
// 'i-carbon-code',
|
2025-08-04 10:53:16 +08:00
|
|
|
|
import { tabbarList as _tabBarList, customTabbarEnable, nativeTabbarNeedHide, tabbarCacheEnable } from './config'
|
2025-08-04 10:44:48 +08:00
|
|
|
|
import { tabbarStore } from './store'
|
2025-06-21 16:56:24 +08:00
|
|
|
|
|
2025-08-04 16:05:00 +08:00
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
|
// 将自定义节点设置成虚拟的(去掉自定义组件包裹层),更加接近Vue组件的表现,能更好的使用flex属性
|
|
|
|
|
|
defineOptions({
|
|
|
|
|
|
virtualHost: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
2025-06-21 16:56:24 +08:00
|
|
|
|
/** tabbarList 里面的 path 从 pages.config.ts 得到 */
|
|
|
|
|
|
const tabbarList = _tabBarList.map(item => ({ ...item, path: `/${item.pagePath}` }))
|
2025-08-04 16:05:00 +08:00
|
|
|
|
function handleClick(index: number) {
|
|
|
|
|
|
// 点击原来的不做操作
|
|
|
|
|
|
if (index === tabbarStore.curIdx) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-06-21 16:56:24 +08:00
|
|
|
|
const url = tabbarList[index].path
|
|
|
|
|
|
tabbarStore.setCurIdx(index)
|
2025-08-04 10:53:16 +08:00
|
|
|
|
if (tabbarCacheEnable) {
|
2025-06-21 16:56:24 +08:00
|
|
|
|
uni.switchTab({ url })
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
uni.navigateTo({ url })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
onLoad(() => {
|
|
|
|
|
|
// 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
|
2025-08-04 10:53:16 +08:00
|
|
|
|
nativeTabbarNeedHide
|
2025-06-21 16:56:24 +08:00
|
|
|
|
&& uni.hideTabBar({
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
console.log('hideTabBar fail: ', err)
|
|
|
|
|
|
},
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
console.log('hideTabBar success: ', res)
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2025-08-04 16:05:00 +08:00
|
|
|
|
const activeColor = '#1890ff'
|
|
|
|
|
|
const inactiveColor = '#666'
|
|
|
|
|
|
function getColorByIndex(index: number) {
|
|
|
|
|
|
return tabbarStore.curIdx === index ? activeColor : inactiveColor
|
|
|
|
|
|
}
|
2025-06-21 16:56:24 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
2024-04-02 17:31:39 +08:00
|
|
|
|
<template>
|
2025-08-04 18:01:06 +08:00
|
|
|
|
<view v-if="customTabbarEnable" class="h-50px pb-safe">
|
|
|
|
|
|
<view class="border-and-fixed bg-white" @touchmove.stop.prevent>
|
2025-08-04 16:21:03 +08:00
|
|
|
|
<view class="h-50px flex items-center">
|
|
|
|
|
|
<view
|
|
|
|
|
|
v-for="(item, index) in tabbarList" :key="index"
|
|
|
|
|
|
class="flex flex-1 flex-col items-center justify-center"
|
|
|
|
|
|
:style="{ color: getColorByIndex(index) }"
|
|
|
|
|
|
@click="handleClick(index)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template v-if="item.iconType === 'uniUi'">
|
|
|
|
|
|
<uni-icons :type="item.icon" size="20" :color="getColorByIndex(index)" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-if="item.iconType === 'uiLib'">
|
|
|
|
|
|
<!-- TODO: 以下内容请根据选择的UI库自行替换 -->
|
|
|
|
|
|
<!-- 如:<wd-icon name="home" /> (https://wot-design-uni.cn/component/icon.html) -->
|
|
|
|
|
|
<!-- 如:<uv-icon name="home" /> (https://www.uvui.cn/components/icon.html) -->
|
|
|
|
|
|
<!-- 如:<sar-icon name="image" /> (https://sard.wzt.zone/sard-uniapp-docs/components/icon)(sar没有home图标^_^) -->
|
|
|
|
|
|
<wd-icon :name="item.icon" size="20" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-if="item.iconType === 'unocss' || item.iconType === 'iconfont'">
|
|
|
|
|
|
<view :class="item.icon" class="text-20px" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<view class="mt-2px text-12px">
|
|
|
|
|
|
{{ item.text }}
|
|
|
|
|
|
</view>
|
2025-08-04 16:05:00 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
2025-08-04 18:01:06 +08:00
|
|
|
|
<view class="pb-safe" />
|
2025-08-04 16:05:00 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
2024-04-02 17:31:39 +08:00
|
|
|
|
</template>
|
2025-08-04 16:05:00 +08:00
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.border-and-fixed {
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
|
|
|
|
border-top: 1px solid #eee;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|