From 6d6b6948083906c8a2cf5382ecbdf638a8ecabe9 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 27 Mar 2020 17:17:28 +0800 Subject: [PATCH] refactor(h5): add onNavigationBarChange --- src/core/service/plugins/app/router-guard.js | 19 +- src/platforms/h5/components/page/index.vue | 72 +++---- .../system-routes/system-header.vue | 185 +++++++++--------- .../h5/service/api/ui/navigation-bar.js | 32 +-- 4 files changed, 135 insertions(+), 173 deletions(-) diff --git a/src/core/service/plugins/app/router-guard.js b/src/core/service/plugins/app/router-guard.js index d0889311a..04143f8b8 100644 --- a/src/core/service/plugins/app/router-guard.js +++ b/src/core/service/plugins/app/router-guard.js @@ -199,22 +199,11 @@ function afterEach (to, from) { if (to.type !== 'reLaunch') { // 因为 reLaunch 会重置 id,故不触发 onShow,switchTab 在 beforeRouteEnter 中触发 // 直接获取所有 pages,getCurrentPages 正常情况下仅返回页面栈内,传 true 则返回所有已存在(主要是 tabBar 页面) const toVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === toId) // 使用最新的 pages - if (toVm) { // 目标页面若已存在,则触发 onShow + if (toVm) { // 目标页面若已存在,则触发 onShow // 延迟执行 onShow,防止与 UniServiceJSBridge.emit('onHidePopup') 冲突。 - setTimeout(function () { - if (__PLATFORM__ === 'h5') { - const navigationBar = toVm.$parent.$parent.navigationBar - if (typeof qh !== 'undefined') { - qh.setNavigationBarTitle({ - title: document.title - }) - qh.setNavigationBarColor({ - backgroundColor: navigationBar.backgroundColor - }) - qh.setNavigationBarTextStyle({ - textStyle: navigationBar.textColor === '#000' ? 'black' : 'white' - }) - } + setTimeout(function () { + if (__PLATFORM__ === 'h5') { + UniServiceJSBridge.emit('onNavigationBarChange', toVm.$parent.$parent.navigationBar) } callPageHook(toVm, 'onShow') }, 0) diff --git a/src/platforms/h5/components/page/index.vue b/src/platforms/h5/components/page/index.vue index 666edd7c4..fed247504 100644 --- a/src/platforms/h5/components/page/index.vue +++ b/src/platforms/h5/components/page/index.vue @@ -1,21 +1,19 @@ + diff --git a/src/platforms/h5/components/system-routes/system-header.vue b/src/platforms/h5/components/system-routes/system-header.vue index 79800c346..38ef20acd 100644 --- a/src/platforms/h5/components/system-routes/system-header.vue +++ b/src/platforms/h5/components/system-routes/system-header.vue @@ -1,106 +1,103 @@ -