From b43f13b88746142f3d703dfd346c5f36f61b1113 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Mon, 4 Apr 2022 16:51:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20Responsive=5FXxx=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=8C=E4=BB=85=E4=BB=85?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E8=AF=BB=E5=8F=96=20pageJson.topWindow=20=E6=9D=A5?= =?UTF-8?q?=E5=AE=8C=E7=BE=8E=E5=AE=9E=E7=8E=B0=E5=93=8D=E5=BA=94=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usertool.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/usertool.js b/usertool.js index 2fc0c22..2abf468 100644 --- a/usertool.js +++ b/usertool.js @@ -13,7 +13,6 @@ export default { WHITE_BUTTON: 'default', // [todo] 能否把这些默认值放到 export 以外? - RESPONSIVE_TABBAR_AUTOHIDE_WIDTH_THRESHOLD_DEFAULT: 0, BACKEND_DEFAULT: 'SERVER', // 服务器 SERVER 或云服务 UNICLOUD thisPage() { @@ -92,23 +91,19 @@ export default { } }) // uni.showTabBar({}) - + // #ifdef H5 - if (uni.getSystemInfoSync().model==='PC') { - const envar = this.envar || wo?.envar || {} - if (envar.Responsive_Tabbar==='AUTOHIDE') { - if (window.screen.width > (envar.Responsive_Tabbar_Autohide_Width_Threshold || this.RESPONSIVE_TABBAR_AUTOHIDE_WIDTH_THRESHOLD_DEFAULT)) { + // 响应式方案:仅仅根据当前设备类型,如果是 PC 大屏幕,则始终显示 topWindow 并且隐藏顶部 navibar 和底部 tabBar。 + const envar = this.envar || wo?.envar + if (pagesJson?.topWindow) { + if (uni.getSystemInfoSync().model==='PC') { + if (window.screen.width > (pagesJson?.topWindow?.matchMedia?.minWidth || 0)) { uni.hideTabBar() + // 不知为何,同一个二级页面,如果第二次进入,就仍然会显示 navibar, 必须通过 setTimeout 执行才能彻底隐藏。 + setTimeout(()=>{ document.getElementsByTagName('uni-page-head')?.[0]?.remove() },0) } - uni.onWindowResize(({size})=>{ - if (size.windowWidth > (envar.Responsive_Tabbar_Autohide_Width_Threshold || this.RESPONSIVE_TABBAR_AUTOHIDE_WIDTH_THRESHOLD_DEFAULT)) { - uni.hideTabBar() - }else{ - uni.showTabBar() - } - }) - }else if (envar.Responsive_Tabbar==='ALWAYSHIDE') { - uni.hideTabBar() + }else { + document.getElementsByTagName('uni-top-window')?.[0]?.remove() // hide topWindow } } // #endif @@ -177,6 +172,7 @@ export default { }) { const thisRoute = this.thisPage()?.route || 'VueApp' // 立刻保存 this.thisPage().route,因为在调用后台后,可能已切换到了其他页面。 const startTime = new Date().toJSON() + let url = undefined let result = {} if (backend === 'UNICLOUD') { let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud @@ -206,8 +202,7 @@ export default { apiWhat[key] = JSON.stringify(apiWhat[key]) } } - const url = this.makeServerUrl(`${apiVersion}/${apiWho}/${apiTodo}`) - process.env.NODE_ENV === 'development' && console.log('%c '+JSON.stringify({url}), 'color:blue') + url = this.makeServerUrl(`${apiVersion}/${apiWho}/${apiTodo}`) let [error, { statusCode, header, errMsg, data: resultServer = {} } = {}] = await uni.request({ method: httpMethod, url: url, @@ -234,7 +229,7 @@ export default { if (process.env.NODE_ENV === 'development') { console.log( '%c '+JSON.stringify({startTime:startTime, page:thisRoute, endTime:new Date().toJSON()}) + - ' %c '+ JSON.stringify({ backend, apiWho, apiTodo, apiWhat }) + + ' %c '+ JSON.stringify({ backend, apiWho, apiTodo, apiWhat, url }) + ' %c '+ JSON.stringify(result), 'color:blue', 'background:skyblue', 'background:magenta') // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。 }