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

feat(v3): titleNViewButton

上级 229c6907
...@@ -6018,6 +6018,31 @@ var serviceContext = (function () { ...@@ -6018,6 +6018,31 @@ var serviceContext = (function () {
} }
} }
function createButtonOnClick (index) {
return function onClick (btn) {
const pages = getCurrentPages();
if (!pages.length) {
return
}
btn.index = index;
const page = pages[pages.length - 1];
page.$vm &&
page.$vm.__call_hook &&
page.$vm.__call_hook('onNavigationBarButtonTap', btn);
}
}
function parseTitleNViewButtons (titleNView) {
const buttons = titleNView.buttons;
if (!Array.isArray(buttons)) {
return titleNView
}
buttons.forEach((btn, index) => {
btn.onclick = createButtonOnClick(index);
});
return titleNView
}
function parseTitleNView (routeOptions) { function parseTitleNView (routeOptions) {
const windowOptions = routeOptions.window; const windowOptions = routeOptions.window;
const titleNView = windowOptions.titleNView; const titleNView = windowOptions.titleNView;
...@@ -6030,38 +6055,38 @@ var serviceContext = (function () { ...@@ -6030,38 +6055,38 @@ var serviceContext = (function () {
) )
) { ) {
return false return false
} }
const titleImage = windowOptions.titleImage || ''; const titleImage = windowOptions.titleImage || '';
const transparentTitle = windowOptions.transparentTitle || 'none'; const transparentTitle = windowOptions.transparentTitle || 'none';
const titleNViewTypeList = { const titleNViewTypeList = {
'none': 'default', 'none': 'default',
'auto': 'transparent', 'auto': 'transparent',
'always': 'float' 'always': 'float'
}; };
const ret = { const ret = {
autoBackButton: !routeOptions.meta.isQuit, autoBackButton: !routeOptions.meta.isQuit,
titleText: titleImage === '' ? windowOptions.navigationBarTitleText || '' : '', titleText: titleImage === '' ? windowOptions.navigationBarTitleText || '' : '',
titleColor: windowOptions.navigationBarTextStyle === 'black' ? '#000000' : '#ffffff', titleColor: windowOptions.navigationBarTextStyle === 'black' ? '#000000' : '#ffffff',
type: titleNViewTypeList[transparentTitle], type: titleNViewTypeList[transparentTitle],
backgroundColor: transparentTitle !== 'always' ? windowOptions.navigationBarBackgroundColor || '#000000' : 'rgba(0,0,0,0)', backgroundColor: transparentTitle !== 'always' ? windowOptions.navigationBarBackgroundColor || '#000000' : 'rgba(0,0,0,0)',
tags: titleImage === '' ? [] : [{ tags: titleImage === '' ? [] : [{
'tag': 'img', 'tag': 'img',
'src': titleImage, 'src': titleImage,
'position': { 'position': {
'left': 'auto', 'left': 'auto',
'top': 'auto', 'top': 'auto',
'width': 'auto', 'width': 'auto',
'height': '26px' 'height': '26px'
} }
}] }]
}; };
routeOptions.meta.statusBarStyle = windowOptions.navigationBarTextStyle === 'black' ? 'dark' : 'light'; routeOptions.meta.statusBarStyle = windowOptions.navigationBarTextStyle === 'black' ? 'dark' : 'light';
if (isPlainObject(titleNView)) { if (isPlainObject(titleNView)) {
return Object.assign(ret, titleNView) return Object.assign(ret, parseTitleNViewButtons(titleNView))
} }
return ret return ret
......
...@@ -3,6 +3,31 @@ import { ...@@ -3,6 +3,31 @@ import {
} }
from 'uni-shared' from 'uni-shared'
function createButtonOnClick (index) {
return function onClick (btn) {
const pages = getCurrentPages()
if (!pages.length) {
return
}
btn.index = index
const page = pages[pages.length - 1]
page.$vm &&
page.$vm.__call_hook &&
page.$vm.__call_hook('onNavigationBarButtonTap', btn)
}
}
function parseTitleNViewButtons (titleNView) {
const buttons = titleNView.buttons
if (!Array.isArray(buttons)) {
return titleNView
}
buttons.forEach((btn, index) => {
btn.onclick = createButtonOnClick(index)
})
return titleNView
}
export function parseTitleNView (routeOptions) { export function parseTitleNView (routeOptions) {
const windowOptions = routeOptions.window const windowOptions = routeOptions.window
const titleNView = windowOptions.titleNView const titleNView = windowOptions.titleNView
...@@ -15,38 +40,38 @@ export function parseTitleNView (routeOptions) { ...@@ -15,38 +40,38 @@ export function parseTitleNView (routeOptions) {
) )
) { ) {
return false return false
} }
const titleImage = windowOptions.titleImage || '' const titleImage = windowOptions.titleImage || ''
const transparentTitle = windowOptions.transparentTitle || 'none' const transparentTitle = windowOptions.transparentTitle || 'none'
const titleNViewTypeList = { const titleNViewTypeList = {
'none': 'default', 'none': 'default',
'auto': 'transparent', 'auto': 'transparent',
'always': 'float' 'always': 'float'
} }
const ret = { const ret = {
autoBackButton: !routeOptions.meta.isQuit, autoBackButton: !routeOptions.meta.isQuit,
titleText: titleImage === '' ? windowOptions.navigationBarTitleText || '' : '', titleText: titleImage === '' ? windowOptions.navigationBarTitleText || '' : '',
titleColor: windowOptions.navigationBarTextStyle === 'black' ? '#000000' : '#ffffff', titleColor: windowOptions.navigationBarTextStyle === 'black' ? '#000000' : '#ffffff',
type: titleNViewTypeList[transparentTitle], type: titleNViewTypeList[transparentTitle],
backgroundColor: transparentTitle !== 'always' ? windowOptions.navigationBarBackgroundColor || '#000000' : 'rgba(0,0,0,0)', backgroundColor: transparentTitle !== 'always' ? windowOptions.navigationBarBackgroundColor || '#000000' : 'rgba(0,0,0,0)',
tags: titleImage === '' ? [] : [{ tags: titleImage === '' ? [] : [{
'tag': 'img', 'tag': 'img',
'src': titleImage, 'src': titleImage,
'position': { 'position': {
'left': 'auto', 'left': 'auto',
'top': 'auto', 'top': 'auto',
'width': 'auto', 'width': 'auto',
'height': '26px' 'height': '26px'
} }
}] }]
} }
routeOptions.meta.statusBarStyle = windowOptions.navigationBarTextStyle === 'black' ? 'dark' : 'light' routeOptions.meta.statusBarStyle = windowOptions.navigationBarTextStyle === 'black' ? 'dark' : 'light'
if (isPlainObject(titleNView)) { if (isPlainObject(titleNView)) {
return Object.assign(ret, titleNView) return Object.assign(ret, parseTitleNViewButtons(titleNView))
} }
return ret return ret
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册