indexNav.vue 2.46 KB
<template>
  <view class="index-nav" :class="[`is-${position}`]">
    <view class="nav-logo" :class="{ 'is-active': active === 'home' }" @tap="() => on_select('home')">
      <image class="nav-icon" :src="icons?.home" mode="aspectFit" />
      <text class="nav-text">首页</text>
    </view>

    <view
      class="nav-logo"
      :class="[{ 'is-active': active === 'code' }, { 'is-center-raised': center_variant === 'raised' }]"
      @tap="() => on_select('code')"
    >
      <image
        class="nav-icon"
        :class="{ 'nav-icon--raised': center_variant === 'raised' }"
        :src="icons?.code"
        mode="aspectFit"
      />
      <view v-if="center_variant === 'raised'" class="nav-icon-placeholder"></view>
      <text class="nav-text">预约码</text>
    </view>

    <view class="nav-logo" :class="{ 'is-active': active === 'me' }" @tap="() => on_select('me')">
      <image class="nav-icon" :src="icons?.me" mode="aspectFit" />
      <text class="nav-text">我的</text>
    </view>
  </view>
</template>

<script setup>
const props = defineProps({
  icons: {
    type: Object,
    default: () => ({})
  },
  active: {
    type: String,
    default: ''
  },
  position: {
    type: String,
    default: 'fixed'
  },
  center_variant: {
    type: String,
    default: 'normal'
  },
  allow_active_tap: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['select'])

const on_select = (key) => {
  if (!props.allow_active_tap && props.active && key === props.active) return
  emit('select', key)
}
</script>

<style lang="less">
.index-nav {
  left: 0;
  bottom: 0;
  width: 750rpx;
  height: 134rpx;
  background: #FFFFFF;
  box-shadow: 0 -10rpx 8rpx 0 rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: #A67939;
  z-index: 99;

  &.is-fixed {
    position: fixed;
  }

  &.is-absolute {
    position: absolute;
  }

  .nav-logo {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .nav-icon {
    width: 48rpx;
    height: 48rpx;
    display: block;

    &.nav-icon--raised {
      width: 130rpx;
      height: 130rpx;
      position: absolute;
      top: -100rpx;
      left: 50%;
      transform: translateX(-50%);
    }
  }

  .nav-icon-placeholder {
    width: 48rpx;
    height: 48rpx;
  }

  .nav-text {
    font-size: 24rpx;
    margin-top: 12rpx;
    line-height: 1;
  }

  .nav-logo.is-center-raised {
    .nav-text {
      margin-top: -10rpx;
    }
  }
}
</style>