BottomNav.vue
2.91 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
<!--
* @Date: 2025-08-27 17:44:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-15 11:35:20
* @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';
//
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';
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 : '';
});
const isActive = (path) => {
return path.includes(currentPage.value);
};
const navigate = (path) => {
// 获取当前页面栈
const pages = Taro.getCurrentPages()
const currentPage = pages[pages.length - 1]
const currentRoute = currentPage?.route || ''
// 在 Welcome 页面屏蔽掉跳转按钮
if (currentRoute === 'pages/Welcome/index' && path === '/pages/Dashboard/index') {
return
} else {
Taro.redirectTo({ url: path });
}
};
</script>
<style lang="less">
.icon-text-color-active {
color: var(--color-primary);
}
.icon-text-color-default {
color: var(--color-text);
}
</style>