DocumentOutlineContent.vue 3.6 KB
<template>
  <div class="document-outline-content">
    <!-- 加载状态 -->
    <div v-if="isLoading" class="loading-state">
      <i class="fas fa-spinner fa-spin"></i>
      <span>加载中...</span>
    </div>

    <!-- 大纲列表 -->
    <div v-else-if="outline && outline.length > 0" class="outline-list">
      <div
        v-for="item in outline"
        :key="item.id"
        class="outline-item"
        :class="{
          active: activeSectionId === item.id,
          [`level-${item.level}`]: true,
        }"
        :style="{ paddingLeft: `${(item.level - 1) * 12 + 12}px` }"
        @click="handleSectionClick(item)"
      >
        <span class="outline-text" :title="item.text">{{ item.text }}</span>
      </div>
    </div>

    <!-- 空状态 -->
    <div v-else class="empty-outline">
      <i class="fas fa-list-ul empty-icon"></i>
      <p class="empty-text">暂无大纲</p>
      <p class="empty-hint">文档中还没有标题</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from "vue";

interface OutlineItem {
  id: string;
  text: string;
  level: number;
  element?: HTMLElement | null;
}

interface Props {
  outline: OutlineItem[];
  activeSectionId?: string | null;
  isLoading?: boolean;
}

interface Emits {
  (e: "section-click", section: OutlineItem): void;
}

defineProps<Props>();
const emit = defineEmits<Emits>();

const handleSectionClick = (section: OutlineItem) => {
  emit("section-click", section);
};
</script>

<style scoped lang="scss">
.document-outline-content {
  width: 100%;
  height: 100%;
  overflow-y: auto;

  .loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--color-text-secondary);
    gap: 12px;

    i {
      font-size: 24px;
    }

    span {
      font-size: 13px;
    }
  }

  .outline-list {
    padding: 8px 0;

    .outline-item {
      display: flex;
      align-items: center;
      padding: 6px 12px;
      border-radius: 4px;
      cursor: pointer;
      transition: all 0.2s;
      color: var(--color-text-secondary);
      font-size: 13px;
      line-height: 1.5;
      margin-bottom: 2px;

      &:hover {
        background-color: var(--color-hover);
        color: var(--color-text);
      }

      &.active {
        background-color: var(--color-primary);
        color: #fff;
      }

      .outline-text {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      // 不同层级的样式
      &.level-1 {
        font-weight: 600;
        font-size: 14px;
      }

      &.level-2 {
        font-weight: 500;
      }

      &.level-3,
      &.level-4,
      &.level-5,
      &.level-6 {
        font-weight: 400;
        font-size: 12px;
      }
    }
  }

  .empty-outline {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--color-text-secondary);
    text-align: center;

    .empty-icon {
      font-size: 32px;
      margin-bottom: 12px;
      opacity: 0.5;
    }

    .empty-text {
      font-size: 14px;
      font-weight: 500;
      margin: 0 0 4px 0;
    }

    .empty-hint {
      font-size: 12px;
      margin: 0;
      opacity: 0.8;
    }
  }

  /* 滚动条样式 */
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
  }
}
</style>