Skip to content

Commit 37fae93

Browse files
committed
更新博客展示UI
1 parent 081c119 commit 37fae93

3 files changed

Lines changed: 6 additions & 98 deletions

File tree

frontend/src/assets/blog.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,6 @@ body {
13501350
color: var(--accent);
13511351
}
13521352

1353-
/* 文章详情页:同时有“博客/目录”两个左侧按钮,避免重叠 */
1354-
.article-detail-page .toc-fab {
1355-
top: calc(50% + 54px);
1356-
}
1357-
13581353
.toc-overlay {
13591354
position: fixed;
13601355
inset: 0;

frontend/src/views/AllArticlesView.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
aria-controls="articles-drawer"
4646
@click="openList"
4747
>
48-
博客
48+
目录
4949
</button>
5050

5151
<div v-if="listOpen" class="articles-overlay" @click="closeList" />
@@ -54,10 +54,10 @@
5454
class="articles-drawer"
5555
:class="{ open: listOpen }"
5656
role="dialog"
57-
aria-label="博客文章列表"
57+
aria-label="文章目录"
5858
>
5959
<div class="articles-drawer-head">
60-
<div class="articles-drawer-title">博客</div>
60+
<div class="articles-drawer-title">目录</div>
6161
<button class="articles-drawer-close" type="button" aria-label="关闭文章列表" @click="closeList">
6262
×
6363
</button>

frontend/src/views/ArticleDetailView.vue

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,6 @@
3636
</template>
3737
</div>
3838

39-
<!-- 外挂式文章列表:左侧抽屉 -->
40-
<button
41-
class="articles-fab"
42-
type="button"
43-
:aria-expanded="listOpen ? 'true' : 'false'"
44-
aria-controls="articles-drawer"
45-
@click="openList"
46-
>
47-
博客
48-
</button>
49-
50-
<div v-if="listOpen" class="articles-overlay" @click="closeList" />
51-
<aside
52-
id="articles-drawer"
53-
class="articles-drawer"
54-
:class="{ open: listOpen }"
55-
role="dialog"
56-
aria-label="博客文章列表"
57-
>
58-
<div class="articles-drawer-head">
59-
<div class="articles-drawer-title">博客</div>
60-
<button class="articles-drawer-close" type="button" aria-label="关闭文章列表" @click="closeList">
61-
×
62-
</button>
63-
</div>
64-
65-
<div class="articles-drawer-search">
66-
<input v-model="keyword" type="text" class="search-input" placeholder="find something..." />
67-
</div>
68-
69-
<div class="articles-drawer-body">
70-
<div v-if="loadingList" class="sidebar-hint" style="color: var(--muted)">加载中...</div>
71-
<div v-else-if="listItems.length === 0" class="sidebar-hint" style="color: var(--muted)">暂无文章</div>
72-
73-
<button
74-
v-for="a in listItems"
75-
:key="a.id"
76-
class="sidebar-item articles-drawer-item"
77-
:class="{ active: String(a.id) === String(route.params.id) }"
78-
type="button"
79-
@click="goArticle(a.id)"
80-
>
81-
<div class="sidebar-item-title">{{ a.title }}</div>
82-
<div class="sidebar-item-date">{{ formatDate(a.publishedAt) }}</div>
83-
</button>
84-
</div>
85-
</aside>
86-
8739
<!-- 外挂式目录:左侧抽屉 -->
8840
<button
8941
v-if="tocItems.length"
@@ -127,16 +79,15 @@
12779
</template>
12880

12981
<script setup>
130-
import { computed, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue'
131-
import { useRoute, useRouter } from 'vue-router'
82+
import { onBeforeUnmount, onMounted, ref, watchEffect } from 'vue'
83+
import { useRoute } from 'vue-router'
13284
import DOMPurify from 'dompurify'
13385
import { marked } from 'marked'
13486
135-
import { fetchArticleDetail, fetchArticles, coverUrl } from '../api/article'
87+
import { fetchArticleDetail, coverUrl } from '../api/article'
13688
import CommentSection from '../components/CommentSection.vue'
13789
13890
const route = useRoute()
139-
const router = useRouter()
14091
const loading = ref(true)
14192
const article = ref({})
14293
const html = ref('')
@@ -153,43 +104,6 @@ onMounted(async () => {
153104
}
154105
})
155106
156-
const listOpen = ref(false)
157-
const loadingList = ref(true)
158-
const keyword = ref('')
159-
const allArticles = ref([])
160-
161-
onMounted(async () => {
162-
try {
163-
loadingList.value = true
164-
const resp = await fetchArticles({ page: 0, size: 200 })
165-
allArticles.value = resp?.items || []
166-
} finally {
167-
loadingList.value = false
168-
}
169-
})
170-
171-
const listItems = computed(() => {
172-
const k = (keyword.value || '').trim().toLowerCase()
173-
if (!k) return allArticles.value
174-
return allArticles.value.filter(a => (a.title || '').toLowerCase().includes(k))
175-
})
176-
177-
function openList() {
178-
listOpen.value = true
179-
}
180-
181-
function closeList() {
182-
listOpen.value = false
183-
}
184-
185-
function goArticle(id) {
186-
closeList()
187-
tocOpen.value = false
188-
router.push(`/article/${id}`).then(() => {
189-
window.scrollTo({ top: 0, behavior: 'auto' })
190-
})
191-
}
192-
193107
watchEffect(() => {
194108
const md = article.value?.contentMarkdown || ''
195109
const rawHtml = marked.parse(md)
@@ -236,7 +150,6 @@ function jumpToHeading(id) {
236150
237151
function onKeyDown(e) {
238152
if (e.key === 'Escape') {
239-
if (listOpen.value) listOpen.value = false
240153
if (tocOpen.value) tocOpen.value = false
241154
}
242155
}

0 commit comments

Comments
 (0)