| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <view class="custom-tabbar">
- <view
- v-for="(item, index) in tabList"
- :key="index"
- class="tab-item"
- :class="{ active: currentTab === item.name }"
- @click="handleTabClick(item)"
- >
- <image
- class="tab-icon"
- :class="{ 'icon-active': currentTab === item.name }"
- :src="item.icon"
- mode="aspectFit"
- />
- <text class="tab-text">{{ item.label }}</text>
- </view>
- </view>
- </template>
- <script setup>
- import { computed } from 'vue'
- import { useI18n } from 'vue-i18n'
- const { t } = useI18n()
- // 定义props
- const props = defineProps({
- currentTab: {
- type: String,
- default: 'home'
- }
- })
- // 底部导航配置
- const tabList = computed(() => [
- {
- name: 'home',
- label: t('common.page.home'),
- icon: '/static/pages/tabbar/home.png',
- url: '/pages/home/index'
- },
- {
- name: 'scan',
- label: t('common.page.scan'),
- icon: '/static/pages/tabbar/scan.png',
- url: '/pages/scan/index'
- },
- {
- name: 'mine',
- label: t('common.page.mine'),
- icon: '/static/pages/tabbar/mine.png',
- url: '/pages/my/index'
- }
- ])
- // 处理tab点击
- const handleTabClick = (item) => {
- if (props.currentTab === item.name) return
-
- // 使用reLaunch跳转,清空页面栈
- uni.reLaunch({
- url: item.url
- })
- }
- </script>
- <style lang="scss" scoped>
- .custom-tabbar {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- height: 100rpx;
- background-color: #ffffff;
- display: flex;
- border-top: 1rpx solid #e5e5e5;
- padding-bottom: env(safe-area-inset-bottom);
- z-index: 1000;
-
- .tab-item {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 8rpx 0;
- transition: all 0.3s ease;
-
- .tab-icon {
- width: 48rpx;
- height: 48rpx;
- margin-bottom: 4rpx;
- transition: all 0.3s ease;
-
- &.icon-active {
- filter: brightness(0) saturate(100%) invert(68%) sepia(48%) saturate(1234%) hue-rotate(134deg) brightness(91%) contrast(92%);
- transform: scale(1.1);
- }
- }
-
- .tab-text {
- font-size: 20rpx;
- color: #666666;
- transition: color 0.3s ease;
- }
-
- &.active {
- .tab-text {
- color: #1ec9c9;
- font-weight: 500;
- }
- }
-
- &:active {
- opacity: 0.8;
- }
- }
- }
- </style>
|