按官方封装tabbar

master
xuWorkEmai 3 years ago
parent 8f08d0b56e
commit b2a4997abd

@ -2,8 +2,6 @@
import fetch from './utils/request'
App({
onLaunch() {
// 隐藏原生的tabbar
wx.hideTabBar()
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())

@ -1,6 +1,5 @@
{
"pages": [
"pages/start/index",
"pages/home/index",
"pages/shequ/index",
"pages/add/index",
@ -8,7 +7,8 @@
"pages/mine/index",
"pages/list/list",
"pages/info/info",
"pages/intro/intro"
"pages/intro/intro",
"pages/start/index"
],
"requiredPrivateInfos": [
"getLocation",
@ -26,40 +26,27 @@
"navigationBarTextStyle": "black"
},
"tabBar": {
"custom":true,
"custom": true,
"list": [
{
"pagePath": "pages/home/index",
"text": "营地",
"iconPath":"iamges/营地.png",
"selectedIconPath": "iamges/营地-变.png"
"text": "营地"
},
{
"pagePath": "pages/shequ/index",
"text": "社区",
"iconPath": "iamges/社区.png",
"selectedIconPath": "iamges/社区-变.png"
"text": "社区"
},
{
"pagePath": "pages/add/index",
"text": "",
"iconPath": "iamges/新增.png"
"text": "发布"
},
{
"pagePath": "pages/activity/index",
"text": "活动",
"iconPath": "iamges/活动.png",
"selectedIconPath": "iamges/活动-变.png"
"text": "活动"
},
{
"pagePath": "pages/mine/index",
"text": "我的",
"iconPath": "iamges/我的.png",
"selectedIconPath": "iamges/我的-变.png"
"text": "我的"
}
]
},
@ -69,9 +56,10 @@
"van-icon": "@vant/weapp/icon/index",
"van-popup": "@vant/weapp/popup/index",
"van-picker": "@vant/weapp/picker/index",
"my-tarBar":"/tabBar/index",
"van-row": "@vant/weapp/row/index",
"van-col": "@vant/weapp/col/index"
"van-col": "@vant/weapp/col/index",
"van-tabbar": "@vant/weapp/tabbar/index",
"van-tabbar-item": "@vant/weapp/tabbar-item/index"
},
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"

@ -0,0 +1,65 @@
// custom-tab-bar/index.js
import bit64Iamges from '../iamges/bit64.js'
Component({
/**
* 组件的属性列表
*/
options: {
styleIsolation: 'isolated'
},
properties: {
},
/**
* 组件的初始数据
*/
data: {
active: null,
tabbarList:[
{
name:'营地',
path:'home',
defaultIcon:bit64Iamges[0].iconPath,
activeIcon:bit64Iamges[0].selectedIconPath
},
{
name:'社区',
path:'shequ',
defaultIcon:bit64Iamges[1].iconPath,
activeIcon:bit64Iamges[1].selectedIconPath
},
{
path:'add',
defaultIcon:bit64Iamges[2].iconPath
},
{
name:'活动',
path:'activity',
defaultIcon:bit64Iamges[3].iconPath,
activeIcon:bit64Iamges[3].selectedIconPath
},
{
name:'我的',
path:'mine',
defaultIcon:bit64Iamges[4].iconPath,
activeIcon:bit64Iamges[4].selectedIconPath
},
],
},
/**
* 组件的方法列表
*/
methods: {
cilckSwitchTab(event) {
let path = event.currentTarget.dataset.path.path
// console.log(path)
if(path == 'add') return
wx.switchTab({
url: `/pages/${path}/index`,
})
},
}
})

@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

@ -0,0 +1,9 @@
<!--custom-tab-bar/index.wxml-->
<view class="tabbar">
<view class="tabbar-item" wx:for="{{tabbarList}}" wx:key="index" bindtap="cilckSwitchTab" data-path="{{item}}">
<view class="tabbar-iocn" >
<image src="{{active == index? item.activeIcon:item.defaultIcon }}" mode="aspectFit"></image>
</view>
<view class="tabbar-title">{{item.name}}</view>
</view>
</view>

@ -0,0 +1,52 @@
/* custom-tab-bar/index.wxss */
.tabbar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
/* height: 115rpx; */
background: #fff;
box-sizing: border-box;
padding-bottom: env(safe-area-inset-bottom);
display: flex;
}
.tabbar-item{
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.tabbar-iocn{
height: 42rpx;
width: 42rpx;
margin:17rpx 0;
}
.tabbar-title{
font-size: 23rpx;
font-family: "Alibaba-PuHuiTi-Regular.otf";
font-weight: 400;
color: #636662;
}
.tabbar-iocn image{
height: 100%;
width: 100%;
display: block;
}
.tabbar-item:nth-child(3){
flex: 0.7;
position: relative;
background-color: white;
top: -30rpx;
border-radius: 50%;
}
.tabbar-item:nth-child(3) .tabbar-iocn{
width: 80%;
height: 80%;
margin: 0 ;
border-radius: 50%;
}
.tabbar-item:nth-child(3) .tabbar-iocn image{
height: 100%;
width: 100%;
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

@ -6,7 +6,6 @@ Page({
* 页面的初始数据
*/
data: {
activeIdx:3
},
/**
@ -27,6 +26,9 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.getTabBar().setData({
active:3
})
},
/**

@ -1,3 +1,2 @@
<!--pages/activity/index.wxml-->
<text>待开发中....</text>
<my-tarBar activeIdx="{{activeIdx}}"></my-tarBar>

@ -291,19 +291,19 @@ Page({
nowScale: 8.8,
key: 'TYBBZ-A2AKV-MLZPW-UFNQI-HKNVE-BEFZH',
style: 1,
activeIdx: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 实例化API核心类
qqmapsdk = new QQMapWX({
key: 'CECBZ-55LCW-TSYR7-O4UGV-75DE7-2JBQH',
});
this.getWeatherData()
// 请求面数据
// // 请求面数据
this.getMian('nanjing')
},
getMapZuobiao(e) {
@ -577,6 +577,9 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.getTabBar().setData({
active:0
})
var markers = this.data.pointMarkers.concat(this.data.shuMarkers)
this.setData({
markers: markers

@ -61,5 +61,3 @@
module.exports.getArr = getArr;
</wxs>
<!-- 底部导航条 -->
<my-tarBar activeIdx="{{activeIdx}}"></my-tarBar>

@ -6,7 +6,6 @@ Page({
* 页面的初始数据
*/
data: {
activeIdx:4
},
/**
@ -27,6 +26,9 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.getTabBar().setData({
active:4
})
},
/**

@ -1,3 +1,2 @@
<!--pages/mine/index.wxml-->
<text>待开发中....</text>
<my-tarBar activeIdx="{{activeIdx}}"></my-tarBar>

@ -6,14 +6,13 @@ Page({
* 页面的初始数据
*/
data: {
activeIdx:1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
@ -27,6 +26,9 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.getTabBar().setData({
active:1
})
},
/**

@ -1,3 +1,2 @@
<!--pages/shequ/index.wxml-->
<text>待开发中....</text>
<my-tarBar activeIdx="{{activeIdx}}"></my-tarBar>
<text>待开发中....</text>
Loading…
Cancel
Save