<template>
  <aside class="sidebar">
    <ul>
      <li v-for="route in routes" :key="route.path" @click="navigateTo(route.path)">
        <component 
          class="icon" 
          :class="{ active: routeStore.currentRoute === route.path }" 
          :is="route.meta?.icon" 
        />
      </li>
    </ul>
  </aside>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { computed } from 'vue'
import { useRouteStore } from '@/store/route'

const router = useRouter()
const route = useRoute()
const routeStore = useRouteStore()

// 获取所有路由配置
const routes = computed(() => {
  return router.getRoutes().filter(route => !route.meta?.hidden && !route.children?.length)
})

// 导航方法
const navigateTo = (path) => {
  routeStore.updateCurrentRoute(path)
  router.push(path)
}
</script>

<style scoped>
.sidebar {
  width: 60px;
  height: inherit;
  background-color: #f0f0f0;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  box-sizing: border-box;
}

.sidebar ul {
  height: inherit;
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}

.sidebar li {
  height: 60px;
  width: 60px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar li .icon {
  margin: 8px;
  padding: 8px;
  border-radius: 8px;
}

.sidebar li .icon:hover {
  background-color: #e0e0e0;
}

.sidebar li .icon.active {
  color: #07c160;
}
</style> 