nav

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: '小程序标题'
    },
    // 按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000
    fontColor: {
      type: String,
      value: '#FFFFFF'
    },
    // 导航栏背景
    backgroundColor: {
      type: String,
      value: '#1E5AA2'
    },
    // 顶部窗口(下拉)的背景色,仅 iOS 支持
    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") {
        // 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;
  /* z-index: 999; */
  top: 0;
  left: 0;
  width: 100%;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值