提交 e7320b24 编写于 作者: fxy060608's avatar fxy060608

fix(runtime): binding current page to navigation-bar

上级 a821048a
......@@ -83,8 +83,9 @@ export default {
}
},
created () {
const pages = getCurrentPages()
const pages = getCurrentPages()
const page = pages[pages.length - 1]
this.__$page = page
this.$watch('title', () => {
this.setNavigationBarTitle()
})
......@@ -101,7 +102,7 @@ export default {
this.setNavigationBarColor()
})
// #ifdef APP-PLUS
this._webview = page.$getAppWebview()
this.__$webview = page.$getAppWebview()
attrs.forEach(key => {
const titleNView = {}
if (this[key] || this[key].length > 0) {
......@@ -124,14 +125,18 @@ export default {
methods: {
setNavigationBarTitle () {
uni.setNavigationBarTitle({
__page__: this.__$page,
title: this.title
})
},
setNavigationBarLoading () {
uni[(this.loading ? 'show' : 'hide') + 'NavigationBarLoading']()
uni[(this.loading ? 'show' : 'hide') + 'NavigationBarLoading']({
__page__: this.__$page
})
},
setNavigationBarColor () {
uni.setNavigationBarColor({
__page__: this.__$page,
frontColor: this.frontColor,
backgroundColor: this.backgroundColor,
animation: {
......@@ -141,7 +146,7 @@ export default {
})
},
setTitleNView (titleNView) {
const webview = this._webview
const webview = this.__$webview
const style = webview.getStyle()
if (style && style.titleNView) {
webview.setStyle({
......
import {
getLastWebview
getWebview
} from '../util'
export function setNavigationBarTitle ({
__page__,
title = ''
} = {}) {
const webview = getLastWebview()
const webview = getWebview(__page__)
if (webview) {
const style = webview.getStyle()
if (style && style.titleNView) {
......@@ -49,11 +50,12 @@ function setPageMeta (statusBarStyle) {
pages[pages.length - 1].$page.meta.statusBarStyle = statusBarStyle
}
export function setNavigationBarColor ({
export function setNavigationBarColor ({
__page__,
frontColor,
backgroundColor
} = {}) {
const webview = getLastWebview()
const webview = getWebview(__page__)
if (webview) {
const styles = {}
if (frontColor) {
......@@ -85,4 +87,4 @@ export function setNavigationBarColor ({
return {
errMsg: 'setNavigationBarColor:fail'
}
}
}
......@@ -15,6 +15,13 @@ export function callApiSync (api, args, name, alias) {
return ret
}
export function getWebview (__page__) {
if (__page__) {
return __page__.$getAppWebview()
}
return getLastWebview()
}
export function getLastWebview () {
try {
const pages = getCurrentPages()
......@@ -225,4 +232,4 @@ export function getFileName (path) {
export function getExtName (path) {
const array = path.split('.')
return array.length > 1 ? '.' + array[array.length - 1] : ''
}
}
function setNavigationBar (type, args) {
const pages = getCurrentPages()
if (pages.length) {
const page = pages[pages.length - 1].$holder
import {
isCurrentPage,
getPageHolder
} from '../util.js'
function setNavigationBar (type, args = {}) {
const page = getPageHolder(args.__page__)
if (page) {
switch (type) {
case 'setNavigationBarColor':
{
......@@ -43,7 +46,9 @@ function setNavigationBar (type, args) {
title
} = args
page.navigationBar.titleText = title
document.title = title
if (isCurrentPage(page)) { // 仅当前页面
document.title = title
}
UniServiceJSBridge.emit('onNavigationBarChange', {
titleText: title
})
......@@ -58,12 +63,12 @@ export function setNavigationBarColor (args) {
return setNavigationBar('setNavigationBarColor', args)
}
export function showNavigationBarLoading () {
return setNavigationBar('showNavigationBarLoading')
export function showNavigationBarLoading (args) {
return setNavigationBar('showNavigationBarLoading', args)
}
export function hideNavigationBarLoading () {
return setNavigationBar('hideNavigationBarLoading')
export function hideNavigationBarLoading (args) {
return setNavigationBar('hideNavigationBarLoading', args)
}
export function setNavigationBarTitle (args) {
......
export function getPageHolder (__page__) {
if (__page__) {
return __page__.$holder
}
const pages = getCurrentPages()
const len = pages.length
if (len) {
return pages[len - 1].$holder
}
}
export function isCurrentPage (pageHolder) {
const pages = getCurrentPages()
const len = pages.length
if (len) {
return pages[len - 1].$holder === pageHolder
}
return false
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册