BottomNav.vue
2.28 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
<!--
* @Date: 2025-08-27 17:44:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-29 11:35:46
* @FilePath: /lls_program/src/components/BottomNav.vue
* @Description: 文件描述
-->
<template>
<view class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-100 flex justify-around py-2 z-50">
<view
v-for="item in navItems"
:key="item.path"
@click="navigate(item.path)"
:class="['flex flex-col items-center py-2 px-5', isActive(item.path) ? 'icon-text-color-active' : 'icon-text-color-default']"
>
<image :src="isActive(item.path) ? item.activeIcon : item.icon" class="w-6 h-6" />
<span class="text-xs mt-1">{{ item.label }}</span>
<!-- <view v-if="isActive(item.path)" class="absolute bottom-0 w-10 h-1 bg-blue-600 rounded-t-full"></view> -->
</view>
</view>
</template>
<script setup>
import { computed, shallowRef } from 'vue';
import Taro from '@tarojs/taro';
import homeIcon from '@/assets/images/icon/home.svg';
import homeIconActive from '@/assets/images/icon/home_active.svg';
import rewardsIcon from '@/assets/images/icon/rewards.svg';
import rewardsIconActive from '@/assets/images/icon/rewards_active.svg';
import activitiesIcon from '@/assets/images/icon/activities.svg';
import activitiesIconActive from '@/assets/images/icon/activities_active.svg';
import meIcon from '@/assets/images/icon/me.svg';
import meIconActive from '@/assets/images/icon/me_active.svg';
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: '兑换' },
{ 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 : '';
});
const isActive = (path) => {
return currentPage.value === path;
};
const navigate = (path) => {
Taro.reLaunch({ url: path });
};
</script>
<style>
.icon-text-color-active {
color: #4A90E2;
}
.icon-text-color-default {
color: #9CA3AF;
}
</style>