小程序 之自定义tabbar与权限控制

摘要:
'top:0':'bottom:0'}};{{borderStyle?(position=='top'?'border-bottom:solid1px'+borderStyle+';':'border-top:solid1px'+borderStyle+';'):''}}"><navigatorhover-class="none"url="{{item.pagePath}}"open-type="switchTab"class="weui-flex__itemmenu-item{{item.class}}"style="{{item.active?'color:'+(item.selectedColor?item.selectedColor:selectedColor):''}}"wx:if="{{item.hidden!

一、效果图

小程序 之自定义tabbar与权限控制第1张小程序 之自定义tabbar与权限控制第2张

二、自定义tabbar

Component({
  options: {
    multipleSlots: true //在组件定义时的选项中启用多slot支持},  /**
   * 组件的属性列表   */properties: {
    color:{
      type:String,
      value:'#333'},
    selectedColor:{
      type:String,
      value:'#1aad19'},
    backgroundColor:{
      type:String,
      value:''},
    position:{
      type:String,
      value:'bottom'},
    borderStyle:{
      type: String,
      value:'#ccc'},
    list:{
      type:Array,
      value:[]
    }
  },

  data: {

  },

  methods: {

  }
})
.weui-flex {display:-webkit-box;display:-webkit-flex;display:flex}.weui-flex__item {-webkit-box-flex:1;-webkit-flex:1;flex:1}.menu-item {height:100rpx;text-align:center;padding-top:5rpx;
}.img {width:60rpx;height:60rpx;display:block;margin:auto;
}.clear {clear:both;
}.tab-bar {position:fixed;width:100%}.tabbar_text {font-size:28rpx;position:relative;top:-12rpx;
}
<view wx:if="{{list.length > 1}}"class="weui-flex tab-bar"style="color: {{color}}; background: {{backgroundColor}}; {{position=='top'? 'top: 0' : 'bottom: 0'}}; {{borderStyle? (position=='top'? 'border-bottom: solid 1px '+borderStyle + ';' : 'border-top: solid 1px '+borderStyle + ';') : ''}}">
  <block wx:for="{{list}}"wx:key="pagePath"><navigator hover-class="none"url="{{item.pagePath}}"open-type="switchTab"class="weui-flex__item menu-item {{item.class}}"style="{{item.active? 'color: '+(item.selectedColor? item.selectedColor : selectedColor) : ''}}"wx:if="{{item.hidden!==true}}">  <image src="https://tool.4xseo.com/article/{{item.selectedIconPath}}"wx:if="{{item.active}}"class="img"></image>  <image src="https://tool.4xseo.com/article/{{item.iconPath}}"wx:if="{{!item.active}}"class="img"></image>  <text class='tabbar_text'>{{item.text}}</text></navigator>
  </block>
  <view class="clear"></view></view>

三、使用tabbar

app.json

{  "pages": ["pages/check/index","pages/index/index","pages/asset/list","pages/mine/index"],  "tabBar": {"list": [
      {"pagePath": "pages/index/index","iconPath": "/image/icon_API.png","selectedIconPath": "/image/icon_API_HL.png","text": "电子名片"},
      {"pagePath": "pages/check/index","iconPath": "/image/icon_API.png","selectedIconPath": "/image/icon_API_HL.png","text": "电子样本"},
      {"pagePath": "pages/mine/index","iconPath": "/image/icon_component.png","selectedIconPath": "/image/icon_component_HL.png","text": "视频浏览"}
    ]
  },  "usingComponents": {"my-tabbar": "/component/tabbar/tabbar"},  "window": {"backgroundTextStyle": "light","navigationBarBackgroundColor": "#fff","navigationBarTitleText": "WeChat","navigationBarTextStyle": "black"},  "sitemapLocation": "sitemap.json"}

app.js

App({
  onLaunch: function() {
    wx.hideTabBar({
      animation: false,
    })
  },
  util: require('./api.js'),
  getTabList: function() {var tabItemList =[{"pagePath": "/pages/index/index","text": "电子名片","iconPath": "/image/icon_API.png","selectedIconPath": "/image/icon_API_HL.png","active": false},
      {"pagePath": "/pages/check/index","text": "电子样本","iconPath": "/image/icon_API.png","selectedIconPath": "/image/icon_API_HL.png","active": false},
      {"pagePath": "/pages/mine/index","text": "视频浏览","iconPath": "/image/icon_component.png","selectedIconPath": "/image/icon_component_HL.png","active": false}
    ];returntabItemList;
  },
  initTabBar(app, activeIdx) {var tabItemList = this.getTabList();this.util.request('https://www.baidu.com', {}, 'Get').then(function(res) {      //同步判断是否有权限,没有权限则隐藏  tabItemList[0].hidden = !true;
      tabItemList[2].hidden = !false;      if (activeIdx >= 0 && activeIdx <tabItemList.length) {
        tabItemList[activeIdx].active = true;
      }
      app.setData({tabItemList})
    })return //去除隐藏项,只有一个tab时,隐藏底部导航var newBar =[]for (var i = 0; i < tabItemList.length; i++) {      if (tabItemList[i].hidden != true) {
        newBar.push(tabItemList[i])
      }
    }returnnewBar;
  }
})

index.js

var app =getApp()
Page({
  data: {

  },

  onLoad: function(options) {
    
  },

  onShow: function() {app.initTabBar(this, 1);},
})

index.wxml

<navigator url="/pages/asset/list">详情</navigator><my-tabbar  list="{{tabItemList}}"></my-tabbar>

免责声明:文章转载自《小程序 之自定义tabbar与权限控制》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇自定义RDLC报表的数据集(手工编辑rdlc文件,配置数据集)线性回归中常见的一些统计学术语(RSE RSS TSS ESS MSE RMSE R2 Pearson's r)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

毫米雷达波概述

毫米波雷达1.毫米波雷达的应用与特点1)车载毫米波雷达研究意义随着现代科学技术的快速发展以及人们生活水平的显著提高,车辆的使用量急剧增加,相应的交通事故也急剧上升。2)车载毫米波雷达特点汽车防撞雷达主要有超声波雷达、激光雷达、毫米波雷达等类型。基带信号处理部分主要是算法,是毫米波雷达稳定性、可靠性的核心。...

Excel数据透视表、高级筛选

目录:1.数据透视表:数据透视表格式和操作说明:多个表一起创建数据透视表创建组创建计算字段创建计算项值显示方法切片器2。高级过滤:高级过滤和或关系精确过滤和模糊过滤通配符过滤原则查询不重复值(使用高级过滤)高级过滤区分大小写使用高级过滤查找空数据使用高级过滤查询两个表中相同的记录或未使用的记录过滤记录1和数据透视表1.正确的数据透视表格式:① 数据源的第一行...

nginx 浏览php的时候会变成下载

php的时候会变成下载:这是因为nginx没有设置好碰到php文件时,要传递到后方的php解释器。当然啦,你的php-fpm解析器也需要正常运行,并监听好9000端口,才能最终生效并有效处理php脚本。windows下开启监听的办法,php-cgi.exe-b127.0.0.1:9000-cphpphp.ini待续:。。。。。...

可爱猫+python——定制化微信机器人

框架是模拟真实用户操作,只要不违法乱纪,是不用担心账号冻结问题的。...

mac 安装git

gitconfig--globaluser.name"your_name"gitconfig--globaluser.email"your_email@gmail.com"配置信息可以更改,以后想要更改使用上面指令就可以。同时可以使用gitconfig--list指令查看Git的配置信息。gitconfigcore.ignorecasefalse生成密钥Gi...

由微博图床挂掉之后想到的

前不久,微博图床挂了,这对于众多使用Markdown写技术博客的人简直太残忍了!无论是哪种方式,知乎都会将文章中的图片上传到自己的服务器。...