wxml
<view class="oc-head">
<view class="head_bg" style="color: {{fontColorTop}}; background-color: {{backgroundColorTop}}; padding-top: {{top}}px; height: {{height}}px; font-size: {{fontSize}}px;"></view>
<view class="head-container" style="padding-top: {{top}}px; height: {{height}}px;">
<view style="color: {{fontColor}}; background-color: {{backgroundColor}};font-size: {{fontSize}}px;line-height: {{height}}px; ">{{title}}</view>
<view class="leftBtn" style="height:{{height}}px;position:absolute;top:{{top}}px;left:5px;line-height:{{height}}px;">
<block wx:if="{{ leftUser||leftArrow||leftText || iconImg }}">
<view wx:if="{{leftUser}}" bindtap="icon">
<image src="/images/icons/icon_user.png" style="width:20px;height:20px;vertical-align: middle;"></image>
</view>
<view wx:elif="{{ leftArrow }}" class="leftArrow" bindtap="back">
<image src="/images/icons/btn_return_normal.png" style="width:20px;height:20px;vertical-align: middle;"></image>
</view>
<view wx:elif="{{ leftText }}" bindtap="icon">{{ leftText }}</view>
<view wx:elif="{{ iconImg }}" bindtap="icon">
<image src="{{iconImg}}" style="width:20px;height:20px;vertical-align: middle;"></image>
</view>
</block>
<slot wx:else name="left" />
</view>
</view>
</view>
js
Component({
properties: {
title: {
type: String,
value: '小程序标题'
},
fontColor: {
type: String,
value: '#FFFFFF'
},
backgroundColor: {
type: String,
value: '#1E5AA2'
},
backgroundColorTop: {
type: String,
value: '#FFFFFF'
},
fontColorTop: {
type: String,
value: '#000000'
},
fontSize: {
type: Number,
value: 16
},
top: {
type: Number,
value: 20
},
height: {
type: Number,
value: 44
},
leftUser: {
type: Boolean,
value: false,
},
leftArrow: {
type: Boolean,
value: true,
},
leftText: String,
iconImg: String,
},
externalClasses: [],
data: {
},
lifetimes: {
attached() {
this.init();
},
detached() {
},
},
pageLifetimes: {
show() {
},
hide() {
},
resize(size) {
}
},
methods: {
init() {
let sysInfo = wx.getSystemInfoSync();
let disTop = 8;
if (sysInfo.platform == "ios") {
disTop = 6;
}
let height = 32 + disTop * 2;
if (wx.canIUse('getMenuButtonBoundingClientRect')) {
let MenuButton = wx.getMenuButtonBoundingClientRect();
disTop = MenuButton.top - sysInfo.statusBarHeight;
height = MenuButton.height + disTop * 2;
}
this.setData({
top: sysInfo.statusBarHeight,
fontSize: sysInfo.fontSizeSetting,
height
});
},
back() {
wx.navigateBack({
delta: 1
})
},
icon(){
this.triggerEvent("leftClick");
},
}
})
wxss
.oc-head {
text-align: center;
position: relative;
}
.head-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
}