• 自适应组件导航栏


     以上目录结构

    tops是自定义组件导航栏

    indexs使用

    先贴上tops代码

    js

    // utils/tops/tops.js
    Component({
      properties: {
        background: {
          type: String,
          value: 'rgba(255, 255, 255, 1)'
        },
        color: {
          type: String,
          value: 'rgba(0, 0, 0, 1)'
        },
        titleText: {
          type: String,
          value: '导航栏'
        },
        titleImg: {
          type: String,
          value: ''
        },
        backIcon: {
          type: String,
          value: ''
        },
        homeIcon: {
          type: String,
          value: ''
        },
        fontSize: {
          type: Number,
          value: 16
        },
        iconHeight: {
          type: Number,
          value: 19
        },
        iconWidth: {
          type: Number,
          value: 58
        }
      },
      attached: function() {
        var that = this;
        that.setNavSize();
        that.setStyle();
      },
      data: {},
      methods: {
        // 通过获取系统信息计算导航栏高度 
        setNavSize: function() {
          var that = this,
            sysinfo = wx.getSystemInfoSync(),
            statusHeight = sysinfo.statusBarHeight,
            isiOS = sysinfo.system.indexOf('iOS') > -1,
            navHeight;
          if (!isiOS) {
            navHeight = 48;
          } else {
            navHeight = 44;
          }
          that.setData({
            status: statusHeight,
            navHeight: navHeight
          })
        },
        setStyle: function() {
          var that = this,
            containerStyle, textStyle, iconStyle;
          containerStyle = [
            'background:' + that.data.background
          ].join(';');
          textStyle = [
            'color:' + that.data.color,
            'font-size:' + that.data.fontSize + 'px'
          ].join(';');
          iconStyle = [
            ' ' + that.data.iconWidth + 'px',
            'height: ' + that.data.iconHeight + 'px'
          ].join(';');
          that.setData({
            containerStyle: containerStyle,
            textStyle: textStyle,
            iconStyle: iconStyle
          })
        },
        // 返回事件 
        back: function() {
          wx.navigateBack({
            delta: 1
          })
          this.triggerEvent('back', {
            back: 1
          })
        },
        home: function() {
          this.triggerEvent('home', {});
        }
      }
    })

    css

    /* utils/tops/tops.wxss */
    .navbar{
     position: relative
    }
    .back-icon, .home-icon{
     width: 28px;
     height: 100%;
     position: absolute; 
     transform: translateY(-50%); 
     top: 50%; 
     display: flex;
     }
    .back-icon{ 
     left: 16px;
    }
    .home-icon{ 
     left: 44px
    }
    .back-icon image{ 
     width: 28px; 
     height: 28px; 
     margin: auto;
    }
    .home-icon image{ 
     width: 20px; 
     height: 20px; 
     margin: auto;
    }
    .nav-title, .nav-icon{ 
     position: absolute; 
     transform: translate(-50%, -50%); 
     left: 50%; 
     top: 50%; 
     font-size: 0; 
     font-weight: bold;
    }

    html

    <view class='nav' style='height: {{status + navHeight}}px'>
      <view class='status' style='height: {{status}}px;{{containerStyle}}'></view>
      <view class='navbar' style='height:{{navHeight}}px;{{containerStyle}}'>
        <view class='back-icon' wx:if="{{backIcon}}" bindtap='back'>
          <image src='{{backIcon}}'></image>
        </view>
        <view class='home-icon' wx:if="{{homeIcon}}" bindtap='home'>
          <image src='{{homeIcon}}'></image>
        </view>
        <view class='nav-icon' wx:if="{{titleImg}}">
          <image src='{{titleImg}}' style='{{iconStyle}}'></image>
        </view>
        <view class='nav-title' wx:if="{{titleText && !titleImg}}">
          <text style='{{textStyle}}'>{{titleText}}</text>
        </view>
      </view>
    </view>

    开启全局自定义导航栏,引入自定义导航栏

        "usingComponents": {
          "navBar": "/utils/tops/tops"
        },
          "window": {
        "navigationStyle":"custom"
      }

    indexs使用

    <!--pages/indexs/indexs.wxml-->
    <navBar 
        title-text="" 
        back-icon="/images/back@3x.png"
        home-icon="/images/home_icon@3x.png"
        background="#f2f2f2"
        bindback="back"/>
  • 相关阅读:
    Ubuntu 16.04实现SSH无密码登录/免密登录/自动登录(ssh-keygen/ssh-copy-id)
    简单理解Linux的Loopback接口
    iptables为什么需要增加loopback回环的规则
    [ASP.NET Core 3框架揭秘] 依赖注入[10]:与第三方依赖注入框架的适配
    [ASP.NET Core 3框架揭秘] 依赖注入[9]:实现概述
    [ASP.NET Core 3框架揭秘] 依赖注入[8]:服务实例的生命周期
    [ASP.NET Core 3框架揭秘] 依赖注入[7]:服务消费
    [ASP.NET Core 3框架揭秘] 依赖注入[6]:服务注册
    [ASP.NET Core 3框架揭秘] 依赖注入[5]: 利用容器提供服务
    AOP框架Dora.Interception 3.0 [5]: 基于策略的拦截器注册方式
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/11690279.html
Copyright © 2020-2023  润新知