From 076a42f86fda24be432abc4a800d59427234b0ff Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sun, 14 May 2023 10:46:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=A8PC=E7=AB=AF=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=20uni.hideTabBar()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unitool.js | 54 +++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/unitool.js b/unitool.js index 692fb27..d0c7558 100644 --- a/unitool.js +++ b/unitool.js @@ -75,41 +75,25 @@ export default { // document.title = ??? // #endif - // 必须要在有 tab 的页面里 setTabBarItem 才有效果 - //const midIndex = parseInt(pagesJson?.tabBar?.list?.length/2) // 如果存在midButton,实际上tabBar.list.length必须为偶数。不过为了心安,再parseInt一下。 - pagesJson?.tabBar?.list?.forEach((tab, tabIndex) => { - if (tab.i18nText && tab.i18nText[mylang]) { - uni.setTabBarItem({ - // #ifdef H5 - index: tabIndex, // + ((pagesJson?.tabBar?.midButton?.iconPath && tabIndex >= midIndex)?1:0), // H5 里,如果使用了 midButton,tabBarItem的index出现错位,需hack调整。推测,在H5里 midButton 作为一个普通tab被插入到 tabBar 里,导致 tabBar 的 index 和 pagesJson.tabBar.list 的 index 错位了。[20211031] 注意到,从 HBuilderX 3.2.12.20211029 起,在 H5 里也没有错位了。 - // #endif - // #ifndef H5 - index: tabIndex, - // #endif - text: tab.i18nText[mylang], - }) - } - }) - // uni.showTabBar({}) - - // 不再使用 topWindow 方案 - // // #ifdef H5 - // // 响应式方案:仅仅根据当前设备类型,如果是 PC 大屏幕,则始终显示 topWindow 并且隐藏顶部 navibar 和底部 tabBar。 - // if (pagesJson?.topWindow || !envar?.showBarsOnPC) { - // // 如果页头不是通过 pagesJson.topWindow 而是作为组件来引入个别页面,那么定义配置参数 showBarsOnPC 来控制。 - // if (uni.getSystemInfoSync().deviceType === 'pc') { - // if (window.innerWidth > (pagesJson?.topWindow?.matchMedia?.minWidth || 0)) { - // uni.hideTabBar() - // // 不知为何,同一个二级页面,如果第二次进入,就仍然会显示 navibar, 必须通过 setTimeout 执行才能彻底隐藏。 - // setTimeout(() => { - // document.getElementsByTagName('uni-page-head')?.[0]?.remove() - // }, 0) - // } - // } else { - // document.getElementsByTagName('uni-top-window')?.[0]?.remove() // 强制隐藏 topWindow,否则在手机浏览器里,topWindow 会遮挡掉 navibar。 - // } - // } - // // #endif + if (uni.getSystemInfoSync().deviceType === 'pc') { + uni.hideTabBar() + } else { + // 必须要在有 tab 的页面里 setTabBarItem 才有效果 + //const midIndex = parseInt(pagesJson?.tabBar?.list?.length/2) // 如果存在midButton,实际上tabBar.list.length必须为偶数。不过为了心安,再parseInt一下。 + pagesJson?.tabBar?.list?.forEach((tab, tabIndex) => { + if (tab.i18nText && tab.i18nText[mylang]) { + uni.setTabBarItem({ + // #ifdef H5 + index: tabIndex, // + ((pagesJson?.tabBar?.midButton?.iconPath && tabIndex >= midIndex)?1:0), // H5 里,如果使用了 midButton,tabBarItem的index出现错位,需hack调整。推测,在H5里 midButton 作为一个普通tab被插入到 tabBar 里,导致 tabBar 的 index 和 pagesJson.tabBar.list 的 index 错位了。[20211031] 注意到,从 HBuilderX 3.2.12.20211029 起,在 H5 里也没有错位了。 + // #endif + // #ifndef H5 + index: tabIndex, + // #endif + text: tab.i18nText[mylang], + }) + } + }) + } //#ifdef H5 //// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。