DocumentOutlineContent.vue
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<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>