Commit 6ac775ef661885e175b82a7be5b76d8f34ede8e2

Authored by 后端研发-苏泰源
1 parent dfefaaed

自定义tabbar修改

custom-tab-bar/index.js
@@ -5,13 +5,14 @@ Component({ @@ -5,13 +5,14 @@ Component({
5 fontcolor:'#6e6d6b', 5 fontcolor:'#6e6d6b',
6 fontcolor_sele:'#f23030', 6 fontcolor_sele:'#f23030',
7 backgroundColor:'#ffffff', 7 backgroundColor:'#ffffff',
8 - active:-1,  
9 list:app.def_list, 8 list:app.def_list,
10 cartGoodsNum:0, 9 cartGoodsNum:0,
  10 + active: 0,
11 }, 11 },
12 12
13 lifetimes: { 13 lifetimes: {
14 attached: function() { 14 attached: function() {
  15 +
15 var th=this; 16 var th=this;
16 getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{ 17 getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{
17 var dis=rs.data.data; 18 var dis=rs.data.data;
@@ -51,7 +52,8 @@ Component({ @@ -51,7 +52,8 @@ Component({
51 var th=this; 52 var th=this;
52 53
53 var is_read=getApp().globalData.is_read; 54 var is_read=getApp().globalData.is_read;
54 - var custum_data=getApp().globalData.custum_data; 55 + var custum_data=getApp().globalData.custum_data;
  56 +
55 if(is_read){ 57 if(is_read){
56 if(custum_data){ 58 if(custum_data){
57 this.set_list(custum_data); 59 this.set_list(custum_data);
@@ -105,16 +107,33 @@ Component({ @@ -105,16 +107,33 @@ Component({
105 fontcolor:data.fontcolor, 107 fontcolor:data.fontcolor,
106 is_custum:1 108 is_custum:1
107 }) 109 })
108 - 110 + // console.log('abc=======<<<<<', this.data.list);
109 }, 111 },
110 112
111 nav_goto:function(e){ 113 nav_goto:function(e){
  114 + // const data = e.currentTarget.dataset
  115 + // this.setData({
  116 + // active: data.index
  117 + // })
  118 + // console.log('active***********<<<<<', this.data.active);
112 var url=e.currentTarget.dataset.url; 119 var url=e.currentTarget.dataset.url;
113 if(!url) return false; 120 if(!url) return false;
114 if(url[0]!='/') url='/'+url; 121 if(url[0]!='/') url='/'+url;
115 //wx.switchTab({url:url,}) 122 //wx.switchTab({url:url,})
116 getApp().goto(url); 123 getApp().goto(url);
117 - } 124 + },
  125 +
  126 +
  127 + // switchTab(e) {
  128 + // const data = e.currentTarget.dataset
  129 + // const url = data.path
  130 + // wx.switchTab({url})
  131 + // this.setData({
  132 + // selected: data.index
  133 + // })
  134 + // }
  135 +
  136 +
118 137
119 } 138 }
120 139
custom-tab-bar/index.wxml
1 <!-- 如果是自定义的话 --> 1 <!-- 如果是自定义的话 -->
2 <view class="main_bar {{is_custum?'custom':''}}" style=" background: {{backgroundColor}}; font-size: 22rpx;"> 2 <view class="main_bar {{is_custum?'custom':''}}" style=" background: {{backgroundColor}}; font-size: 22rpx;">
3 - <block wx:for="{{list}}" wx:for-index="idx">  
4 - <block wx:if="{{item.nav_name !== '分销' && item.weappurl!= '/pages/distribution/distribution'}}">  
5 - <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"  
6 - style="color: {{active==idx?fontcolor_sele:fontcolor}};">  
7 - <!-- <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"  
8 - style="width:{{100 / list.length}}%;color: {{active==idx?fontcolor_sele:fontcolor}};"> -->  
9 -  
10 - <view class="tab_img">  
11 - <view wx:if="{{item.nav_name=='购物车' && cartGoodsNum != 0}}" class="cart_num" >{{cartGoodsNum}}</view>  
12 - <view class="nav_imgage" style="background-image: url({{active==idx?item.src_sele:item.src}});"></view>  
13 - </view>  
14 - <view>{{item.nav_name}}</view>  
15 - </view>  
16 - </block>  
17 - <!-- 是分销商且没有关闭,可以显示 --> 3 + <block wx:for="{{list}}" wx:for-index="idx">
  4 + <block wx:if="{{item.nav_name !== '分销' && item.weappurl != '/pages/distribution/distribution'}}">
  5 + <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"
  6 + style="color: {{active==idx?fontcolor_sele:fontcolor}};">
  7 + <!-- <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"
  8 + style="width:{{100 / list.length}}%;color: {{active==idx?fontcolor_sele:fontcolor}};"> -->
  9 + <!-- <view class="tabbar_item_wrapper"> -->
  10 + <view class="{{item.specific ? 'tabbar_item_wrapper':''}}" style="background-color: {{item.specific ? item.button_background:'transparent'}};">
  11 + <view class="tab_img">
  12 + <view wx:if="{{item.nav_name=='购物车' && cartGoodsNum != 0}}" class="cart_num" >{{cartGoodsNum}}</view>
  13 + <view class="nav_imgage" style="background-image: url({{active==idx?item.src_sele:item.src}});"></view>
  14 + </view>
  15 + <view>{{item.nav_name}}</view>
  16 + </view>
  17 +
  18 + </view>
  19 + </block>
  20 +
  21 +
  22 + <!-- 是分销商且没有关闭,可以显示 -->
18 <block wx:if="{{(item.nav_name === '分销' || item.weappurl === '/pages/distribution/distribution') && !is_no_distri}}"> 23 <block wx:if="{{(item.nav_name === '分销' || item.weappurl === '/pages/distribution/distribution') && !is_no_distri}}">
19 <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}" 24 <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"
20 style="color: {{active==idx?fontcolor_sele:fontcolor}};"> 25 style="color: {{active==idx?fontcolor_sele:fontcolor}};">
21 <!-- <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}" 26 <!-- <view data-url="{{item.weappurl}}" bindtap="nav_goto" class="tabbar_item" data-act="{{active==idx?1:0}}"
22 style="width:{{100 / list.length}}%;color: {{active==idx?fontcolor_sele:fontcolor}};"> --> 27 style="width:{{100 / list.length}}%;color: {{active==idx?fontcolor_sele:fontcolor}};"> -->
23 - <view class="tab_img">  
24 - <view class="nav_imgage" style="background-image: url({{active==idx?item.src_sele:item.src}});"></view>  
25 - </view>  
26 - <view>{{item.nav_name}}</view>  
27 - </view> 28 + <view class="{{item.specific ? 'tabbar_item_wrapper':''}}" style="background-color: {{item.specific ? item.button_background:'transparent'}};">
  29 + <view class="tab_img">
  30 + <view class="nav_imgage" style="background-image: url({{active==idx?item.src_sele:item.src}});"></view>
  31 + </view>
  32 + <view>{{item.nav_name}}</view>
  33 + </view>
  34 +
  35 + </view>
28 </block> 36 </block>
29 - </block> 37 + </block>
30 </view > 38 </view >
31 39
32 40
custom-tab-bar/index.wxss
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 z-index: 10000; 7 z-index: 10000;
8 display: flex; 8 display: flex;
9 justify-content: space-around; 9 justify-content: space-around;
  10 + align-items: center;
10 height: 100rpx; 11 height: 100rpx;
11 } 12 }
12 .main_bar.custom { 13 .main_bar.custom {
@@ -19,14 +20,14 @@ @@ -19,14 +20,14 @@
19 /* float: left; */ 20 /* float: left; */
20 text-align: center; 21 text-align: center;
21 padding: 0; 22 padding: 0;
22 - display: flex; 23 + /* display: flex; */
23 flex: 1; 24 flex: 1;
24 - flex-direction: column;  
25 - justify-content: center; 25 + /* flex-direction: column; */
  26 + /* justify-content: center; */
26 } 27 }
27 28
28 .tab_img { 29 .tab_img {
29 - display: flex; 30 + /* display: flex; */
30 justify-content: center; 31 justify-content: center;
31 position: relative; 32 position: relative;
32 } 33 }
@@ -39,6 +40,7 @@ @@ -39,6 +40,7 @@
39 /* background-position: center; 40 /* background-position: center;
40 background-repeat: no-repeat; */ 41 background-repeat: no-repeat; */
41 background-size: 100%; 42 background-size: 100%;
  43 + margin: 0 auto;
42 } 44 }
43 45
44 .cart_num { 46 .cart_num {
@@ -55,3 +57,17 @@ @@ -55,3 +57,17 @@
55 right: 34rpx; 57 right: 34rpx;
56 /* margin-right: -70rpx; */ 58 /* margin-right: -70rpx; */
57 } 59 }
  60 +
  61 +.tabbar_item_wrapper {
  62 + background-color: white;
  63 + position: relative;
  64 + width: 120rpx;
  65 + height: 120rpx;
  66 + border-radius: 50%;
  67 + bottom: 14rpx;
  68 + display: flex;
  69 + flex-direction: column;
  70 + justify-content: center;
  71 + margin: 0 auto;
  72 +}
  73 +