BottomNav.vue
5.45 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!--
* @Date: 2025-08-27 17:44:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-22 15:12:13
* @FilePath: /map-demo/src/components/BottomNav.vue
* @Description: 文件描述
-->
<template>
<div v-if="isMiniProgramWebView" class="bottom-nav">
<div
v-for="item in navItems"
:key="item.path"
@click="navigate(item.path)"
:class="['nav-item', isActive(item.path) ? 'nav-item-active' : 'nav-item-inactive']"
>
<img :src="isActive(item.path) ? item.activeIcon : item.icon" class="nav-icon" alt="" />
<span class="nav-label">{{ item.label }}</span>
<!-- <div v-if="isActive(item.path)" class="nav-indicator"></div> -->
</div>
</div>
</template>
<script setup>
import { computed, shallowRef } from 'vue';
import wx from 'weixin-js-sdk'
const homeIcon = 'https://cdn.ipadbiz.cn/lls_prog/icon/home.svg';
const homeIconActive = 'https://cdn.ipadbiz.cn/lls_prog/icon/home_active1.svg';
const rewardsIcon = 'https://cdn.ipadbiz.cn/lls_prog/icon/rewards.svg';
const rewardsIconActive = 'https://cdn.ipadbiz.cn/lls_prog/icon/rewards_active1.svg';
const activitiesIcon = 'https://cdn.ipadbiz.cn/lls_prog/icon/activities.svg';
const activitiesIconActive = 'https://cdn.ipadbiz.cn/lls_prog/icon/activities_active1.svg';
const meIcon = 'https://cdn.ipadbiz.cn/lls_prog/icon/me.svg';
const meIconActive = 'https://cdn.ipadbiz.cn/lls_prog/icon/me_active1.svg';
/**
* 检测是否在小程序web-view环境中
* @returns {boolean} 是否在小程序环境
*/
const isMiniProgramWebView = computed(() => {
return navigator.userAgent.includes('miniProgram');
});
const navItems = shallowRef([
{ path: '/pages/Dashboard/index', icon: homeIcon, activeIcon: homeIconActive, label: '首页' },
{ path: '/pages/ActivitiesCover/index', icon: activitiesIcon, activeIcon: activitiesIconActive, label: '乐在重阳' },
// { path: '/pages/RewardCategories/index', icon: rewardsIcon, activeIcon: rewardsIconActive, label: '兑换' },
// TAG: 暂时写死以后可能会改变
{ path: '/pages/Rewards/index?id=health&category=health', icon: rewardsIcon, activeIcon: rewardsIconActive, label: '兑换' },
{ path: '/pages/Profile/index', icon: meIcon, activeIcon: meIconActive, label: '我的' },
]);
const currentPage = computed(() => {
// const pages = Taro.getCurrentPages();
// return pages.length > 0 ? '/' + pages[pages.length - 1].route : '';
// 默认选中活动页面
return '/pages/ActivitiesCover/index';
});
const isActive = (path) => {
return path.includes(currentPage.value);
};
const navigate = (path) => {
wx.miniProgram.reLaunch({ url: path });
};
</script>
<style scoped>
/* 底部导航容器 */
.bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: white;
border-top: 1px solid #f3f4f6;
display: flex;
justify-content: space-around;
padding: 16rpx 0;
z-index: 50;
/* 基础高度适配 */
min-height: 120rpx;
}
/* 导航项 */
.nav-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 16rpx 40rpx;
position: relative;
cursor: pointer;
transition: all 0.2s ease;
}
/* 激活状态 */
.nav-item-active {
color: #54ABAE;
}
/* 非激活状态 */
.nav-item-inactive {
color: #9CA3AF;
}
/* 图标样式 */
.nav-icon {
width: 52rpx;
height: 52rpx;
transition: transform 0.2s ease;
}
/* 标签样式 */
.nav-label {
font-size: 26rpx;
margin-top: 8rpx;
line-height: 1.2;
}
/* 激活指示器 */
.nav-indicator {
position: absolute;
bottom: -8rpx;
width: 80rpx;
height: 8rpx;
background-color: #2563eb;
border-radius: 4rpx 4rpx 0 0;
}
/* 响应式适配 - 小屏设备 */
@media screen and (max-width: 480px) {
.bottom-nav {
padding: 8px 0;
min-height: 60px;
}
.nav-item {
padding: 8px 16px;
}
.nav-icon {
width: 26px;
height: 26px;
}
.nav-label {
font-size: 13px;
margin-top: 4px;
}
.nav-indicator {
bottom: -4px;
width: 40px;
height: 4px;
border-radius: 2px 2px 0 0;
}
}
/* 响应式适配 - 中等屏幕设备 (平板竖屏) */
@media screen and (min-width: 481px) and (max-width: 768px) {
.bottom-nav {
padding: 12px 0;
min-height: 80px;
}
.nav-item {
padding: 12px 24px;
}
.nav-icon {
width: 53px;
height: 53px;
}
.nav-label {
font-size: 24px;
margin-top: 6px;
}
.nav-indicator {
bottom: -6px;
width: 48px;
height: 5px;
border-radius: 3px 3px 0 0;
}
}
/* 响应式适配 - 大屏设备 (平板横屏/桌面) */
@media screen and (min-width: 769px) {
.bottom-nav {
padding: 16px 0;
min-height: 100px;
}
.nav-item {
padding: 16px 32px;
}
.nav-icon {
width: 62px;
height: 62px;
}
.nav-label {
font-size: 27px;
margin-top: 8px;
}
.nav-indicator {
bottom: -8px;
width: 60px;
height: 6px;
border-radius: 3px 3px 0 0;
}
}
/* 微信小程序环境适配 */
@media screen and (min-device-width: 1024px) {
.bottom-nav {
padding: 20rpx 0;
min-height: 140rpx;
}
.nav-item {
padding: 20rpx 50rpx;
}
.nav-icon {
width: 104rpx;
height: 104rpx;
}
.nav-label {
font-size: 55rpx;
margin-top: 10rpx;
}
.nav-indicator {
bottom: -10rpx;
width: 90rpx;
height: 10rpx;
border-radius: 5rpx 5rpx 0 0;
}
}
/* 悬浮效果 - 仅在非触摸设备上启用 */
@media (hover: hover) {
.nav-item:hover {
transform: translateY(-2px);
}
.nav-item:hover .nav-icon {
transform: scale(1.1);
}
}
</style>