From ccfab5eea48e8ce496fd2c2db4893c68b87ec31b Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Thu, 7 Aug 2025 20:33:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(tabbar):=20=E5=B0=86=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=BB=8E'local'=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E4=B8=BA'image'=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改图标类型命名以更准确描述其用途 在image模式下未配置iconActive时添加控制台警告 --- src/tabbar/config.ts | 6 +++--- src/tabbar/index.vue | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tabbar/config.ts b/src/tabbar/config.ts index a22521d..c088106 100644 --- a/src/tabbar/config.ts +++ b/src/tabbar/config.ts @@ -1,9 +1,9 @@ import type { TabBar } from '@uni-helper/vite-plugin-uni-pages' type FgTabBarItem = TabBar['list'][0] & { - iconType: 'uniUi' | 'uiLib' | 'unocss' | 'iconfont' | 'local' + iconType: 'uniUi' | 'uiLib' | 'unocss' | 'iconfont' | 'image' icon: any // 其实是 string 类型,这里是为了避免 ts 报错 - activeIcon?: string // 只有在 local 模式下才需要,传递的是高亮的图片(PS: 不建议用 local 模式) + activeIcon?: string // 只有在 image 模式下才需要,传递的是高亮的图片(PS: 不建议用 image 模式) } /** @@ -79,7 +79,7 @@ export const tabbarList: FgTabBarItem[] = [ // text: '首页', // // 使用 ‘local’时,需要配置 icon + iconActive 2张图片(不推荐) // // 既然已经用了自定义tabbar了,就不建议用图片了,所以不推荐 - // iconType: 'local', + // iconType: 'image', // icon: '/static/tabbar/home.png', // iconActive: '/static/tabbar/homeHL.png', // }, diff --git a/src/tabbar/index.vue b/src/tabbar/index.vue index 58d76d4..60d3419 100644 --- a/src/tabbar/index.vue +++ b/src/tabbar/index.vue @@ -44,7 +44,11 @@ function getColorByIndex(index: number) { return tabbarStore.curIdx === index ? activeColor : inactiveColor } -function getImageByIndex(index: number, item: { iconActive: string, icon: string }) { +function getImageByIndex(index: number, item: { iconActive?: string, icon: string }) { + if (!item.iconActive) { + console.warn('image 模式下,需要配置 iconActive,否则无法切换图片') + return item.icon + } return tabbarStore.curIdx === index ? item.iconActive : item.icon } @@ -72,7 +76,7 @@ function getImageByIndex(index: number, item: { iconActive: string, icon: string -