refactor(tabbar): 将 tabbar 组件从 components 移动到 layouts 目录

重构 tabbar 组件结构,将其从 components 目录迁移至 layouts 目录以更符合项目结构规范
移除未使用的 midButton 配置
This commit is contained in:
feige996
2025-06-21 13:35:29 +08:00
parent 4b77ca6c13
commit 2a71d02ab8
6 changed files with 3 additions and 6 deletions

View File

@@ -1,66 +0,0 @@
<template>
<wd-tabbar
v-if="CUSTOM_TABBAR_ENABLE"
fixed
v-model="tabbarStore.curIdx"
bordered
safeAreaInsetBottom
placeholder
@change="selectTabBar"
>
<block v-for="(item, idx) in tabbarList" :key="item.path">
<wd-tabbar-item
v-if="item.iconType === 'wot'"
:title="item.text"
:icon="item.icon"
></wd-tabbar-item>
<wd-tabbar-item
v-else-if="item.iconType === 'unocss' || item.iconType === 'iconfont'"
:title="item.text"
>
<template #icon>
<view
h-40rpx
w-40rpx
:class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
></view>
</template>
</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>
</block>
</wd-tabbar>
<view v-else></view>
</template>
<script setup lang="ts">
import { tabbarList as _tabBarList, CUSTOM_TABBAR_ENABLE } from './tabbarList'
import { tabbarStore } from './tabbar'
/** 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 (CUSTOM_TABBAR_ENABLE) {
uni.navigateTo({ url })
} else {
uni.switchTab({ url })
}
}
onLoad(() => {
// 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
// !CUSTOM_TABBAR_ENABLE &&
// uni.hideTabBar({
// fail(err) {
// console.log('hideTabBar fail: ', err)
// },
// success(res) {
// console.log('hideTabBar success: ', res)
// },
// })
})
</script>

View File

@@ -1,11 +0,0 @@
/**
* tabbar 状态,增加 storageSync 保证刷新浏览器时在正确的 tabbar 页面
* 使用reactive简单状态而不是 pinia 全局状态
*/
export const tabbarStore = reactive({
curIdx: uni.getStorageSync('app-tabbar-index') || 0,
setCurIdx(idx: number) {
this.curIdx = idx
uni.setStorageSync('app-tabbar-index', idx)
},
})

View File

@@ -1,57 +0,0 @@
// 是否使用自定义的tabbar?
export const CUSTOM_TABBAR_ENABLE = false
// CUSTOM_TABBAR_ENABLE 为 true 时,可以不填 iconPath 和 selectedIconPath
// CUSTOM_TABBAR_ENABLE 为 false 时,可以不填 icon 和 iconType
export const tabbarList = [
{
iconPath: 'static/tabbar/home.png',
selectedIconPath: 'static/tabbar/homeHL.png',
pagePath: 'pages/index/index',
text: '首页',
icon: 'home',
iconType: 'wot',
},
{
iconPath: 'static/tabbar/example.png',
selectedIconPath: 'static/tabbar/exampleHL.png',
pagePath: 'pages/about/about',
text: '关于',
icon: 'i-carbon-code',
iconType: 'unocss',
},
// {
// pagePath: 'pages/my/index',
// text: '我的',
// icon: '/static/logo.svg',
// iconType: 'local',
// },
// {
// pagePath: 'pages/mine/index',
// text: '我的',
// icon: 'iconfont icon-my',
// iconType: 'iconfont',
// },
]
// midButton 仅App和H5支持
const midButton = {
iconPath: '/static/logo.svg',
text: '发布',
}
const _tabbar = {
color: '#999999',
selectedColor: '#018d71',
backgroundColor: '#F8F8F8',
borderStyle: 'black',
height: '50px',
fontSize: '10px',
iconWidth: '24px',
spacing: '3px',
list: tabbarList as any,
// midButton 仅App和H5支持h5中测试也没生效
// midButton: midButton,
}
export const tabBar = CUSTOM_TABBAR_ENABLE ? undefined : _tabbar