通过微信开发者工具 商城模板 创建新小程序
This commit is contained in:
		
							
								
								
									
										22
									
								
								mini-program/custom-tab-bar/data.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								mini-program/custom-tab-bar/data.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
export default [
 | 
			
		||||
  {
 | 
			
		||||
    icon: 'home',
 | 
			
		||||
    text: '首页',
 | 
			
		||||
    url: 'pages/home/home',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    icon: 'sort',
 | 
			
		||||
    text: '分类',
 | 
			
		||||
    url: 'pages/goods/category/index',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    icon: 'cart',
 | 
			
		||||
    text: '购物车',
 | 
			
		||||
    url: 'pages/cart/index',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    icon: 'person',
 | 
			
		||||
    text: '个人中心',
 | 
			
		||||
    url: 'pages/usercenter/index',
 | 
			
		||||
  },
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										29
									
								
								mini-program/custom-tab-bar/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								mini-program/custom-tab-bar/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
import TabMenu from './data';
 | 
			
		||||
Component({
 | 
			
		||||
  data: {
 | 
			
		||||
    active: 0,
 | 
			
		||||
    list: TabMenu,
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  methods: {
 | 
			
		||||
    onChange(event) {
 | 
			
		||||
      this.setData({ active: event.detail.value });
 | 
			
		||||
      wx.switchTab({
 | 
			
		||||
        url: this.data.list[event.detail.value].url.startsWith('/')
 | 
			
		||||
          ? this.data.list[event.detail.value].url
 | 
			
		||||
          : `/${this.data.list[event.detail.value].url}`,
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    init() {
 | 
			
		||||
      const page = getCurrentPages().pop();
 | 
			
		||||
      const route = page ? page.route.split('?')[0] : '';
 | 
			
		||||
      const active = this.data.list.findIndex(
 | 
			
		||||
        (item) =>
 | 
			
		||||
          (item.url.startsWith('/') ? item.url.substr(1) : item.url) ===
 | 
			
		||||
          `${route}`,
 | 
			
		||||
      );
 | 
			
		||||
      this.setData({ active });
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										8
									
								
								mini-program/custom-tab-bar/index.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								mini-program/custom-tab-bar/index.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
{
 | 
			
		||||
  "component": true,
 | 
			
		||||
  "usingComponents": {
 | 
			
		||||
    "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
 | 
			
		||||
    "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item",
 | 
			
		||||
    "t-icon": "tdesign-miniprogram/icon/icon"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								mini-program/custom-tab-bar/index.wxml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								mini-program/custom-tab-bar/index.wxml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
<t-tab-bar
 | 
			
		||||
 value="{{active}}"
 | 
			
		||||
 bindchange="onChange"
 | 
			
		||||
 split="{{false}}"
 | 
			
		||||
>
 | 
			
		||||
	<t-tab-bar-item
 | 
			
		||||
	 wx:for="{{list}}"
 | 
			
		||||
	 wx:for-item="item"
 | 
			
		||||
	 wx:for-index="index"
 | 
			
		||||
	 wx:key="index"
 | 
			
		||||
	>
 | 
			
		||||
		<view class="custom-tab-bar-wrapper">
 | 
			
		||||
			<t-icon prefix="wr" name="{{item.icon}}" size="48rpx" />
 | 
			
		||||
			<view class="text">{{ item.text }}</view>
 | 
			
		||||
		</view>
 | 
			
		||||
	</t-tab-bar-item>
 | 
			
		||||
</t-tab-bar>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								mini-program/custom-tab-bar/index.wxss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								mini-program/custom-tab-bar/index.wxss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
.custom-tab-bar-wrapper {
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.custom-tab-bar-wrapper .text {
 | 
			
		||||
  font-size: 20rpx;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user