<template>
  <div class="bread flex">
    <div class="flex">
      <div
        v-for="(item, index) in breadList"
        :class="['item', '', currentPath === item.path ? 'active' : '']"
        :key="item.path"
      >
        {{ item.name }} <span class="split" v-if="index + 1 < breadList.length">/</span>
      </div>
    </div>

    <div class="right flex">
      <div class="username cp" @click="toUserInfo">{{ userName }}</div>
      <img class="cp" src="@/assets/images/login/logout.png" alt="" @click="logout" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import utils from '@/utils'
const route = useRoute()
const router = useRouter()
const currentPath = computed(() => {
  return route.path
})

const userName = computed(() => {
  return utils.getKey('userInfo')?.name
})

const breadList = computed(() => {
  return route.matched.filter((item) => {
    return item.path !== '/home'
  })
})

const logout = () => {
  router.push('/login')
}

const toUserInfo = () => {
  router.push('/userInfo')
}
</script>

<style scoped lang="less">
.bread {
  height: 100%;
  width: 100%;
  color: #9999;
  padding-top: 32px;
  padding-right: 24px;
  font-size: 20px;
  font-weight: 500;
  justify-content: space-between;
  .active {
    color: #333333;
  }
  .split {
    margin: 0 10px;
  }
  .right {
    color: #333;
    .username {
      font-size: 16px;
    }
    img {
      width: 20px;
      height: 20px;
      margin-left: 40px;
    }
  }
}
</style>
