当前位置:   article > 正文

小程序自定义底部导航根据权限动态生成_小程序导航栏 权限

小程序导航栏 权限

先在根目录pages同级创建文件夹custom-tab-bar
在这里插入图片描述

<view class="tab-bar">
  <view class="tab-bar-border"></view>
  <view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
    <image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image>
    <view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view>
  </view>
</view>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
.tab-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: white;
  display: flex;
  padding-top: 10rpx;
  box-sizing: border-box;
  flex-direction: row;
  padding-bottom: env(safe-area-inset-bottom);
  pointer-events: auto;
}

.tab-bar-border {
  background-color: rgba(0, 0, 0, 0.33);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 1px;
  transform: scaleY(0.5);
}

.tab-bar-item {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.tab-bar-item image {
  width: 27px;
  height: 27px;
}

.tab-bar-item view {
  font-size: 10px;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

Component({
    lifetimes: {
        attached(){
            this.getUser("", "") //未上传 获取当前登录用户的底部导航权限动态切换data里的list为mdlist或者userlist
        }
    }, 
    data: {
        selected: 0,
        color: "#7A7E83",
        selectedColor: "#07C160",
        list: [],
        num: 0,
        mdlist: [{
            pagePath: "/pages/mdsy/mdsy",
            iconPath: "/images/tabbar/icon1.png",
            selectedIconPath: "/images/tabbar/icon2.png",
            text: "首页"
        }, {
            pagePath: "/pages/main/main",
            iconPath: "/images/tabbar/icon9.png",
            selectedIconPath: "/images/tabbar/icon10.png",
            text: "商城"
        }, {
            pagePath: "/pages/ddcenter/ddcenter",
            iconPath: "/images/tabbar/icon3.png",
            selectedIconPath: "/images/tabbar/icon4.png",
            text: "购物车"
        }, {
            pagePath: "/pages/mycenter/mycenter",
            iconPath: "/images/tabbar/icon5.png",
            selectedIconPath: "/images/tabbar/icon6.png",
            text: "个人中心"
        }, {
            pagePath: "/pages/myshop/myshop",
            iconPath: "/images/tabbar/icon7.png",
            selectedIconPath: "/images/tabbar/icon8.png",
            text: "我的店铺"
        }],
        userlist: [{
            pagePath: "/pages/mdsy/mdsy",
            iconPath: "/images/tabbar/icon1.png",
            selectedIconPath: "/images/tabbar/icon2.png",
            text: "首页"
        }, {
            pagePath: "/pages/main/main",
            iconPath: "/images/tabbar/icon1.png",
            selectedIconPath: "/images/tabbar/icon2.png",
            text: "商城"
        }, {
            pagePath: "/pages/ddcenter/ddcenter",
            iconPath: "/images/tabbar/icon3.png",
            selectedIconPath: "/images/tabbar/icon4.png",
            text: "购物车"
        }, {
            pagePath: "/pages/mycenter/mycenter",
            iconPath: "/images/tabbar/icon5.png",
            selectedIconPath: "/images/tabbar/icon6.png",
            text: "个人中心"
        }]
    },
 

    methods: {
        switchTab(e) {
            const data = e.currentTarget.dataset
            const url = data.path
            console.log(data,'eee')
            wx.switchTab({
                url
            })
            this.setData({
                selected: data.index
            })
        },
    }
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77

在底部导航onshow添加

    if (typeof this.getTabBar === 'function') {
            this.getTabBar((tabBar) => {
                tabBar.setData({
                    selected: 0  //选择第几个导航
                })
            })
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/101579
推荐阅读
相关标签
  

闽ICP备14008679号