7 changed files with 366 additions and 252 deletions
@ -0,0 +1,130 @@ |
|||||
|
<template> |
||||
|
<view class="tab_bar"> |
||||
|
<view class="tabbarBox"> |
||||
|
<view class="handleBox" v-for="(item,index) in tabBarList" :key="index"> |
||||
|
<view class="menuBox" @click="goPages(item.pageIndex)"> |
||||
|
<view class="menuIcon"> |
||||
|
<image v-if="item.type!=selectIndex" class="img" :src="item.iconPath"></image> |
||||
|
<image v-else class="img" :src="item.selectIconPath"></image> |
||||
|
</view> |
||||
|
<view class="menuName"> |
||||
|
<text :class="item.type==selectIndex?'TextColor':'Text'" >{{item.tabbarName}}</text> |
||||
|
</view> |
||||
|
</view> |
||||
|
</view> |
||||
|
</view> |
||||
|
|
||||
|
</view> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
props: { |
||||
|
page: { |
||||
|
type: String, |
||||
|
default: "homeIndex" |
||||
|
} |
||||
|
}, |
||||
|
watch: { |
||||
|
page: { |
||||
|
handler(value) { |
||||
|
this.selectIndex = value; |
||||
|
}, |
||||
|
immediate: true, |
||||
|
deep: true |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
selectIndex: "", |
||||
|
tabBarList: [], |
||||
|
} |
||||
|
|
||||
|
}, |
||||
|
//uniapp子组件不支持应用生命周期,所以只能用vue生命周期 |
||||
|
created() { |
||||
|
|
||||
|
//tabbar数据,这儿也支持后台定义通过接口获取数据 |
||||
|
// this.tabBarList = [{ |
||||
|
// "tabbarName":"", //tababr名称 |
||||
|
// "iconPath":"", //tabbar icon |
||||
|
// "selectIconPath":"", //tabbar 选择icon |
||||
|
// "pageIndex":"" //页面路径 |
||||
|
// }] |
||||
|
this.listTabbar(); |
||||
|
},methods: { |
||||
|
listTabbar() { |
||||
|
this.$api.listTabbar({}) |
||||
|
.then(res => { |
||||
|
console.log(res) |
||||
|
for (var i = 0; i < res.data.length; i++) { |
||||
|
if (res.data[i].hide == 1) { |
||||
|
this.tabBarList.push({ |
||||
|
"tabbarName": res.data[i].title, |
||||
|
"iconPath": res.data[i].selectedIconPath, |
||||
|
"selectIconPath": res.data[i].selectedIconPath, |
||||
|
"pageIndex": res.data[i].pagePath, |
||||
|
"type": res.data[i].type |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}).catch((e) => console.log(e)); //捕获异常 |
||||
|
}, |
||||
|
//进入tabble页 |
||||
|
goPages(pageIndex) { |
||||
|
uni.switchTab({ |
||||
|
url:"/"+pageIndex |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
}, |
||||
|
} |
||||
|
</script> |
||||
|
<style lang="scss"> |
||||
|
.tab_bar { |
||||
|
width: 100vw; |
||||
|
height: 120rpx; |
||||
|
position: fixed; |
||||
|
bottom: 30rpx; |
||||
|
/* 模糊大小就是靠的blur这个函数中的数值大小 */ |
||||
|
backdrop-filter: blur(10px); |
||||
|
border-radius: 60rpx; |
||||
|
|
||||
|
.tabbarBox { |
||||
|
display: flex; |
||||
|
margin-top: 10rpx; |
||||
|
justify-content: space-evenly; |
||||
|
|
||||
|
|
||||
|
.handleBox { |
||||
|
width: 20vw; |
||||
|
height: 110rpx; |
||||
|
|
||||
|
|
||||
|
.menuBox { |
||||
|
padding: 0rpx 20rpx; |
||||
|
width: 120rpx; |
||||
|
height: 98%; |
||||
|
text-align: center; |
||||
|
|
||||
|
.img { |
||||
|
width: 50rpx; |
||||
|
height: 50rpx; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.Text { |
||||
|
font-size: 24rpx; |
||||
|
font-family: Cochin, serif; |
||||
|
font-weight: 900; |
||||
|
} |
||||
|
|
||||
|
.TextColor { |
||||
|
@extend .Text; |
||||
|
color: #d81e06; |
||||
|
} |
||||
|
|
||||
|
</style> |
||||
Loading…
Reference in new issue