BottomNav.vue 3.2 KB
<!--
 * @Date: 2025-03-20 20:36:36
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-12-01 16:14:16
 * @FilePath: /mlaj/src/components/layout/BottomNav.vue
 * @Description: 文件描述
-->
<template>
  <nav class="fixed bottom-0 left-0 right-0 bg-white/70 backdrop-blur-lg border-t border-gray-100 z-50">
    <div class="flex justify-around items-center h-16">
      <div
        v-for="item in navItems"
        :key="item.name"
        @click="handleNavClick(item)"
        class="flex flex-col items-center justify-center w-1/4 h-full cursor-pointer"
        :class="{
          'text-green-500': isActive(item.path),
          'text-gray-500': !isActive(item.path)
        }"
      >
        <svg
          xmlns="http://www.w3.org/2000/svg"
          class="h-6 w-6 mb-1"
          :class="{
            'text-green-500': isActive(item.path),
            'text-gray-500': !isActive(item.path)
          }"
          fill="none"
          viewBox="0 0 24 24"
          stroke="currentColor"
          v-html="item.icon"
        />
        <span class="text-xs">{{ item.name }}</span>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAuth } from '@/contexts/auth'
import { showToast } from 'vant'

const route = useRoute()
const router = useRouter()
const { currentUser } = useAuth()

const navItems = [
  {
    name: '首页',
    path: '/',
    icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />'
  },
  {
    name: '课程',
    path: '/courses',
    icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />'
  },
  {
    name: '活动',
    path: '/activity',
    // icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />'
    icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />'
  },
  {
    name: '我的',
    path: '/profile',
    icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />'
  }
]

const isActive = (path) => {
  return route.path === path || (path !== '/' && route.path.startsWith(path))
}

const handleNavClick = (item) => {
  if (item.path === '/activity') {
    // showToast('功能暂未开放')
    // TODO: 活动页面跳转
    window.open('https://wxm.behalo.cc/pages/activity/activity?token=&user_id=', '_blank')
    return
  }
  if (item.path === '/profile' && !currentUser.value) {
    router.push('/login')
    return
  }
  router.push(item.path)
}
</script>