From 1baec3728f12ab92e5aac58d2733bf4e5121c98f Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Mon, 19 May 2025 15:53:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=97=A0tabbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.config.ts | 1 + src/utils/index.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pages.config.ts b/pages.config.ts index 1745eb0..8906405 100644 --- a/pages.config.ts +++ b/pages.config.ts @@ -16,6 +16,7 @@ export default defineUniPages({ 'z-paging/components/z-paging$1/z-paging$1.vue', }, }, + // 如果不需要tabBar,可以注释掉这个配置,或者直接删除 tabBar: { color: '#999999', selectedColor: '#018d71', diff --git a/src/utils/index.ts b/src/utils/index.ts index e358e1b..c2e9ef5 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,8 @@ -import { pages, subPackages, tabBar } from '@/pages.json' +import pagesConfig from '@/pages.json' import { isMpWeixin } from './platform' +const { pages, subPackages, tabBar = { list: [] } } = { ...pagesConfig } + export const getLastPage = () => { // getCurrentPages() 至少有1个元素,所以不再额外判断 // const lastPage = getCurrentPages().at(-1) @@ -11,16 +13,14 @@ export const getLastPage = () => { /** 判断当前页面是否是 tabbar 页 */ export const getIsTabbar = () => { - if (!tabBar) { + try { + const lastPage = getLastPage() + const currPath = lastPage?.route + + return Boolean(tabBar?.list?.some((item) => item.pagePath === currPath)) + } catch { return false } - if (!tabBar.list.length) { - // 通常有 tabBar 的话,list 不能有空,且至少有2个元素,这里其实不用处理 - return false - } - const lastPage = getLastPage() - const currPath = lastPage.route - return !!tabBar.list.find((e) => e.pagePath === currPath) } /**