dao-guan-tab-bar.vue 2.95 KB
<template>
  <view class="dao-guan-tab-bar">
    <image
      v-if="currentIndex >= 0"
      :src="config.baseUrl_api + '/fs/static/img/toolbar.png'"
      class="dg-tab-bar-bg"
      mode="scaleToFill"
      :style="{ left: tabBgLeft }"
    ></image>
    <view
      v-for="(item, index) in tabs"
      :key="index"
      class="dg-tab-item"
      :class="{ active: currentIndex === index }"
      @click="handleClick(index, item.url)"
    >
      <image :src="currentIndex === index ? item.activeIcon : item.icon" class="dg-tab-icon"></image>
      <text class="dg-tab-text">{{ item.text }}</text>
    </view>
  </view>
</template>

<script setup>
import config from '@/config.js'
import { computed, ref } from 'vue'

const props = defineProps({
  currentIndex: {
    type: Number,
    default: 0
  }
})

const emit = defineEmits(['switch'])
const switching = ref(false)

const tabs = [
  { text: '人员', url: '/pages/index/daoGuanPerson', icon: config.baseUrl_api + '/fs/static/img/tool01.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool01_dwn.png' },
  { text: '订单', url: '/pages/index/daoGuanOrder', icon: config.baseUrl_api + '/fs/static/img/tool02.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool02_dwn.png' },
  { text: '通知', url: '/pages/index/daoGuanNotice', icon: config.baseUrl_api + '/fs/static/img/tool03.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool03_dwn.png' },
  { text: '级位', url: '/pages/index/daoGuanLevel', icon: config.baseUrl_api + '/fs/static/img/tool04.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool04_dwn.png' },
  { text: '我的', url: '/pages/index/daoGuanMy', icon: config.baseUrl_api + '/fs/static/img/tool05.png', activeIcon: config.baseUrl_api + '/fs/static/img/tool05_dwn.png' },
]

const tabBgLeft = computed(() => {
  if (props.currentIndex < 0) return '0'
  return `${props.currentIndex * 20}%`
})

const handleClick = (index, url) => {
  if (switching.value || index === props.currentIndex) return

  switching.value = true
  emit('switch', index, url)

  uni.redirectTo({
    url,
    fail: () => {
      switching.value = false
    }
  })
}
</script>

<style lang="scss" scoped>
.dao-guan-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 9999;
  background-color: #d9d9d9;
  overflow: hidden;
}

.dg-tab-bar-bg {
  position: absolute;
  top: 0rpx;
  width: 20%;
  height: calc(100% - 35rpx);
  z-index: 0;
  transition: left 0.3s ease;
  pointer-events: none;
}

.dg-tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 20%;
  height: 100%;
  position: relative;
  z-index: 1;
}

.dg-tab-icon {
  width: 50rpx;
  height: 50rpx;
  margin-bottom: 4rpx;
}

.dg-tab-text {
  font-size: 20rpx;
  color: #666;
}

.dg-tab-item.active .dg-tab-text {
  color: #C30D23;
  font-weight: bold;
}
</style>