From 137db25b4919e24bbad9be307a298f4724006897 Mon Sep 17 00:00:00 2001 From: liu <2302563948@qq.com> Date: Wed, 1 Jul 2026 21:58:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=95=E9=83=A8=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PublishPopup/index.tsx | 3 +-- src/custom-tab-bar/index.tsx | 24 ++++++------------------ src/pages/index/index.tsx | 2 +- src/pages/messages/index.tsx | 2 +- src/pages/profile/index.tsx | 2 +- src/pages/tasks/index.tsx | 2 +- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/components/PublishPopup/index.tsx b/src/components/PublishPopup/index.tsx index a014ac6..197a4d1 100644 --- a/src/components/PublishPopup/index.tsx +++ b/src/components/PublishPopup/index.tsx @@ -26,12 +26,11 @@ interface PublishPopupProps { export default function PublishPopup({ visible, onClose, onSelect }: PublishPopupProps) { return ( diff --git a/src/custom-tab-bar/index.tsx b/src/custom-tab-bar/index.tsx index 4d118b5..c16baaf 100644 --- a/src/custom-tab-bar/index.tsx +++ b/src/custom-tab-bar/index.tsx @@ -20,24 +20,13 @@ const TAB_LIST: TabItem[] = [ { key: 'profile', label: '我的', icon: '👤', pagePath: '/pages/profile/index' }, ] -/** - * 根据当前页面路由推导激活的 tab。 - * 不使用 useState —— Taro 在每次切换 tab 时都会重建 custom-tab-bar 实例, - * 因此直接从 getCurrentPages() 实时计算即可保证正确性。 - */ -function useActiveKey(): string { - const pages = Taro.getCurrentPages() - if (pages.length > 0) { - const route = pages[pages.length - 1].route || '' - for (const tab of TAB_LIST) { - if (route.includes(tab.key)) return tab.key - } - } - return 'index' +interface CustomTabBarProps { + /** 当前激活的 tab key,由页面传入 */ + activeKey: string } /** 获取底部安全距离 */ -function useSafeBottom(): number { +function getSafeBottom(): number { try { const info = Taro.getSystemInfoSync() if (info.safeArea) { @@ -47,9 +36,8 @@ function useSafeBottom(): number { return 0 } -export default function CustomTabBar() { - const activeKey = useActiveKey() - const safeBottom = useSafeBottom() +export default function CustomTabBar({ activeKey }: CustomTabBarProps) { + const safeBottom = getSafeBottom() const [publishVisible, setPublishVisible] = useState(false) /** 切换 Tab —— 使用 Taro.switchTab 与原生 tabBar 行为一致 */ diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 6e58767..61a42aa 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -165,7 +165,7 @@ export default function Index() { - + ) } diff --git a/src/pages/messages/index.tsx b/src/pages/messages/index.tsx index ec84474..eaf26eb 100644 --- a/src/pages/messages/index.tsx +++ b/src/pages/messages/index.tsx @@ -10,7 +10,7 @@ export default function Messages() { 消息 即将上线,敬请期待 - + ) } diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index 59d0af2..78d114a 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -10,7 +10,7 @@ export default function Profile() { 我的 即将上线,敬请期待 - + ) } diff --git a/src/pages/tasks/index.tsx b/src/pages/tasks/index.tsx index 3a1a8f3..bb99826 100644 --- a/src/pages/tasks/index.tsx +++ b/src/pages/tasks/index.tsx @@ -10,7 +10,7 @@ export default function Tasks() { 校园任务 即将上线,敬请期待 - + ) }