123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <template>
- <view class="tab_bar">
- <view class="tabbarBox">
- <view class="handleBox" v-for="(item) in tabBarList" :key="item.key + 'tab_bar'">
- <view class="menuBox" @click="goPages(item)">
- <view class="menuIcon">
- <view class="message-style" v-if="item.key === 'chat' && messageCount > 0">{{ messageCount }}
- </view>
- <image v-if="item.key != selectIndex" class="img" :src="item.iconPath"></image>
- <image v-else class="img" :src="item.selectedIconPath"></image>
- </view>
- <view class="menuName">
- <text :class="item.key == selectIndex ? 'TextColor' : 'Text'">{{ item.text }}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { onMounted } from 'vue';
- import store from '@/store'
- export default {
- props: {
- page: {
- type: String,
- default: "home"
- }
- },
- watch: {
- page: {
- handler(value) {
- console.log('value', value);
- this.selectIndex = value;
- },
- immediate: true,
- deep: true
- }
- },
- data() {
- return {
- selectIndex: null,
- userType: uni.getStorageSync('userType'), //读取本地存储
- messageCount: store.state.user.messageCount
- }
- },
- computed: {
- //获取当前页面
- tabBarList() {
- if (this.userType === 1) {
- return [
- {
- "pagePath": "/pages/index",
- "iconPath": "/static/images/tabbar/home.png",
- "selectedIconPath": "/static/images/tabbar/home_.png",
- "text": "首页",
- key: 'home'
- },
- {
- "pagePath": "/pages/mallMenu",
- "iconPath": "/static/images/tabbar/class.png",
- "selectedIconPath": "/static/images/tabbar/class_.png",
- "text": "分类",
- key: 'class'
- },
- {
- "pagePath": "/pages/chat",
- "iconPath": "/static/images/tabbar/class.png",
- "selectedIconPath": "/static/images/tabbar/class_.png",
- "text": "消息",
- key: 'chat'
- },
- {
- "pagePath": "/pages/classify",
- "iconPath": "/static/images/tabbar/work.png",
- "selectedIconPath": "/static/images/tabbar/work_.png",
- "text": "订单",
- key: 'order'
- },
- {
- "pagePath": "/pages/mine",
- "iconPath": "/static/images/tabbar/mine.png",
- "selectedIconPath": "/static/images/tabbar/mine_.png",
- "text": "我的",
- key: 'mine'
- }
- ]
- }
- return [
- {
- "pagePath": "/pages/index",
- "iconPath": "/static/images/tabbar/home.png",
- "selectedIconPath": "/static/images/tabbar/home_.png",
- "text": "首页",
- key: 'home'
- },
- {
- "pagePath": "/pages/mallMenu",
- "iconPath": "/static/images/tabbar/class.png",
- "selectedIconPath": "/static/images/tabbar/class_.png",
- "text": "分类",
- key: 'class'
- },
- // {
- // "pagePath": "/pages/release",
- // "iconPath": "/static/images/tabbar/class.png",
- // "selectedIconPath": "/static/images/tabbar/class_.png",
- // "text": "发布",
- // key:'release'
- // },
- {
- "pagePath": "/pages/chat",
- "iconPath": "/static/images/tabbar/class.png",
- "selectedIconPath": "/static/images/tabbar/class_.png",
- "text": "消息",
- key: 'chat'
- },
- {
- "pagePath": "/pages/classify",
- "iconPath": "/static/images/tabbar/work.png",
- "selectedIconPath": "/static/images/tabbar/work_.png",
- "text": "订单",
- key: 'order'
- },
- {
- "pagePath": "/pages/mine",
- "iconPath": "/static/images/tabbar/mine.png",
- "selectedIconPath": "/static/images/tabbar/mine_.png",
- "text": "我的",
- key: 'mine'
- }
- ]
- }
- },
- //uniapp子组件不支持应用生命周期,所以只能用vue生命周期
- created() {
- },
- onMounted() {
- },
- methods: {
- //进入tabble页
- goPages(page) {
- console.log('page,index', page);
- uni.switchTab({
- url: page.pagePath
- })
- },
- },
- }
- </script>
- <style lang="scss">
- .tab_bar {
- width: 100vw;
- height: 160rpx;
- position: fixed;
- bottom: 0rpx;
- /* 模糊大小就是靠的blur这个函数中的数值大小 */
- // backdrop-filter: blur(10px);
- // border-radius: 60rpx;
- background-color: #fff;
- .tabbarBox {
- display: flex;
- margin-top: 20rpx;
- 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-weight: 900;
- }
- .TextColor {
- @extend .Text;
- color: #d81e06;
- }
- .menuIcon {
- position: relative;
- }
- .message-style {
- background: rgba(239, 68, 68, 1);
- color: #fff;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 20px;
- height: 20px;
- border-radius: 20px;
- position: absolute;
- right: 0;
- z-index: 3;
- }
- </style>
|