Commit f755133f by 李伟康

navBar增加返回按钮

1 parent d0696dbe
...@@ -6,6 +6,7 @@ Component({ ...@@ -6,6 +6,7 @@ Component({
properties: { properties: {
navStyle: String, navStyle: String,
custom: Boolean, custom: Boolean,
showBack: Boolean,
pageTitle: { pageTitle: {
type: String, type: String,
value: '', value: '',
...@@ -47,8 +48,13 @@ Component({ ...@@ -47,8 +48,13 @@ Component({
width, width,
top top
} = wx.getMenuButtonBoundingClientRect(), } = wx.getMenuButtonBoundingClientRect(),
currentPages = getCurrentPages() currentPages = getCurrentPages(), {
showBack
} = this.data
if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true
})
console.log(currentPages.length, showBack)
let navigationBarHeight = height + ((top - statusBarHeight) * 2) + 4 // 4 let navigationBarHeight = height + ((top - statusBarHeight) * 2) + 4 // 4
let navigationBarPadding = screenWidth - right let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width
...@@ -81,6 +87,9 @@ Component({ ...@@ -81,6 +87,9 @@ Component({
navHeight, navHeight,
statusBarHeight statusBarHeight
}) })
},
back() {
wx.$router.back()
} }
}, },
lifetimes: { lifetimes: {
......
<view class="navigation-bar" id="navigation-bar" <view class="navigation-bar" id="navigation-bar" style="padding-top:{{statusBarHeight}}px;height:{{navigationBarHeight}}px;{{navStyle}}">
style="padding-top:{{statusBarHeight}}px;height:{{navigationBarHeight}}px;{{navStyle}}">
<block wx:if="{{!custom}}"> <block wx:if="{{!custom}}">
<view class="navigation-bar-box" wx:if="{{showNavBar}}" style="{{navigationBarStyle}}"> <view class="navigation-bar-box" wx:if="{{showNavBar}}" style="{{navigationBarStyle}}">
<block wx:if="{{SHOWBACK}}">
<view class="back" bindtap="back">
<image src="./images/icon-back.png"></image>
</view>
</block>
<view class="navigation-bar-titleText" style="{{navigationBarTextWidth}}"> <view class="navigation-bar-titleText" style="{{navigationBarTextWidth}}">
<slot></slot> <slot></slot>
</view> </view>
......
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
} }
.back{ .back{
position: absolute; position: absolute;
left: 20rpx; left: 44rpx;
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
width: 36rpx; width: 16rpx;
height: 36rpx; height: 34rpx;
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!