From 7fdd18a244951f3998872b449cc10d2cb5489668 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 29 Sep 2021 14:40:06 +0800 Subject: [PATCH] feat: support dynamic tabbarItem hidden --- .../app-plus/service/api/ui/tab-bar.js | 5 +- .../app-plus/service/framework/tab-bar.js | 14 ++++- src/platforms/h5/components/app/tabBar.vue | 56 +++++++++++++------ src/platforms/h5/service/api/ui/tab-bar.js | 2 +- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/platforms/app-plus/service/api/ui/tab-bar.js b/src/platforms/app-plus/service/api/ui/tab-bar.js index c835c9cd4..c5510fba1 100644 --- a/src/platforms/app-plus/service/api/ui/tab-bar.js +++ b/src/platforms/app-plus/service/api/ui/tab-bar.js @@ -20,9 +20,10 @@ export function setTabBarItem ({ text, iconPath, selectedIconPath, - pagePath + pagePath, + visible }) { - tabBar.setTabBarItem(index, text, iconPath, selectedIconPath) + tabBar.setTabBarItem(index, text, iconPath, selectedIconPath, visible) const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath) if (route) { const meta = route.meta diff --git a/src/platforms/app-plus/service/framework/tab-bar.js b/src/platforms/app-plus/service/framework/tab-bar.js index e056dfd12..3b14da16f 100644 --- a/src/platforms/app-plus/service/framework/tab-bar.js +++ b/src/platforms/app-plus/service/framework/tab-bar.js @@ -49,7 +49,7 @@ function setTabBarBadge (type, index, text) { /** * 动态设置 tabBar 某一项的内容 */ -function setTabBarItem (index, text, iconPath, selectedIconPath) { +function setTabBarItem (index, text, iconPath, selectedIconPath, visible) { const item = { index } @@ -62,7 +62,17 @@ function setTabBarItem (index, text, iconPath, selectedIconPath) { if (selectedIconPath) { item.selectedIconPath = getRealPath(selectedIconPath) } - tabBar && tabBar.setTabBarItem(item) + if (visible !== undefined) { + item.visible = config.list[index].visible = visible + delete item.index + + const tabbarItems = config.list.map(item => ({ visible: item.visible })) + tabbarItems[index] = item + + tabBar && tabBar.setTabBarItems({ list: tabbarItems }) + } else { + tabBar && tabBar.setTabBarItem(item) + } } /** * 动态设置 tabBar 的整体样式 diff --git a/src/platforms/h5/components/app/tabBar.vue b/src/platforms/h5/components/app/tabBar.vue index 9439fdd0a..d1be1eb5c 100644 --- a/src/platforms/h5/components/app/tabBar.vue +++ b/src/platforms/h5/components/app/tabBar.vue @@ -12,7 +12,7 @@ class="uni-tabbar-border" />