From d349281da52a9b0abd62582efa5b42cef8bae298 Mon Sep 17 00:00:00 2001 From: Utopia Date: Tue, 19 Aug 2025 16:49:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=20tabbar=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20-=20NativeTabBarItem=20=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tabbar/config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tabbar/config.ts b/src/tabbar/config.ts index d56785e..e8bdf0e 100644 --- a/src/tabbar/config.ts +++ b/src/tabbar/config.ts @@ -22,7 +22,8 @@ export const TABBAR_STRATEGY_MAP = { // 如果是使用 CUSTOM_TABBAR(2,3),只需要配置 customTabbarList,nativeTabbarList 不生效 export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.NATIVE_TABBAR -type NativeTabBarItem = TabBar['list'][0] +type NativeTabBarItem = TabBar['list'][number] + // TODO: 2/3. 使用 NATIVE_TABBAR 时,更新下面的 tabbar 配置 export const nativeTabbarList: NativeTabBarItem[] = [ { From f72d8e9a0406bec38b5de937e49beb872bf458e7 Mon Sep 17 00:00:00 2001 From: Utopia Date: Tue, 19 Aug 2025 17:07:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20tabbar=20-=20=E8=A1=A5=E5=85=A8=20t?= =?UTF-8?q?abbarList=20ts=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tabbar/config.ts | 2 +- src/tabbar/index.vue | 2 +- src/tabbar/store.ts | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tabbar/config.ts b/src/tabbar/config.ts index e8bdf0e..91eeac6 100644 --- a/src/tabbar/config.ts +++ b/src/tabbar/config.ts @@ -40,7 +40,7 @@ export const nativeTabbarList: NativeTabBarItem[] = [ }, ] -interface CustomTabBarItem { +export interface CustomTabBarItem { text: string pagePath: string iconType: 'uniUi' | 'uiLib' | 'unocss' | 'iconfont' | 'image' // 不建议用 image 模式,需要配置2张图 diff --git a/src/tabbar/index.vue b/src/tabbar/index.vue index b0ede6f..fd9c6f8 100644 --- a/src/tabbar/index.vue +++ b/src/tabbar/index.vue @@ -29,7 +29,7 @@ function handleClick(index: number) { handleClickBulge() return } - const url = tabbarList[index].path + const url = tabbarList[index].pagePath tabbarStore.setCurIdx(index) if (tabbarCacheEnable) { uni.switchTab({ url }) diff --git a/src/tabbar/store.ts b/src/tabbar/store.ts index 2feeea7..86e0db1 100644 --- a/src/tabbar/store.ts +++ b/src/tabbar/store.ts @@ -1,27 +1,27 @@ +import type { CustomTabBarItem } from './config' import { tabbarList as _tabbarList } from './config' // TODO 1/2: 中间的鼓包tabbarItem的开关 const BULGE_ENABLE = true /** tabbarList 里面的 path 从 pages.config.ts 得到 */ -const tabbarList = _tabbarList.map(item => ({ ...item, path: `/${item.pagePath}` })) +const tabbarList: CustomTabBarItem[] = _tabbarList.map(item => ({ ...item, pagePath: item.pagePath.startsWith('/') ? item.pagePath : `/${item.pagePath}` })) + if (BULGE_ENABLE) { if (tabbarList.length % 2 === 1) { console.error('tabbar 数量必须是偶数,否则样式很奇怪!!') } tabbarList.splice(tabbarList.length / 2, 0, { isBulge: true, - } as any) + } as CustomTabBarItem) } -export { tabbarList } - /** * 自定义 tabbar 的状态管理,原生 tabbar 无需关注本文件 * tabbar 状态,增加 storageSync 保证刷新浏览器时在正确的 tabbar 页面 * 使用reactive简单状态,而不是 pinia 全局状态 */ -export const tabbarStore = reactive({ +const tabbarStore = reactive({ curIdx: uni.getStorageSync('app-tabbar-index') || 0, prevIdx: uni.getStorageSync('app-tabbar-index') || 0, setCurIdx(idx: number) { @@ -46,3 +46,5 @@ export const tabbarStore = reactive({ this.prevIdx = uni.getStorageSync('app-tabbar-index') || 0 }, }) + +export { tabbarList, tabbarStore } From 2f95bc2f5fc21c4bd624d0c2b5ebfd439f8275d1 Mon Sep 17 00:00:00 2001 From: Utopia Date: Tue, 19 Aug 2025 17:09:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E8=87=AA=E5=AE=9A=E4=B9=89=20tabbar?= =?UTF-8?q?=20=E6=97=B6=EF=BC=88=E5=9B=BE=E6=A0=87=E4=B8=BA=20image=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=89=EF=BC=8C=E9=80=89=E4=B8=AD=E9=AB=98?= =?UTF-8?q?=E4=BA=AE=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tabbar/index.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tabbar/index.vue b/src/tabbar/index.vue index fd9c6f8..ac67aa6 100644 --- a/src/tabbar/index.vue +++ b/src/tabbar/index.vue @@ -1,5 +1,5 @@