BottomNav.vue
3.03 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
<!--
* @Date: 2025-08-27 17:44:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-28 13:36:05
* @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="item.icon" :class="['nav-icon', isActive(item.path) ? 'filter-blue' : 'filter-gray']" 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'
import homeIcon from '@images/icons/home.svg';
import rewardsIcon from '@images/icons/rewards.svg';
import activitiesIcon from '@images/icons/activities.svg';
import meIcon from '@images/icons/me.svg';
/**
* 检测是否在小程序web-view环境中
* @returns {boolean} 是否在小程序环境
*/
const isMiniProgramWebView = computed(() => {
return navigator.userAgent.includes('miniProgram');
});
const navItems = shallowRef([
{ path: '/pages/Dashboard/index', icon: homeIcon, label: '首页' },
{ path: '/pages/Activities/index', icon: activitiesIcon, label: '活动' },
{ path: '/pages/RewardCategories/index', icon: rewardsIcon, label: '兑换' },
{ path: '/pages/Profile/index', icon: meIcon, label: '我的' },
]);
const currentPage = computed(() => {
// const pages = Taro.getCurrentPages();
// return pages.length > 0 ? '/' + pages[pages.length - 1].route : '';
// 默认选中活动页面
return '/pages/Activities/index';
});
const isActive = (path) => {
return currentPage.value === path;
};
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: 8px 0;
z-index: 50;
}
/* 导航项 */
.nav-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 8px 20px;
position: relative;
}
/* 激活状态 */
.nav-item-active {
color: #2563eb;
}
/* 非激活状态 */
.nav-item-inactive {
color: #6b7280;
}
/* 图标样式 */
.nav-icon {
width: 26px;
height: 26px;
}
/* 标签样式 */
.nav-label {
font-size: 13px;
margin-top: 4px;
}
/* 激活指示器 */
.nav-indicator {
position: absolute;
bottom: -4px;
width: 40px;
height: 4px;
background-color: #2563eb;
border-radius: 2px 2px 0 0;
}
/* 图标滤镜 */
.filter-blue {
filter: brightness(0) saturate(100%) invert(22%) sepia(100%) saturate(3441%) hue-rotate(229deg) brightness(101%) contrast(101%);
}
.filter-gray {
filter: brightness(0) saturate(100%) invert(91%) sepia(6%) saturate(394%) hue-rotate(201deg) brightness(50%) contrast(92%);
}
</style>