<!--
 * @Author: xiejiang
 * @Date: 2024-11-11 09:38:40
 * @LastEditors: xiejiang
 * @LastEditTime: 2024-11-29 16:56:48
 * @Description: 
 * Copyright（c）2024 by 好老师教育科技有限公司 All right Reserved.
-->
<template>
  <div class="breadcrumb-box">
    <t-breadcrumb>
      <transition-group name="breadcrumb">
        <t-breadcrumb-item v-for="(item, index) in breadcrumbList" :key="index">
          <div
            class="t-breadcrumb__inner"
            :class="[item.name ? 'is-link' : '']"
            @click="onBreadcrumbClick(item, index)"
          >
            <span class="breadcrumb-title">{{ item.title }}</span>
          </div>
        </t-breadcrumb-item>
      </transition-group>
    </t-breadcrumb>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/modules/auth'

const router = useRouter()
const authStore = useAuthStore()

const breadcrumbList = computed(() => authStore.breadcrumbList)
console.log(breadcrumbList)

interface BreadcrumbItem {
  title: string
  name: string
  query: any
}
// 点击面包屑，处理跳转
const onBreadcrumbClick = (item: BreadcrumbItem, index: number) => {
  if (index !== breadcrumbList.value.length - 1) {
    router.push({
      name: item.name,
      query: item.query
    })
  }
}
</script>

<style scoped lang="less">
.breadcrumb-box {
  display: flex;
  align-items: center;
  padding-right: 50px;
  overflow: hidden;
  mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 50px), transparent);

  .t-breadcrumb {
    white-space: nowrap;

    .t-breadcrumb__item {
      position: relative;
      // top: -2px;
      // display: inline-block;
      float: none;

      .t-breadcrumb__inner {
        display: inline-flex;

        &.is-link {
          opacity: 0.7;

          &:hover {
            opacity: 1;
          }
        }

        .breadcrumb-title {
          margin-top: 3px;
        }
      }

      :deep(.t-breadcrumb__separator) {
        position: relative;
        top: 2px;
      }
    }
  }
}
</style>
