dao-guan-tab-bar.vue
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<template>
<view class="dao-guan-tab-bar">
<image
v-if="currentIndex >= 0"
:src="config.baseUrl_api + '/fs/static/img/toolbar.png'"
class="dg-tab-bar-bg"
mode="scaleToFill"
:style="{ left: tabBgLeft }"
></image>
<view
v-for="(item, index) in tabs"
:key="index"
class="dg-tab-item"
:class="{ active: currentIndex === index }"
@click="handleClick(index, item.url)"
>
<image :src="currentIndex === index ? item.activeIcon : item.icon" class="dg-tab-icon"></image>
<text class="dg-tab-text">{{ item.text }}</text>
</view>
</view>
</template>
<script setup>
import config from '@/config.js'
import { computed, ref } from 'vue'
const props = defineProps({
currentIndex: {
type: Number,
default: 0
}
})
const emit = defineEmits(['switch'])
const switching = ref(false)
const tabs = [
{ text: '人员', url: '/pages/index/daoGuanPerson', icon: config.baseUrl_api + '/fs/static/img/tool01.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool01_dwn.png' },
{ text: '订单', url: '/pages/index/daoGuanOrder', icon: config.baseUrl_api + '/fs/static/img/tool02.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool02_dwn.png' },
{ text: '通知', url: '/pages/index/daoGuanNotice', icon: config.baseUrl_api + '/fs/static/img/tool03.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool03_dwn.png' },
{ text: '级位', url: '/pages/index/daoGuanLevel', icon: config.baseUrl_api + '/fs/static/img/tool04.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool04_dwn.png' },
{ text: '我的', url: '/pages/index/daoGuanMy', icon: config.baseUrl_api + '/fs/static/img/tool05.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool05_dwn.png' },
]
const tabBgLeft = computed(() => {
if (props.currentIndex < 0) return '0'
return `${props.currentIndex * 20}%`
})
const handleClick = (index, url) => {
if (switching.value || index === props.currentIndex) return
switching.value = true
emit('switch', index, url)
uni.redirectTo({
url,
fail: () => {
switching.value = false
}
})
}
</script>
<style lang="scss" scoped>
.dao-guan-tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 120rpx;
display: flex;
justify-content: flex-start;
align-items: stretch;
padding-bottom: env(safe-area-inset-bottom);
z-index: 9999;
background-color: #d9d9d9;
overflow: hidden;
}
.dg-tab-bar-bg {
position: absolute;
top: 0rpx;
width: 20%;
height: calc(100% - 35rpx);
z-index: 0;
transition: left 0.3s ease;
pointer-events: none;
}
.dg-tab-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 20%;
height: 100%;
position: relative;
z-index: 1;
}
.dg-tab-icon {
width: 50rpx;
height: 50rpx;
margin-bottom: 4rpx;
}
.dg-tab-text {
font-size: 20rpx;
color: #666;
}
.dg-tab-item.active .dg-tab-text {
color: #C30D23;
font-weight: bold;
}
</style>