支付寶小程序重寫底部tabbar

支付寶小程序

  1. app.js中代碼如下
 editTabBar: function () {
    var e = this.globalData.tabbar, a = getCurrentPages(), t = a[a.length - 1], s = t.route;
    console.log(t)
    console.log(s)
    0 != s.indexOf("/") && (s = "/" + s);
    for (var n in e.items) e.items[n].selected = !1, e.items[n].pagePath == s && (e.items[n].selected = !0);
    t.setData({
      tabbar: e
    });
  },
  globalData: {
    userInfo: null,
    //配置tabbar
    tabbar: {
      textColor: "#333",
      selectedColor: "#d0501f",
      backgroundColor: "#ffffff",
      borderStyle: "#d5d5d5",
      items: [{
        pagePath: "/pages/seller/gzt/gzt",
        name: "工作臺",
        icon: "/pages/icon/index.png",
        activeIcon: "/pages/icon/index_1.png",
        selected: !0
       },{
        pagePath: "/pages/seller/shezhi/shezhi",
        name: "設置",
        icon: "/pages/images/[email protected]",
        activeIcon: "/pages/images/xzsz.png",
        selected: !1
      }],
      position: "bottom"
    }
  }
  1. template.axml代碼如下
<template name="tabbar">
    <view class="tabbar_box" style="background-color:{{tabbar.backgroundColor}}; border-top-color:{{tabbar.borderStyle}}; {{tabbar.position=='top'?'top:0':'bottom:0'}}">
        <navigator class="tabbar_nav" openType="redirect" style="width:{{1/tabbar.items.length*100}}%; color:{{item.selected?tabbar.selectedColor:tabbar.textColor}}" url="{{item.pagePath}}" a:for="{{tabbar.items}}" a:key="index">
            <image class="tabbar_icon" src="{{item.selected?item.activeIcon:item.icon}}"></image>
            <text>{{item.name}}</text>
        </navigator>
    </view>
</template>
  1. template.acssl代碼如下
 .tabbar_box {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-direction: row;
    flex-direction: row;
    -ms-flex-pack: distribute;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 999;
    width: 100%;
    height: 100rpx;
    border-top: 0.5rpx solid #d5d5d5;
}

.tabbar_nav {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 25rpx;
    height: 100%;
}

.tabbar_icon {
    width: 40rpx;
    height: 40rpx;
}

4.在需要引入的頁面(.axml)中

 - <import src="../template.axml"></import>
<template is="tabbar" data="{{tabbar:tabbar}}"></template>

5.在需要引入的樣式(acss)中

@import "../template.acss";

6.在需要引入的js中

  var app=getApp();  //放在頂部
  tabbar:{},         //放在data中
  app.editTabBar();  //放在onLoad中
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章