From e67479489ad2ca1405fd87b35399ddda9bec19ee Mon Sep 17 00:00:00 2001 From: irony Date: Sat, 6 Dec 2025 21:02:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(auto):=20=E6=90=9C=E7=B4=A2=E5=BB=BA?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/css/pages.css | 5 +--- src/main/resources/static/js/app.js | 34 ++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/resources/static/css/pages.css b/src/main/resources/static/css/pages.css index deaf43d..7532efe 100644 --- a/src/main/resources/static/css/pages.css +++ b/src/main/resources/static/css/pages.css @@ -383,10 +383,7 @@ /* 搜索建议 */ .search-suggestions { - position: absolute; - top: calc(var(--header-height) + 1px); - left: 0; - right: 0; + position: relative; background: var(--bg-primary); border-bottom: 1px solid var(--border-color); max-height: 60vh; diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index f3184b0..7169a23 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -177,6 +177,8 @@ const App = (function() { $('#search-clear').addClass('hidden'); $('#search-results').html('
输入关键词搜索小说
'); $('#search-suggestions').html('').addClass('hidden'); + // 清空时重新显示搜索历史和标签 + renderSearchTags(); } }); @@ -419,6 +421,27 @@ const App = (function() { $(this).text($text.hasClass('text-clamp-3') ? '展开' : '收起'); }); + // 点击搜索建议项 + $(document).on('click', '.suggestion-item', function(e) { + e.preventDefault(); + e.stopPropagation(); + const novelId = $(this).data('novel-id'); + const author = $(this).data('author'); + + if (novelId) { + // 跳转到小说详情 + hideSearch(); + setTimeout(() => { + navigate('#/novel/' + novelId); + }, 100); + } else if (author) { + // 按作者搜索 + $('#search-input').val(author); + $('#search-suggestions').html('').addClass('hidden'); + doSearch(author); + } + }); + // 加载更多按钮(使用事件委托,在pages.js中也有绑定,这里作为备用) $(document).on('click', '.load-more-btn', function() { if (Pages.hasMore()) { @@ -447,23 +470,27 @@ const App = (function() { } try { + console.log('正在加载搜索建议,关键词:', keyword); const suggestions = await API.getSearchSuggestions(keyword, 8); - if (suggestions.length === 0) { + console.log('搜索建议结果:', suggestions); + + if (!suggestions || suggestions.length === 0) { $('#search-suggestions').html('').addClass('hidden'); return; } let html = '
'; suggestions.forEach(suggestion => { + if (!suggestion || !suggestion.text) return; const highlightText = highlightKeyword(suggestion.text, keyword); if (suggestion.novelId) { html += `
- ${suggestion.type} + ${suggestion.type || '书名'} ${highlightText}
`; } else { html += `
- ${suggestion.type} + ${suggestion.type || '作者'} ${highlightText}
`; } @@ -471,6 +498,7 @@ const App = (function() { html += '
'; $('#search-suggestions').html(html).removeClass('hidden'); + console.log('搜索建议已显示,HTML长度:', html.length); } catch (error) { console.error('加载搜索建议失败:', error); $('#search-suggestions').html('').addClass('hidden');