From 82054d0aaff1e848a12e94a0b46d0671d4f0a66c Mon Sep 17 00:00:00 2001 From: Agent Date: Wed, 15 Jul 2026 00:43:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=90=9C=E7=B4=A2=E5=BB=BA=E8=AE=AE?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=A1=A5=E5=85=A8=20-=20=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A1=86=E8=BE=93=E5=85=A5=E6=97=B6=E6=98=BE=E7=A4=BA=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E5=BB=BA=E8=AE=AE=E5=88=97=E8=A1=A8=EF=BC=88=E6=9C=80?= =?UTF-8?q?=E5=A4=9A6=E6=9D=A1=EF=BC=89=20-=20=E5=BB=BA=E8=AE=AE=E9=A1=B9?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=A6=96=E5=AD=97=E6=AF=8D=E5=9B=BE=E6=A0=87?= =?UTF-8?q?+=E6=A0=87=E9=A2=98+=E5=88=86=E7=B1=BB=E5=90=8D=20-=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=AB=98=E4=BA=AE=E5=8C=B9=E9=85=8D=E6=96=87=E5=AD=97?= =?UTF-8?q?=20-=20=E7=82=B9=E5=87=BB=E5=BB=BA=E8=AE=AE=E9=A1=B9=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=89=93=E5=BC=80=E7=BD=91=E5=9D=80=20-=20blur?= =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E9=9A=90=E8=97=8F=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Home.vue | 95 +++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index c47d087..bb161b5 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -15,12 +15,28 @@ v-model="search" placeholder="搜索网址..." class="search-box" - @input="filterLinks" + @input="onSearchInput" + @focus="showSuggestions = true" + @blur="hideSuggestions" > +
+
+ {{ s.title[0] }} +
+ + {{ s.categoryName }} +
+
+
@@ -83,6 +99,9 @@ const search = ref('') const filteredLinks = ref([]) const searchTimer = ref>() const collapsedCats = ref>(new Set()) +const showSuggestions = ref(false) +const suggestions = ref([]) +let suggestTimer: ReturnType function toggleCat(id: number) { const s = new Set(collapsedCats.value) @@ -101,13 +120,30 @@ function linksInCat(catId: number) { } function filterLinks() { - if (searchTimer.value) clearTimeout(searchTimer.value) - searchTimer.value = setTimeout(() => { - const q = search.value.trim().toLowerCase() - filteredLinks.value = q - ? data.links.filter((l: any) => l.title.toLowerCase().includes(q) || l.description.toLowerCase().includes(q)) - : [...data.links] - }, 200) + const q = search.value.trim().toLowerCase() + filteredLinks.value = q + ? data.links.filter((l: any) => l.title.toLowerCase().includes(q) || l.description.toLowerCase().includes(q)) + : [...data.links] +} + +function onSearchInput() { + filterLinks() + clearTimeout(suggestTimer) + const q = search.value.trim().toLowerCase() + if (q.length < 1) { suggestions.value = []; return } + suggestTimer = setTimeout(() => { + suggestions.value = data.links + .filter((l: any) => l.title.toLowerCase().includes(q) || l.description.toLowerCase().includes(q)) + .slice(0, 6) + }, 100) +} + +function hideSuggestions() { + setTimeout(() => { showSuggestions.value = false }, 200) +} + +function jumpTo(url: string) { + window.open(url, '_blank') } function highlight(text: string, keyword: string) { @@ -163,6 +199,7 @@ loadData() align-items: center; justify-content: space-between; gap: 24px; + position: relative; } .brand { @@ -178,6 +215,48 @@ loadData() .search-box { width: 320px; } + .suggestions-dropdown { + position: absolute; + top: 100%; + right: 0; + width: 320px; + background: white; + border-radius: 8px; + box-shadow: 0 8px 24px rgba(0,0,0,0.12); + z-index: 20; + overflow: hidden; + margin-top: 4px; + } + .suggestion-item { + display: flex; + align-items: center; + gap: 10px; + padding: 10px 14px; + cursor: pointer; + transition: background 0.15s; + } + .suggestion-item:hover { background: #f5f7fa; } + .sug-icon { + width: 28px; + height: 28px; + border-radius: 6px; + background: linear-gradient(135deg, #6366f1, #818cf8); + color: white; + display: flex; + align-items: center; + justify-content: center; + font-size: 12px; + font-weight: 600; + flex-shrink: 0; + } + .sug-info { display: flex; flex-direction: column; min-width: 0; } + .sug-title { font-size: 14px; font-weight: 500; color: #333; } + .sug-cat { font-size: 11px; color: #888; margin-top: 2px; } + html.dark .suggestions-dropdown { background: var(--bg-card); } + html.dark .suggestion-item:hover { background: var(--hover-bg); } + html.dark .sug-title { color: var(--text-primary); } + html.dark .sug-cat { color: var(--text-secondary); } + .admin-link { display: inline-flex; align-items: center;