提交 6928528c 编写于 作者: W wangyaqi

update: H5新增transparentTitle配置

上级 d6127e30
...@@ -27,7 +27,7 @@ const passiveOptions = supportsPassive ? { ...@@ -27,7 +27,7 @@ const passiveOptions = supportsPassive ? {
function updateCssVar (vm) { function updateCssVar (vm) {
if (uni.canIUse('css.var')) { if (uni.canIUse('css.var')) {
const pageVm = vm.$parent.$parent const pageVm = vm.$parent.$parent
const windowTop = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? (NAVBAR_HEIGHT + const windowTop = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' && pageVm.navigationBar.type !== 'alwaysTransparent' ? (NAVBAR_HEIGHT +
'px') 'px')
: '0px' : '0px'
const windowBottom = getApp().$children[0].showTabBar ? (TABBAR_HEIGHT + 'px') : '0px' const windowBottom = getApp().$children[0].showTabBar ? (TABBAR_HEIGHT + 'px') : '0px'
...@@ -74,8 +74,8 @@ export default function initSubscribe (subscribe) { ...@@ -74,8 +74,8 @@ export default function initSubscribe (subscribe) {
const enablePageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom') const enablePageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom')
const onReachBottomDistance = pageVm.onReachBottomDistance const onReachBottomDistance = pageVm.onReachBottomDistance
const enableTransparentTitleNView = isPlainObject(pageVm.titleNView) && pageVm.titleNView.type === const enableTransparentTitleNView = (isPlainObject(pageVm.titleNView) && pageVm.titleNView.type ===
'transparent' 'transparent') || (isPlainObject(pageVm.navigationBar) && pageVm.navigationBar.type === 'transparent')
if (scrollListener) { if (scrollListener) {
document.removeEventListener('scroll', scrollListener) document.removeEventListener('scroll', scrollListener)
......
...@@ -136,9 +136,19 @@ export default { ...@@ -136,9 +136,19 @@ export default {
titleImage: { titleImage: {
type: String, type: String,
default: '' default: ''
},
transparentTitle: {
type: String,
default: 'none'
} }
}, },
data () { data () {
const titleNViewTypeList = {
'none': 'default',
'auto': 'transparent',
'always': 'alwaysTransparent'
}
const navigationBar = mergeTitleNView({ const navigationBar = mergeTitleNView({
loading: false, loading: false,
backButton: !this.isQuit && !this.$route.meta.isQuit, // redirectTo,reLaunch时可能动态修改 meta.isQuit backButton: !this.isQuit && !this.$route.meta.isQuit, // redirectTo,reLaunch时可能动态修改 meta.isQuit
...@@ -147,7 +157,8 @@ export default { ...@@ -147,7 +157,8 @@ export default {
titleText: this.navigationBarTitleText, titleText: this.navigationBarTitleText,
titleImage: this.titleImage, titleImage: this.titleImage,
duration: '0', duration: '0',
timingFunc: '' timingFunc: '',
type: titleNViewTypeList[this.transparentTitle]
}, this.titleNView) }, this.titleNView)
const showNavigationBar = this.navigationStyle === 'default' && this.titleNView const showNavigationBar = this.navigationStyle === 'default' && this.titleNView
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
v-if="!searchInput" v-if="!searchInput"
class="uni-page-head-bd"> class="uni-page-head-bd">
<div <div
:style="{fontSize:titleSize,opacity:type==='transparent'?0:1}" :style="{fontSize:titleSize}"
class="uni-page-head__title" class="uni-page-head__title"
> >
<i <i
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
</div> </div>
</div> </div>
<div <div
v-if="type!=='transparent'" v-if="type!=='transparent'&&type!=='alwaysTransparent'"
class="uni-placeholder"/> class="uni-placeholder"/>
</uni-page-head> </uni-page-head>
</template> </template>
...@@ -277,7 +277,7 @@ uni-page-head .uni-page-head__title .uni-loading { ...@@ -277,7 +277,7 @@ uni-page-head .uni-page-head__title .uni-loading {
uni-page-head .uni-page-head__title .uni-page-head__title_image { uni-page-head .uni-page-head__title .uni-page-head__title_image {
width: auto; width: auto;
height: 20px; height: 26px;
vertical-align: middle; vertical-align: middle;
} }
</style> </style>
...@@ -335,7 +335,7 @@ export default { ...@@ -335,7 +335,7 @@ export default {
type: { type: {
default: 'default', default: 'default',
validator (value) { validator (value) {
return ['default', 'transparent'].indexOf(value) !== -1 return ['default', 'transparent', 'alwaysTransparent'].indexOf(value) !== -1
} }
}, },
coverage: { coverage: {
......
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
mounted () { mounted () {
if (this.type === 'transparent') { if (this.type === 'transparent') {
const transparentElemStyle = this.$el.querySelector('.uni-page-head-transparent').style const transparentElemStyle = this.$el.querySelector('.uni-page-head-transparent').style
const titleElem = this.$el.querySelector('.uni-page-head__title') // const titleElem = this.$el.querySelector('.uni-page-head__title')
const iconElems = this.$el.querySelectorAll('.uni-btn-icon') const iconElems = this.$el.querySelectorAll('.uni-btn-icon')
const iconElemsStyles = [] const iconElemsStyles = []
const textColor = this.textColor const textColor = this.textColor
...@@ -40,9 +40,10 @@ export default { ...@@ -40,9 +40,10 @@ export default {
} }
this._A = alpha this._A = alpha
// TODO 暂时仅处理背景色 // TODO 暂时仅处理背景色
if (titleElem) { // 对齐支付宝小程序,标题不透明渐变
titleElem.style.opacity = alpha // if (titleElem) {
} // titleElem.style.opacity = alpha
// }
transparentElemStyle.backgroundColor = `rgba(${this._R},${this._G},${this._B},${alpha})` transparentElemStyle.backgroundColor = `rgba(${this._R},${this._G},${this._B},${alpha})`
borderRadiusElemsStyles.forEach(function (borderRadiusElemStyle, index) { borderRadiusElemsStyles.forEach(function (borderRadiusElemStyle, index) {
let oldColor = oldColors[index] let oldColor = oldColors[index]
...@@ -52,17 +53,31 @@ export default { ...@@ -52,17 +53,31 @@ export default {
borderRadiusElemStyle.backgroundColor = `rgba(${rgba})` borderRadiusElemStyle.backgroundColor = `rgba(${rgba})`
}) })
}) })
} else if (this.type === 'alwaysTransparent') {
const iconElems = this.$el.querySelectorAll('.uni-btn-icon')
const iconElemsStyles = []
for (let i = 0; i < iconElems.length; i++) {
iconElemsStyles.push(iconElems[i].style)
}
const borderRadiusElems = this.$el.querySelectorAll('.uni-page-head-btn')
const oldColors = []
const borderRadiusElemsStyles = []
for (let i = 0; i < borderRadiusElems.length; i++) {
let borderRadiusElem = borderRadiusElems[i]
oldColors.push(getComputedStyle(borderRadiusElem).backgroundColor)
borderRadiusElemsStyles.push(borderRadiusElem.style)
}
} }
}, },
computed: { computed: {
color () { color () {
return this.type === 'transparent' ? '#fff' : this.textColor return this.type === 'transparent' || this.type === 'alwaysTransparent' ? '#fff' : this.textColor
}, },
offset () { offset () {
return parseInt(this.coverage) return parseInt(this.coverage)
}, },
bgColor () { bgColor () {
if (this.type === 'transparent') { if (this.type === 'transparent' || this.type === 'alwaysTransparent') {
const { const {
r, r,
g, g,
......
...@@ -17,7 +17,7 @@ export default function getWindowOffset () { ...@@ -17,7 +17,7 @@ export default function getWindowOffset () {
const pages = getCurrentPages() const pages = getCurrentPages()
if (pages.length) { if (pages.length) {
const pageVm = pages[pages.length - 1].$parent.$parent const pageVm = pages[pages.length - 1].$parent.$parent
top = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? NAVBAR_HEIGHT : 0 top = pageVm.showNavigationBar && (pageVm.navigationBar.type !== 'transparent' || pageVm.navigationBar.type !== 'alwaysTransparent') ? NAVBAR_HEIGHT : 0
} }
const app = getApp() const app = getApp()
if (app) { if (app) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册