From b6415c82829decc7d2fa9ba737980b8de8905d3a Mon Sep 17 00:00:00 2001 From: Utopia Date: Wed, 29 Oct 2025 14:08:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=20tabbar=20=E7=9A=84=20pagePa?= =?UTF-8?q?th=20=E6=B7=BB=E5=8A=A0=E6=98=8E=E7=A1=AE=E7=9A=84=E8=81=94?= =?UTF-8?q?=E5=90=88=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 | 7 +++++-- src/typings.ts | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tabbar/config.ts b/src/tabbar/config.ts index 2656ea4..4345586 100644 --- a/src/tabbar/config.ts +++ b/src/tabbar/config.ts @@ -1,4 +1,5 @@ import type { TabBar } from '@uni-helper/vite-plugin-uni-pages' +import type { RemoveLeadingSlashFromUnion } from '@/typings' /** * tabbar 选择的策略,更详细的介绍见 tabbar.md 文件 @@ -22,7 +23,9 @@ export const TABBAR_STRATEGY_MAP = { // 如果是使用 CUSTOM_TABBAR(2,3),只需要配置 customTabbarList,nativeTabbarList 不生效 export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE -type NativeTabBarItem = TabBar['list'][number] +type NativeTabBarItem = TabBar['list'][number] & { + pagePath: RemoveLeadingSlashFromUnion<_LocationUrl> +} // TODO: 2/3. 使用 NATIVE_TABBAR 时,更新下面的 tabbar 配置 export const nativeTabbarList: NativeTabBarItem[] = [ @@ -45,7 +48,7 @@ export type CustomTabBarItemBadge = number | 'dot' export interface CustomTabBarItem { text: string - pagePath: string + pagePath: RemoveLeadingSlashFromUnion<_LocationUrl> iconType: 'uiLib' | 'unocss' | 'iconfont' | 'image' // 不建议用 image 模式,需要配置2张图 icon: any // 其实是 string 类型,这里是为了避免 ts 报错 (tabbar/index.vue 里面 uni-icons 那行) iconActive?: string // 只有在 image 模式下才需要,传递的是高亮的图片(PS: 不建议用 image 模式) diff --git a/src/typings.ts b/src/typings.ts index b48b630..fefe1cb 100644 --- a/src/typings.ts +++ b/src/typings.ts @@ -13,3 +13,9 @@ export interface IUniUploadFileOptions { name?: string formData?: any } + +/** 工具类型:删除字符串开头的第一个斜杠 */ +export type RemoveLeadingSlash = S extends `/${infer Rest}` ? Rest : S + +/** 工具类型:删除联合类型中每个字符串的第一个斜杠 */ +export type RemoveLeadingSlashFromUnion = T extends any ? RemoveLeadingSlash : never