|
|
<template> <view class="tab-bar"> <view v-for="(item,index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)"> <image class="tab_img" :src="currentIndex == index ? item.selectedIconPath : item.iconPath"></image> <view class="tab_text" :style="{color: currentIndex == index ? selectedColor : color}">{{item.text}}</view> </view> </view> </template>
<script> export default { props: { selectedIndex: { // 当前选中的tab index
default: 0 }, }, data() { return { color: "#666666", selectedColor: "#00BAB2", list: [], currentIndex:0, } }, created() { this.currentIndex = this.selectedIndex; var _this = this if (uni.getStorageSync('identify') == 'nurse') { //护士
_this.list = [ { "pagePath": "/pages/tabbar/index/index", "text": "首页", "iconPath": "/static/images/tabbar/sy.png", "selectedIconPath": "/static/images/tabbar/syActive.png" }, { "pagePath": "/pages/tabbar/question/index", "text": "题库", "iconPath": "/static/images/tabbar/tk.png", "selectedIconPath": "/static/images/tabbar/tkActive.png" }, { "pagePath": "/pages/tabbar/mine/index", "text": "我的", "iconPath": "/static/images/tabbar/wd.png", "selectedIconPath": "/static/images/tabbar/wdActive.png" } ] } else { //医管
_this.list = [{ "pagePath": "/pages/tabbar/index/index", "text": "首1页", "iconPath": "/static/images/tabbar/sy.png", "selectedIconPath": "/static/images/tabbar/syActive.png" }, { "pagePath": "/pages/tabbar/question/index", "text": "题2库", "iconPath": "/static/images/tabbar/tk.png", "selectedIconPath": "/static/images/tabbar/tkActive.png" }, { "pagePath": "/pages/tabbar/mine/index", "text": "我3的", "iconPath": "/static/images/tabbar/wd.png", "selectedIconPath": "/static/images/tabbar/wdActive.png" } ] } }, methods: { switchTab(item, index) { this.currentIndex = index; let url = item.pagePath; console.log(url) uni.reLaunch({url:url}) } } } </script>
<style lang="scss"> .tab-bar { position: fixed; bottom: 0; left: 0; right: 0; height: 100rpx; background: white; display: flex; justify-content: center; align-items: center; padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
.tab-bar-item { flex: 1; text-align: center; display: flex; justify-content: center; align-items: center; flex-direction: column; .tab_img { width: 48rpx; height: 48rpx; } .tab_text { font-size: 24rpx; margin-top: 4rpx; } } } </style>
|