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;